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

Commit 7da49b33 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Deprecate system server power re-attribution

Bug: 311793616
Test: atest PowerStatsTests && atest PowerStatsTestsRavenwood
Change-Id: If6eff0f5f9afaf84b6817a25fdd4e1d642c3fce2
parent a5d07622
Loading
Loading
Loading
Loading
+17 −16
Original line number Diff line number Diff line
@@ -288,6 +288,7 @@ public class BinderCallsStatsService extends Binder {
                        CachedDeviceState.Readonly.class);
                mBinderCallsStats.setDeviceState(deviceState);

                if (!com.android.server.power.optimization.Flags.disableSystemServicePowerAttr()) {
                    BatteryStatsInternal batteryStatsInternal = getLocalService(
                            BatteryStatsInternal.class);
                    mBinderCallsStats.setCallStatsObserver(new BinderInternal.CallStatsObserver() {
@@ -303,7 +304,7 @@ public class BinderCallsStatsService extends Binder {
                            batteryStatsInternal.noteBinderThreadNativeIds(binderThreadNativeTids);
                        }
                    });

                }
                // It needs to be called before mService.systemReady to make sure the observer is
                // initialized before installing it.
                mWorkSourceProvider.systemReady(getContext());
+3 −1
Original line number Diff line number Diff line
@@ -422,7 +422,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        mStats.setExternalStatsSyncLocked(mWorker);
        mStats.setRadioScanningTimeoutLocked(mContext.getResources().getInteger(
                com.android.internal.R.integer.config_radioScanningTimeout) * 1000L);
        if (!Flags.disableSystemServicePowerAttr()) {
            mStats.startTrackingSystemServerCpuTime();
        }

        mAggregatedPowerStatsConfig = createAggregatedPowerStatsConfig();
        mPowerStatsStore = new PowerStatsStore(systemDir, mHandler, mAggregatedPowerStatsConfig);
+40 −24
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ import com.android.internal.util.XmlUtils;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.net.module.util.NetworkCapabilitiesUtils;
import com.android.server.power.optimization.Flags;
import com.android.server.power.stats.SystemServerCpuThreadReader.SystemServiceCpuThreadTimes;
import libcore.util.EmptyArray;
@@ -185,7 +186,8 @@ public class BatteryStatsImpl extends BatteryStats {
    // TODO: remove "tcp" from network methods, since we measure total stats.
    // Current on-disk Parcel version. Must be updated when the format of the parcelable changes
    public static final int VERSION = 214;
    public static final int VERSION =
            !Flags.disableSystemServicePowerAttr() ? 214 : 215;
    // The maximum number of names wakelocks we will keep track of
    // per uid; once the limit is reached, we batch the remaining wakelocks
@@ -1753,7 +1755,9 @@ public class BatteryStatsImpl extends BatteryStats {
        mCpuUidActiveTimeReader = new KernelCpuUidActiveTimeReader(true, mClock);
        mCpuUidClusterTimeReader = new KernelCpuUidClusterTimeReader(true, mClock);
        mKernelWakelockReader = new KernelWakelockReader();
        if (!Flags.disableSystemServicePowerAttr()) {
            mSystemServerCpuThreadReader = SystemServerCpuThreadReader.create();
        }
        mKernelMemoryBandwidthStats = new KernelMemoryBandwidthStats();
        mTmpRailStats = new RailStats();
    }
@@ -11702,7 +11706,9 @@ public class BatteryStatsImpl extends BatteryStats {
        EnergyConsumerStats.resetIfNotNull(mGlobalEnergyConsumerStats);
        if (!Flags.disableSystemServicePowerAttr()) {
            resetIfNotNull(mBinderThreadCpuTimesUs, false, elapsedRealtimeUs);
        }
        mNumAllUidCpuTimeReads = 0;
        mNumUidsRemoved = 0;
@@ -13676,7 +13682,9 @@ public class BatteryStatsImpl extends BatteryStats {
                    mKernelCpuSpeedReaders[i].readDelta();
                }
            }
            if (!Flags.disableSystemServicePowerAttr()) {
                mSystemServerCpuThreadReader.readDelta();
            }
            return;
        }
@@ -15696,6 +15704,7 @@ public class BatteryStatsImpl extends BatteryStats {
            }
        }
        if (!Flags.disableSystemServicePowerAttr()) {
            updateSystemServiceCallStats();
            if (mBinderThreadCpuTimesUs != null) {
                pw.println("Per UID System server binder time in ms:");
@@ -15716,6 +15725,7 @@ public class BatteryStatsImpl extends BatteryStats {
                }
            }
        }
    }
    /**
     * Dump EnergyConsumer stats
@@ -16428,9 +16438,11 @@ public class BatteryStatsImpl extends BatteryStats {
            }
        }
        if (!Flags.disableSystemServicePowerAttr()) {
            mBinderThreadCpuTimesUs =
                    LongSamplingCounterArray.readSummaryFromParcelLocked(in, mOnBatteryTimeBase);
        }
    }
    /**
     * Writes a summary of the statistics to a Parcel, in a format suitable to be written to
@@ -16973,8 +16985,10 @@ public class BatteryStatsImpl extends BatteryStats {
            }
        }
        if (!Flags.disableSystemServicePowerAttr()) {
            LongSamplingCounterArray.writeSummaryToParcelLocked(out, mBinderThreadCpuTimesUs);
        }
    }
    @GuardedBy("this")
    public void prepareForDumpLocked() {
@@ -16985,8 +16999,10 @@ public class BatteryStatsImpl extends BatteryStats {
        // if we had originally pulled a time before the RTC was set.
        getStartClockTime();
        if (!Flags.disableSystemServicePowerAttr()) {
            updateSystemServiceCallStats();
        }
    }
    @GuardedBy("this")
    public void dump(Context context, PrintWriter pw, int flags, int reqUid, long histStart,
+7 −5
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ public class BatteryUsageStatsProvider {
                mPowerCalculators.add(new CustomEnergyConsumerPowerCalculator(mPowerProfile));
                mPowerCalculators.add(new UserPowerCalculator());

                if (!com.android.server.power.optimization.Flags.disableSystemServicePowerAttr()) {
                    // It is important that SystemServicePowerCalculator be applied last,
                    // because it re-attributes some of the power estimated by the other
                    // calculators.
@@ -103,6 +104,7 @@ public class BatteryUsageStatsProvider {
                            new SystemServicePowerCalculator(mCpuScalingPolicies, mPowerProfile));
                }
            }
        }
        return mPowerCalculators;
    }

+8 −0
Original line number Diff line number Diff line
@@ -13,3 +13,11 @@ flag {
    description: "Feature flag for streamlined battery stats"
    bug: "285646152"
}

flag {
    name: "disable_system_service_power_attr"
    namespace: "backstage_power"
    description: "Deprecation of system service power re-attribution"
    bug: "311793616"
    is_fixed_read_only: true
}
Loading