- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
210 lines
9.1 KiB
Java
210 lines
9.1 KiB
Java
package com.google.firebase.perf.transport;
|
|
|
|
import android.content.Context;
|
|
import com.google.firebase.perf.config.ConfigResolver;
|
|
import com.google.firebase.perf.logging.AndroidLogger;
|
|
import com.google.firebase.perf.util.Clock;
|
|
import com.google.firebase.perf.util.Constants$TraceNames;
|
|
import com.google.firebase.perf.util.Rate;
|
|
import com.google.firebase.perf.util.Timer;
|
|
import com.google.firebase.perf.util.Utils;
|
|
import com.google.firebase.perf.v1.PerfMetric;
|
|
import com.google.firebase.perf.v1.PerfSession;
|
|
import com.google.firebase.perf.v1.SessionVerbosity;
|
|
import com.unity3d.ads.core.domain.InitializeAndroidBoldSDK;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public final class RateLimiter {
|
|
public final ConfigResolver configResolver;
|
|
public final double fragmentBucketId;
|
|
public boolean isLogcatEnabled;
|
|
public RateLimiterImpl networkLimiter;
|
|
public final double samplingBucketId;
|
|
public RateLimiterImpl traceLimiter;
|
|
|
|
public RateLimiter(Context context, Rate rate, long j) {
|
|
this(rate, j, new Clock(), getSamplingBucketId(), getSamplingBucketId(), ConfigResolver.getInstance());
|
|
this.isLogcatEnabled = Utils.isDebugLoggingEnabled(context);
|
|
}
|
|
|
|
public static double getSamplingBucketId() {
|
|
return new Random().nextDouble();
|
|
}
|
|
|
|
public RateLimiter(Rate rate, long j, Clock clock, double d, double d2, ConfigResolver configResolver) {
|
|
this.traceLimiter = null;
|
|
this.networkLimiter = null;
|
|
boolean z = false;
|
|
this.isLogcatEnabled = false;
|
|
Utils.checkArgument(0.0d <= d && d < 1.0d, "Sampling bucket ID should be in range [0.0, 1.0).");
|
|
if (0.0d <= d2 && d2 < 1.0d) {
|
|
z = true;
|
|
}
|
|
Utils.checkArgument(z, "Fragment sampling bucket ID should be in range [0.0, 1.0).");
|
|
this.samplingBucketId = d;
|
|
this.fragmentBucketId = d2;
|
|
this.configResolver = configResolver;
|
|
this.traceLimiter = new RateLimiterImpl(rate, j, clock, configResolver, "Trace", this.isLogcatEnabled);
|
|
this.networkLimiter = new RateLimiterImpl(rate, j, clock, configResolver, InitializeAndroidBoldSDK.MSG_NETWORK, this.isLogcatEnabled);
|
|
}
|
|
|
|
public final boolean isDeviceAllowedToSendTraces() {
|
|
return this.samplingBucketId < this.configResolver.getTraceSamplingRate();
|
|
}
|
|
|
|
public final boolean isDeviceAllowedToSendNetworkEvents() {
|
|
return this.samplingBucketId < this.configResolver.getNetworkRequestSamplingRate();
|
|
}
|
|
|
|
public final boolean isDeviceAllowedToSendFragmentScreenTraces() {
|
|
return this.fragmentBucketId < this.configResolver.getFragmentSamplingRate();
|
|
}
|
|
|
|
public boolean isFragmentScreenTrace(PerfMetric perfMetric) {
|
|
return perfMetric.hasTraceMetric() && perfMetric.getTraceMetric().getName().startsWith("_st_") && perfMetric.getTraceMetric().containsCustomAttributes("Hosting_activity");
|
|
}
|
|
|
|
public boolean isEventRateLimited(PerfMetric perfMetric) {
|
|
if (!isRateLimitApplicable(perfMetric)) {
|
|
return false;
|
|
}
|
|
if (perfMetric.hasNetworkRequestMetric()) {
|
|
return !this.networkLimiter.check(perfMetric);
|
|
}
|
|
if (perfMetric.hasTraceMetric()) {
|
|
return !this.traceLimiter.check(perfMetric);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public boolean isEventSampled(PerfMetric perfMetric) {
|
|
if (perfMetric.hasTraceMetric() && !isDeviceAllowedToSendTraces() && !hasVerboseSessions(perfMetric.getTraceMetric().getPerfSessionsList())) {
|
|
return false;
|
|
}
|
|
if (!isFragmentScreenTrace(perfMetric) || isDeviceAllowedToSendFragmentScreenTraces() || hasVerboseSessions(perfMetric.getTraceMetric().getPerfSessionsList())) {
|
|
return !perfMetric.hasNetworkRequestMetric() || isDeviceAllowedToSendNetworkEvents() || hasVerboseSessions(perfMetric.getNetworkRequestMetric().getPerfSessionsList());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public final boolean hasVerboseSessions(List list) {
|
|
return list.size() > 0 && ((PerfSession) list.get(0)).getSessionVerbosityCount() > 0 && ((PerfSession) list.get(0)).getSessionVerbosity(0) == SessionVerbosity.GAUGES_AND_SYSTEM_EVENTS;
|
|
}
|
|
|
|
public boolean isRateLimitApplicable(PerfMetric perfMetric) {
|
|
return (!perfMetric.hasTraceMetric() || (!(perfMetric.getTraceMetric().getName().equals(Constants$TraceNames.FOREGROUND_TRACE_NAME.toString()) || perfMetric.getTraceMetric().getName().equals(Constants$TraceNames.BACKGROUND_TRACE_NAME.toString())) || perfMetric.getTraceMetric().getCountersCount() <= 0)) && !perfMetric.hasGaugeMetric();
|
|
}
|
|
|
|
public void changeRate(boolean z) {
|
|
this.traceLimiter.changeRate(z);
|
|
this.networkLimiter.changeRate(z);
|
|
}
|
|
|
|
public static class RateLimiterImpl {
|
|
public long backgroundCapacity;
|
|
public Rate backgroundRate;
|
|
public long capacity;
|
|
public final Clock clock;
|
|
public long foregroundCapacity;
|
|
public Rate foregroundRate;
|
|
public final boolean isLogcatEnabled;
|
|
public Timer lastTimeTokenReplenished;
|
|
public Rate rate;
|
|
public double tokenCount;
|
|
public static final AndroidLogger logger = AndroidLogger.getInstance();
|
|
public static final long MICROS_IN_A_SECOND = TimeUnit.SECONDS.toMicros(1);
|
|
|
|
public RateLimiterImpl(Rate rate, long j, Clock clock, ConfigResolver configResolver, String str, boolean z) {
|
|
this.clock = clock;
|
|
this.capacity = j;
|
|
this.rate = rate;
|
|
this.tokenCount = j;
|
|
this.lastTimeTokenReplenished = clock.getTime();
|
|
setRateByReadingRemoteConfigValues(configResolver, str, z);
|
|
this.isLogcatEnabled = z;
|
|
}
|
|
|
|
public synchronized boolean check(PerfMetric perfMetric) {
|
|
try {
|
|
Timer time = this.clock.getTime();
|
|
double durationMicros = (this.lastTimeTokenReplenished.getDurationMicros(time) * this.rate.getTokensPerSeconds()) / MICROS_IN_A_SECOND;
|
|
if (durationMicros > 0.0d) {
|
|
this.tokenCount = Math.min(this.tokenCount + durationMicros, this.capacity);
|
|
this.lastTimeTokenReplenished = time;
|
|
}
|
|
double d = this.tokenCount;
|
|
if (d >= 1.0d) {
|
|
this.tokenCount = d - 1.0d;
|
|
return true;
|
|
}
|
|
if (this.isLogcatEnabled) {
|
|
logger.warn("Exceeded log rate limit, dropping the log.");
|
|
}
|
|
return false;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
public synchronized void changeRate(boolean z) {
|
|
try {
|
|
this.rate = z ? this.foregroundRate : this.backgroundRate;
|
|
this.capacity = z ? this.foregroundCapacity : this.backgroundCapacity;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
public final void setRateByReadingRemoteConfigValues(ConfigResolver configResolver, String str, boolean z) {
|
|
long flimitSec = getFlimitSec(configResolver, str);
|
|
long flimitEvents = getFlimitEvents(configResolver, str);
|
|
TimeUnit timeUnit = TimeUnit.SECONDS;
|
|
Rate rate = new Rate(flimitEvents, flimitSec, timeUnit);
|
|
this.foregroundRate = rate;
|
|
this.foregroundCapacity = flimitEvents;
|
|
if (z) {
|
|
logger.debug("Foreground %s logging rate:%f, burst capacity:%d", str, rate, Long.valueOf(flimitEvents));
|
|
}
|
|
long blimitSec = getBlimitSec(configResolver, str);
|
|
long blimitEvents = getBlimitEvents(configResolver, str);
|
|
Rate rate2 = new Rate(blimitEvents, blimitSec, timeUnit);
|
|
this.backgroundRate = rate2;
|
|
this.backgroundCapacity = blimitEvents;
|
|
if (z) {
|
|
logger.debug("Background %s logging rate:%f, capacity:%d", str, rate2, Long.valueOf(blimitEvents));
|
|
}
|
|
}
|
|
|
|
public static long getFlimitSec(ConfigResolver configResolver, String str) {
|
|
if (str == "Trace") {
|
|
return configResolver.getRateLimitSec();
|
|
}
|
|
return configResolver.getRateLimitSec();
|
|
}
|
|
|
|
public static long getFlimitEvents(ConfigResolver configResolver, String str) {
|
|
if (str == "Trace") {
|
|
return configResolver.getTraceEventCountForeground();
|
|
}
|
|
return configResolver.getNetworkEventCountForeground();
|
|
}
|
|
|
|
public static long getBlimitSec(ConfigResolver configResolver, String str) {
|
|
if (str == "Trace") {
|
|
return configResolver.getRateLimitSec();
|
|
}
|
|
return configResolver.getRateLimitSec();
|
|
}
|
|
|
|
public static long getBlimitEvents(ConfigResolver configResolver, String str) {
|
|
if (str == "Trace") {
|
|
return configResolver.getTraceEventCountBackground();
|
|
}
|
|
return configResolver.getNetworkEventCountBackground();
|
|
}
|
|
}
|
|
}
|