Loading services/profcollect/src/com/android/server/profcollect/Utils.java +25 −0 Original line number Diff line number Diff line Loading @@ -25,10 +25,14 @@ import android.util.Log; import com.android.internal.os.BackgroundThread; import java.time.Instant; import java.util.concurrent.ThreadLocalRandom; public final class Utils { private static Instant lastTraceTime = Instant.EPOCH; private static final int TRACE_COOLDOWN_SECONDS = 30; public static boolean withFrequency(String configName, int defaultFrequency) { int threshold = DeviceConfig.getInt( DeviceConfig.NAMESPACE_PROFCOLLECT_NATIVE_BOOT, configName, defaultFrequency); Loading @@ -40,6 +44,9 @@ public final class Utils { if (mIProfcollect == null) { return false; } if (isInCooldownOrReset()) { return false; } BackgroundThread.get().getThreadHandler().post(() -> { try { mIProfcollect.trace_system(eventName); Loading @@ -54,6 +61,9 @@ public final class Utils { if (mIProfcollect == null) { return false; } if (isInCooldownOrReset()) { return false; } BackgroundThread.get().getThreadHandler().postDelayed(() -> { try { mIProfcollect.trace_system(eventName); Loading @@ -69,6 +79,9 @@ public final class Utils { if (mIProfcollect == null) { return false; } if (isInCooldownOrReset()) { return false; } BackgroundThread.get().getThreadHandler().post(() -> { try { mIProfcollect.trace_process(eventName, Loading @@ -80,4 +93,16 @@ public final class Utils { }); return true; } /** * Returns true if the last trace is within the cooldown period. If the last trace is outside * the cooldown period, the last trace time is reset to the current time. */ private static boolean isInCooldownOrReset() { if (!Instant.now().isBefore(lastTraceTime.plusSeconds(TRACE_COOLDOWN_SECONDS))) { lastTraceTime = Instant.now(); return false; } return true; } } Loading
services/profcollect/src/com/android/server/profcollect/Utils.java +25 −0 Original line number Diff line number Diff line Loading @@ -25,10 +25,14 @@ import android.util.Log; import com.android.internal.os.BackgroundThread; import java.time.Instant; import java.util.concurrent.ThreadLocalRandom; public final class Utils { private static Instant lastTraceTime = Instant.EPOCH; private static final int TRACE_COOLDOWN_SECONDS = 30; public static boolean withFrequency(String configName, int defaultFrequency) { int threshold = DeviceConfig.getInt( DeviceConfig.NAMESPACE_PROFCOLLECT_NATIVE_BOOT, configName, defaultFrequency); Loading @@ -40,6 +44,9 @@ public final class Utils { if (mIProfcollect == null) { return false; } if (isInCooldownOrReset()) { return false; } BackgroundThread.get().getThreadHandler().post(() -> { try { mIProfcollect.trace_system(eventName); Loading @@ -54,6 +61,9 @@ public final class Utils { if (mIProfcollect == null) { return false; } if (isInCooldownOrReset()) { return false; } BackgroundThread.get().getThreadHandler().postDelayed(() -> { try { mIProfcollect.trace_system(eventName); Loading @@ -69,6 +79,9 @@ public final class Utils { if (mIProfcollect == null) { return false; } if (isInCooldownOrReset()) { return false; } BackgroundThread.get().getThreadHandler().post(() -> { try { mIProfcollect.trace_process(eventName, Loading @@ -80,4 +93,16 @@ public final class Utils { }); return true; } /** * Returns true if the last trace is within the cooldown period. If the last trace is outside * the cooldown period, the last trace time is reset to the current time. */ private static boolean isInCooldownOrReset() { if (!Instant.now().isBefore(lastTraceTime.plusSeconds(TRACE_COOLDOWN_SECONDS))) { lastTraceTime = Instant.now(); return false; } return true; } }