Loading services/core/java/com/android/server/am/BatteryStatsService.java +6 −3 Original line number Diff line number Diff line Loading @@ -480,6 +480,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub } public void systemServicesReady() { mStats.setPowerStatsCollectorEnabled(Flags.streamlinedBatteryStats()); mBatteryUsageStatsProvider.setPowerStatsExporterEnabled(Flags.streamlinedBatteryStats()); mWorker.systemServicesReady(); mStats.systemServicesReady(mContext); Loading Loading @@ -2648,7 +2649,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub pw.println(" --proto: output as a binary protobuffer"); pw.println(" --model power-profile: use the power profile model" + " even if measured energy is available"); if (Flags.streamlinedBatteryStats()) { pw.println(" --sample: collect and dump a sample of stats for debugging purpose"); } pw.println(" <package.name>: optional name of package to filter output by."); pw.println(" -h: print this help text."); pw.println("Battery stats (batterystats) commands:"); Loading Loading @@ -2938,10 +2941,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub mCpuWakeupStats.dump(new IndentingPrintWriter(pw, " "), SystemClock.elapsedRealtime()); return; } else if ("--sample".equals(arg)) { } else if (Flags.streamlinedBatteryStats() && "--sample".equals(arg)) { dumpStatsSample(pw); return; } else if ("--aggregated".equals(arg)) { } else if (Flags.streamlinedBatteryStats() && "--aggregated".equals(arg)) { dumpAggregatedStats(pw); return; } else if ("--store".equals(arg)) { Loading services/core/java/com/android/server/power/stats/BatteryStatsImpl.java +23 −4 Original line number Diff line number Diff line Loading @@ -286,6 +286,7 @@ public class BatteryStatsImpl extends BatteryStats { private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); private int[] mCpuPowerBracketMap; private final CpuPowerStatsCollector mCpuPowerStatsCollector; private boolean mPowerStatsCollectorEnabled; public LongSparseArray<SamplingTimer> getKernelMemoryStats() { return mKernelMemoryStats; Loading Loading @@ -601,6 +602,10 @@ public class BatteryStatsImpl extends BatteryStats { @SuppressWarnings("GuardedBy") // errorprone false positive on getProcStateTimeCounter @VisibleForTesting public void updateProcStateCpuTimesLocked(int uid, long elapsedRealtimeMs, long uptimeMs) { if (mPowerStatsCollectorEnabled) { return; } ensureKernelSingleUidTimeReaderLocked(); final Uid u = getUidStatsLocked(uid); Loading Loading @@ -653,8 +658,9 @@ public class BatteryStatsImpl extends BatteryStats { */ @SuppressWarnings("GuardedBy") // errorprone false positive on getProcStateTimeCounter public void updateCpuTimesForAllUids() { if (mCpuPowerStatsCollector != null) { if (mPowerStatsCollectorEnabled && mCpuPowerStatsCollector != null) { mCpuPowerStatsCollector.schedule(); return; } synchronized (BatteryStatsImpl.this) { Loading Loading @@ -712,7 +718,7 @@ public class BatteryStatsImpl extends BatteryStats { @GuardedBy("this") private void ensureKernelSingleUidTimeReaderLocked() { if (mKernelSingleUidTimeReader != null) { if (mPowerStatsCollectorEnabled || mKernelSingleUidTimeReader != null) { return; } Loading Loading @@ -8213,6 +8219,10 @@ public class BatteryStatsImpl extends BatteryStats { @GuardedBy("mBsi") private void ensureMultiStateCounters(long timestampMs) { if (mBsi.mPowerStatsCollectorEnabled) { throw new IllegalStateException("Multi-state counters used in streamlined mode"); } if (mProcStateTimeMs == null) { mProcStateTimeMs = new TimeInFreqMultiStateCounter(mBsi.mOnBatteryTimeBase, Loading Loading @@ -10511,7 +10521,7 @@ public class BatteryStatsImpl extends BatteryStats { mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtimeMs); } if (mBsi.trackPerProcStateCpuTimes()) { if (!mBsi.mPowerStatsCollectorEnabled && mBsi.trackPerProcStateCpuTimes()) { mBsi.updateProcStateCpuTimesLocked(mUid, elapsedRealtimeMs, uptimeMs); LongArrayMultiStateCounter onBatteryCounter = Loading Loading @@ -14211,7 +14221,7 @@ public class BatteryStatsImpl extends BatteryStats { mCpuUidFreqTimeReader.onSystemReady(); } if (mCpuPowerStatsCollector != null) { mCpuPowerStatsCollector.onSystemReady(); mCpuPowerStatsCollector.setEnabled(mPowerStatsCollectorEnabled); } mSystemReady = true; } Loading Loading @@ -15232,6 +15242,15 @@ public class BatteryStatsImpl extends BatteryStats { return mCpuUidFreqTimeReader.isFastCpuTimesReader(); } /** * Enables or disables the PowerStatsCollector mode. */ public void setPowerStatsCollectorEnabled(boolean enabled) { synchronized (this) { mPowerStatsCollectorEnabled = enabled; } } @GuardedBy("this") public void systemServicesReady(Context context) { mConstants.startObserving(context.getContentResolver()); services/core/java/com/android/server/power/stats/CpuPowerStatsCollector.java +0 −8 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ import com.android.internal.os.CpuScalingPolicies; import com.android.internal.os.PowerProfile; import com.android.internal.os.PowerStats; import com.android.server.LocalServices; import com.android.server.power.optimization.Flags; import java.io.PrintWriter; import java.util.ArrayList; Loading Loading @@ -273,13 +272,6 @@ public class CpuPowerStatsCollector extends PowerStatsCollector { mDefaultCpuPowerBracketsPerEnergyConsumer = defaultCpuPowerBracketsPerEnergyConsumer; } /** * Initializes the collector during the boot sequence. */ public void onSystemReady() { setEnabled(Flags.streamlinedBatteryStats()); } private boolean ensureInitialized() { if (mIsInitialized) { return true; Loading Loading
services/core/java/com/android/server/am/BatteryStatsService.java +6 −3 Original line number Diff line number Diff line Loading @@ -480,6 +480,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub } public void systemServicesReady() { mStats.setPowerStatsCollectorEnabled(Flags.streamlinedBatteryStats()); mBatteryUsageStatsProvider.setPowerStatsExporterEnabled(Flags.streamlinedBatteryStats()); mWorker.systemServicesReady(); mStats.systemServicesReady(mContext); Loading Loading @@ -2648,7 +2649,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub pw.println(" --proto: output as a binary protobuffer"); pw.println(" --model power-profile: use the power profile model" + " even if measured energy is available"); if (Flags.streamlinedBatteryStats()) { pw.println(" --sample: collect and dump a sample of stats for debugging purpose"); } pw.println(" <package.name>: optional name of package to filter output by."); pw.println(" -h: print this help text."); pw.println("Battery stats (batterystats) commands:"); Loading Loading @@ -2938,10 +2941,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub mCpuWakeupStats.dump(new IndentingPrintWriter(pw, " "), SystemClock.elapsedRealtime()); return; } else if ("--sample".equals(arg)) { } else if (Flags.streamlinedBatteryStats() && "--sample".equals(arg)) { dumpStatsSample(pw); return; } else if ("--aggregated".equals(arg)) { } else if (Flags.streamlinedBatteryStats() && "--aggregated".equals(arg)) { dumpAggregatedStats(pw); return; } else if ("--store".equals(arg)) { Loading
services/core/java/com/android/server/power/stats/BatteryStatsImpl.java +23 −4 Original line number Diff line number Diff line Loading @@ -286,6 +286,7 @@ public class BatteryStatsImpl extends BatteryStats { private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); private int[] mCpuPowerBracketMap; private final CpuPowerStatsCollector mCpuPowerStatsCollector; private boolean mPowerStatsCollectorEnabled; public LongSparseArray<SamplingTimer> getKernelMemoryStats() { return mKernelMemoryStats; Loading Loading @@ -601,6 +602,10 @@ public class BatteryStatsImpl extends BatteryStats { @SuppressWarnings("GuardedBy") // errorprone false positive on getProcStateTimeCounter @VisibleForTesting public void updateProcStateCpuTimesLocked(int uid, long elapsedRealtimeMs, long uptimeMs) { if (mPowerStatsCollectorEnabled) { return; } ensureKernelSingleUidTimeReaderLocked(); final Uid u = getUidStatsLocked(uid); Loading Loading @@ -653,8 +658,9 @@ public class BatteryStatsImpl extends BatteryStats { */ @SuppressWarnings("GuardedBy") // errorprone false positive on getProcStateTimeCounter public void updateCpuTimesForAllUids() { if (mCpuPowerStatsCollector != null) { if (mPowerStatsCollectorEnabled && mCpuPowerStatsCollector != null) { mCpuPowerStatsCollector.schedule(); return; } synchronized (BatteryStatsImpl.this) { Loading Loading @@ -712,7 +718,7 @@ public class BatteryStatsImpl extends BatteryStats { @GuardedBy("this") private void ensureKernelSingleUidTimeReaderLocked() { if (mKernelSingleUidTimeReader != null) { if (mPowerStatsCollectorEnabled || mKernelSingleUidTimeReader != null) { return; } Loading Loading @@ -8213,6 +8219,10 @@ public class BatteryStatsImpl extends BatteryStats { @GuardedBy("mBsi") private void ensureMultiStateCounters(long timestampMs) { if (mBsi.mPowerStatsCollectorEnabled) { throw new IllegalStateException("Multi-state counters used in streamlined mode"); } if (mProcStateTimeMs == null) { mProcStateTimeMs = new TimeInFreqMultiStateCounter(mBsi.mOnBatteryTimeBase, Loading Loading @@ -10511,7 +10521,7 @@ public class BatteryStatsImpl extends BatteryStats { mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtimeMs); } if (mBsi.trackPerProcStateCpuTimes()) { if (!mBsi.mPowerStatsCollectorEnabled && mBsi.trackPerProcStateCpuTimes()) { mBsi.updateProcStateCpuTimesLocked(mUid, elapsedRealtimeMs, uptimeMs); LongArrayMultiStateCounter onBatteryCounter = Loading Loading @@ -14211,7 +14221,7 @@ public class BatteryStatsImpl extends BatteryStats { mCpuUidFreqTimeReader.onSystemReady(); } if (mCpuPowerStatsCollector != null) { mCpuPowerStatsCollector.onSystemReady(); mCpuPowerStatsCollector.setEnabled(mPowerStatsCollectorEnabled); } mSystemReady = true; } Loading Loading @@ -15232,6 +15242,15 @@ public class BatteryStatsImpl extends BatteryStats { return mCpuUidFreqTimeReader.isFastCpuTimesReader(); } /** * Enables or disables the PowerStatsCollector mode. */ public void setPowerStatsCollectorEnabled(boolean enabled) { synchronized (this) { mPowerStatsCollectorEnabled = enabled; } } @GuardedBy("this") public void systemServicesReady(Context context) { mConstants.startObserving(context.getContentResolver());
services/core/java/com/android/server/power/stats/CpuPowerStatsCollector.java +0 −8 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ import com.android.internal.os.CpuScalingPolicies; import com.android.internal.os.PowerProfile; import com.android.internal.os.PowerStats; import com.android.server.LocalServices; import com.android.server.power.optimization.Flags; import java.io.PrintWriter; import java.util.ArrayList; Loading Loading @@ -273,13 +272,6 @@ public class CpuPowerStatsCollector extends PowerStatsCollector { mDefaultCpuPowerBracketsPerEnergyConsumer = defaultCpuPowerBracketsPerEnergyConsumer; } /** * Initializes the collector during the boot sequence. */ public void onSystemReady() { setEnabled(Flags.streamlinedBatteryStats()); } private boolean ensureInitialized() { if (mIsInitialized) { return true; Loading