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

Commit 7f8def9d authored by Chenjie Yu's avatar Chenjie Yu
Browse files

pull cpu time per freq

also adjust lock for ValueMetricProducer.cpp

Test: manual test
Change-Id: Ib96e3011d7bcf44ac92346d880196c425623a86f
parent 2888533e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -172,6 +172,7 @@ std::unique_ptr<std::vector<uint8_t>> ValueMetricProducer::onDumpReport() {
}

void ValueMetricProducer::onConditionChanged(const bool condition, const uint64_t eventTime) {
    AutoMutex _l(mLock);
    mCondition = condition;

    if (mPullTagId != -1) {
@@ -187,7 +188,6 @@ void ValueMetricProducer::onConditionChanged(const bool condition, const uint64_
            if (allData.size() == 0) {
                return;
            }
            AutoMutex _l(mLock);
            for (const auto& data : allData) {
                onMatchedLogEvent(0, *data, false);
            }
@@ -198,8 +198,8 @@ void ValueMetricProducer::onConditionChanged(const bool condition, const uint64_
}

void ValueMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEvent>>& allData) {
    if (mCondition == ConditionState::kTrue || !mMetric.has_condition()) {
    AutoMutex _l(mLock);
    if (mCondition == ConditionState::kTrue || !mMetric.has_condition()) {
        if (allData.size() == 0) {
            return;
        }
+19 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ message StatsEvent {
        PowerStatePlatformSleepStatePulled power_state_platform_sleep_state_pulled = 1005;
        PowerStateVoterPulled power_state_voter_pulled = 1006;
        PowerStateSubsystemSleepStatePulled power_state_subsystem_sleep_state_pulled = 1007;
        CpuTimePerFreqPulled cpu_time_per_freq_pulled = 1008;
    }
}

@@ -849,6 +850,7 @@ message PowerStateSubsystemSleepStatePulled {
}

/**
<<<<<<< HEAD
 * Logs creation or removal of an isolated uid. Isolated uid's are temporary uid's to sandbox risky
 * behavior in its own uid. However, the metrics of these isolated uid's almost always should be
 * attributed back to the parent (host) uid. One example is Chrome.
@@ -866,3 +868,20 @@ message IsolatedUidChanged {
    // be removed before if it's used for another parent uid.
    optional int32 is_create = 3;
}

/*
 * Pulls Cpu time per frequency.
 * Note: this should be pulled for gauge metric only, without condition.
 * The puller keeps internal state of last values. It should not be pulled by
 * different metrics.
 * The pulled data is delta of cpu time from last pull, calculated as
 * following:
 * if current time is larger than last value, take delta between the two.
 * if current time is smaller than last value, there must be a cpu
 * hotplug event, and the current time is taken as delta.
 */
message CpuTimePerFreqPulled {
    optional uint32 cluster = 1;
    optional uint32 freq_index = 2;
    optional uint64 time = 3;
}
+31 −3
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.net.NetworkStatsFactory;
import com.android.internal.os.KernelWakelockReader;
import com.android.internal.os.KernelWakelockStats;
import com.android.internal.os.KernelCpuSpeedReader;
import com.android.internal.os.PowerProfile;
import com.android.server.LocalServices;
import com.android.server.SystemService;

@@ -71,6 +73,9 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
    private final PendingIntent mPullingAlarmIntent;
    private final BroadcastReceiver mAppUpdateReceiver;
    private final BroadcastReceiver mUserUpdateReceiver;
    private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader();
    private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats();
    private final KernelCpuSpeedReader[] mKernelCpuSpeedReaders;

    public StatsCompanionService(Context context) {
        super();
@@ -103,6 +108,16 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
            }
        };
        Slog.w(TAG, "Registered receiver for ACTION_PACKAGE_REPLACE AND ADDED.");
        PowerProfile powerProfile = new PowerProfile(context);
        final int numClusters = powerProfile.getNumCpuClusters();
        mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters];
        int firstCpuOfCluster = 0;
        for (int i = 0; i < numClusters; i++) {
            final int numSpeedSteps = powerProfile.getNumSpeedStepsInCpuCluster(i);
            mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster,
                            numSpeedSteps);
            firstCpuOfCluster += powerProfile.getNumCoresInCpuCluster(i);
        }
    }

    private final static int[] toIntArray(List<Integer> list) {
@@ -286,9 +301,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
      }
    }

    private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader();
    private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats();

    private StatsLogEventWrapper[] addNetworkStats(int tag, NetworkStats stats, boolean withFGBG) {
        List<StatsLogEventWrapper> ret = new ArrayList<>();
        int size = stats.size();
@@ -446,6 +458,22 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                }
                return ret.toArray(new StatsLogEventWrapper[ret.size()]);
            }
            case StatsLog.CPU_TIME_PER_FREQ_PULLED: {
                List<StatsLogEventWrapper> ret = new ArrayList();
                for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) {
                    long[] clusterTimeMs = mKernelCpuSpeedReaders[cluster].readDelta();
                    if (clusterTimeMs != null) {
                        for (int speed = clusterTimeMs.length - 1; speed >= 0; --speed) {
                            StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, 3);
                            e.writeInt(tagId);
                            e.writeInt(speed);
                            e.writeLong(clusterTimeMs[speed]);
                            ret.add(e);
                        }
                    }
                }
                return ret.toArray(new StatsLogEventWrapper[ret.size()]);
            }
            default:
                Slog.w(TAG, "No such tagId data as " + tagId);
                return null;