Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit efc2dccc authored by Dhavalkumar Chaudhary's avatar Dhavalkumar Chaudhary
Browse files

Making power stats logging frequency configurable and can be overlaid

Fix: 166689029

Test: atest PowerStatsTests
Flag: com.android.server.power.optimization.configure_power_stats_log_frequency
Change-Id: I3334af6563f71c9b9ef6db03ddc274f7b0f1f72d
parent 9a5460ee
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -74,5 +74,9 @@
    It only affects the `dumpsys batterystats -\-checkin` command, The real checkin Format -->
    <integer name="config_batteryHistoryDumpRealCheckinWindowSize">86400000</integer>

    <!-- PowerStats log period on low frequency, default value is 1 hour (60 * 60 * 1000) in millis -->
    <integer name="config_powerStatsLogPeriodLowFrequencyMs">3600000</integer>

    <!-- PowerStats log period on high frequency, default value is 2 minutes (2 * 60 * 1000) in millis -->
    <integer name="config_powerStatsLogPeriodHighFrequencyMs">120000</integer>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -5467,6 +5467,8 @@
  <java-symbol type="integer" name="config_batteryHistoryDumpWindowSize" />
  <java-symbol type="integer" name="config_batteryHistoryDumpCheckinWindowSize" />
  <java-symbol type="integer" name="config_batteryHistoryDumpRealCheckinWindowSize" />
  <java-symbol type="integer" name="config_powerStatsLogPeriodLowFrequencyMs" />
  <java-symbol type="integer" name="config_powerStatsLogPeriodHighFrequencyMs" />

  <!--Dynamic Tokens-->
  <java-symbol name="system_accent1_0_light" type="color"/>
+7 −0
Original line number Diff line number Diff line
@@ -64,3 +64,10 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
     namespace: "backstage_power"
     name: "configure_power_stats_log_frequency"
     description: "Add a configurable value for power stats logging frequency"
     bug: "166689029"
}
+18 −3
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.os.Handler;
import android.os.SystemClock;
import android.util.Slog;

import com.android.server.power.optimization.Flags;

/**
 * TimerTrigger sets a 60 second opportunistic timer using postDelayed.
 * When the timer expires a message is sent to the PowerStatsLogger to
@@ -30,7 +32,6 @@ import android.util.Slog;
public final class TimerTrigger extends PowerStatsLogTrigger {
    private static final String TAG = TimerTrigger.class.getSimpleName();
    private static final boolean DEBUG = false;
    // TODO(b/166689029): Make configurable through global settings.
    private static final long LOG_PERIOD_MS_LOW_FREQUENCY = 60 * 60 * 1000; // 1 hour
    private static final long LOG_PERIOD_MS_HIGH_FREQUENCY = 2 * 60 * 1000; // 2 minutes

@@ -66,15 +67,29 @@ public final class TimerTrigger extends PowerStatsLogTrigger {
    public TimerTrigger(Context context, PowerStatsLogger powerStatsLogger,
            boolean triggerEnabled) {
        super(context, powerStatsLogger);
        long logPeriodMsLowFrequency;
        long logPeriodMsHighFrequency;
        if (Flags.configurePowerStatsLogFrequency()) {
            logPeriodMsLowFrequency = mContext.getResources().getInteger(
                        com.android.internal.R.integer
                            .config_powerStatsLogPeriodLowFrequencyMs);
            logPeriodMsHighFrequency = mContext.getResources().getInteger(
                        com.android.internal.R.integer
                            .config_powerStatsLogPeriodHighFrequencyMs);
        } else {
            logPeriodMsLowFrequency = LOG_PERIOD_MS_LOW_FREQUENCY;
            logPeriodMsHighFrequency = LOG_PERIOD_MS_HIGH_FREQUENCY;
        }

        mHandler = mContext.getMainThreadHandler();
        mAlarmManager = mContext.getSystemService(AlarmManager.class);

        if (triggerEnabled) {
            final PeriodicTimer logDataLowFrequency = new PeriodicTimer("PowerStatsLowFreqLog",
                    LOG_PERIOD_MS_LOW_FREQUENCY,
                    logPeriodMsLowFrequency,
                    PowerStatsLogger.MSG_LOG_TO_DATA_STORAGE_LOW_FREQUENCY);
            final PeriodicTimer logDataHighFrequency = new PeriodicTimer("PowerStatsHighFreqLog",
                    LOG_PERIOD_MS_HIGH_FREQUENCY,
                    logPeriodMsHighFrequency,
                    PowerStatsLogger.MSG_LOG_TO_DATA_STORAGE_HIGH_FREQUENCY);
            logDataLowFrequency.run();
            logDataHighFrequency.run();