Migrate pullProcessCpuTime

Test: No CTS test. Ran adb shell cmd pull-source 10035
Change-Id: Idc6cad89d4a953f6c92fd55c7f9e0161633efad0
This commit is contained in:
Jeffrey Huang
2020-01-14 15:44:58 -08:00
parent fdc5369e3e
commit 7a9ae133b3
3 changed files with 35 additions and 34 deletions

View File

@@ -806,27 +806,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
}
}
private void pullProcessCpuTime(int tagId, long elapsedNanos, final long wallClockNanos,
List<StatsLogEventWrapper> pulledData) {
synchronized (this) {
if (mProcessCpuTracker == null) {
mProcessCpuTracker = new ProcessCpuTracker(false);
mProcessCpuTracker.init();
}
mProcessCpuTracker.update();
for (int i = 0; i < mProcessCpuTracker.countStats(); i++) {
ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos,
wallClockNanos);
e.writeInt(st.uid);
e.writeString(st.name);
e.writeLong(st.base_utime);
e.writeLong(st.base_stime);
pulledData.add(e);
}
}
}
private void pullDebugElapsedClock(int tagId,
long elapsedNanos, final long wallClockNanos, List<StatsLogEventWrapper> pulledData) {
final long elapsedMillis = SystemClock.elapsedRealtime();
@@ -1139,11 +1118,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
break;
}
case StatsLog.PROCESS_CPU_TIME: {
pullProcessCpuTime(tagId, elapsedNanos, wallClockNanos, ret);
break;
}
case StatsLog.DEBUG_ELAPSED_CLOCK: {
pullDebugElapsedClock(tagId, elapsedNanos, wallClockNanos, ret);
break;

View File

@@ -96,11 +96,6 @@ std::map<PullerKey, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
{{.atomTag = android::util::PROC_STATS_PKG_PROC},
{.puller = new StatsCompanionServicePuller(android::util::PROC_STATS_PKG_PROC)}},
// Process cpu stats. Min cool-down is 5 sec, inline with what AcitivityManagerService uses.
{{.atomTag = android::util::PROCESS_CPU_TIME},
{.coolDownNs = 5 * NS_PER_SEC /* min cool-down in seconds*/,
.puller = new StatsCompanionServicePuller(android::util::PROCESS_CPU_TIME)}},
// DebugElapsedClock.
{{.atomTag = android::util::DEBUG_ELAPSED_CLOCK},
{.additiveFields = {1, 2, 3, 4},

View File

@@ -1944,12 +1944,44 @@ public class StatsPullAtomService extends SystemService {
return StatsManager.PULL_SUCCESS;
}
private final Object mCpuTrackerLock = new Object();
@GuardedBy("mCpuTrackerLock")
private ProcessCpuTracker mProcessCpuTracker;
private void registerProcessCpuTime() {
// No op.
int tagId = StatsLog.PROCESS_CPU_TIME;
// Min cool-down is 5 sec, inline with what ActivityManagerService uses.
PullAtomMetadata metadata = PullAtomMetadata.newBuilder()
.setCoolDownNs(5 * NS_PER_SEC)
.build();
mStatsManager.registerPullAtomCallback(
tagId,
metadata,
(atomTag, data) -> pullProcessCpuTime(atomTag, data),
BackgroundThread.getExecutor()
);
}
private void pullProcessCpuTime() {
// No op.
private int pullProcessCpuTime(int atomTag, List<StatsEvent> pulledData) {
synchronized (mCpuTrackerLock) {
if (mProcessCpuTracker == null) {
mProcessCpuTracker = new ProcessCpuTracker(false);
mProcessCpuTracker.init();
}
mProcessCpuTracker.update();
for (int i = 0; i < mProcessCpuTracker.countStats(); i++) {
ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
StatsEvent e = StatsEvent.newBuilder()
.setAtomId(atomTag)
.writeInt(st.uid)
.writeString(st.name)
.writeLong(st.base_utime)
.writeLong(st.base_stime)
.build();
pulledData.add(e);
}
}
return StatsManager.PULL_SUCCESS;
}
@Nullable