Migrate Debug(Failing)ElapsedClock to new API
Test: adb shell cmd stats pull-source 10046 Test: adb shell cmd stats pull-source 10047 Bug: 145565211 Change-Id: I515269ec77880d85ce2ce83bd81ea6f34b6e3db7
This commit is contained in:
@@ -714,56 +714,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private void pullDebugElapsedClock(int tagId,
|
||||
long elapsedNanos, final long wallClockNanos, List<StatsLogEventWrapper> pulledData) {
|
||||
final long elapsedMillis = SystemClock.elapsedRealtime();
|
||||
final long clockDiffMillis = mDebugElapsedClockPreviousValue == 0
|
||||
? 0 : elapsedMillis - mDebugElapsedClockPreviousValue;
|
||||
|
||||
StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
|
||||
e.writeLong(mDebugElapsedClockPullCount);
|
||||
e.writeLong(elapsedMillis);
|
||||
// Log it twice to be able to test multi-value aggregation from ValueMetric.
|
||||
e.writeLong(elapsedMillis);
|
||||
e.writeLong(clockDiffMillis);
|
||||
e.writeInt(1 /* always set */);
|
||||
pulledData.add(e);
|
||||
|
||||
if (mDebugElapsedClockPullCount % 2 == 1) {
|
||||
StatsLogEventWrapper e2 = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
|
||||
e2.writeLong(mDebugElapsedClockPullCount);
|
||||
e2.writeLong(elapsedMillis);
|
||||
// Log it twice to be able to test multi-value aggregation from ValueMetric.
|
||||
e2.writeLong(elapsedMillis);
|
||||
e2.writeLong(clockDiffMillis);
|
||||
e2.writeInt(2 /* set on odd pulls */);
|
||||
pulledData.add(e2);
|
||||
}
|
||||
|
||||
mDebugElapsedClockPullCount++;
|
||||
mDebugElapsedClockPreviousValue = elapsedMillis;
|
||||
}
|
||||
|
||||
private void pullDebugFailingElapsedClock(int tagId,
|
||||
long elapsedNanos, final long wallClockNanos, List<StatsLogEventWrapper> pulledData) {
|
||||
StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
|
||||
final long elapsedMillis = SystemClock.elapsedRealtime();
|
||||
// Fails every 5 buckets.
|
||||
if (mDebugFailingElapsedClockPullCount++ % 5 == 0) {
|
||||
mDebugFailingElapsedClockPreviousValue = elapsedMillis;
|
||||
throw new RuntimeException("Failing debug elapsed clock");
|
||||
}
|
||||
|
||||
e.writeLong(mDebugFailingElapsedClockPullCount);
|
||||
e.writeLong(elapsedMillis);
|
||||
// Log it twice to be able to test multi-value aggregation from ValueMetric.
|
||||
e.writeLong(elapsedMillis);
|
||||
e.writeLong(mDebugFailingElapsedClockPreviousValue == 0
|
||||
? 0 : elapsedMillis - mDebugFailingElapsedClockPreviousValue);
|
||||
mDebugFailingElapsedClockPreviousValue = elapsedMillis;
|
||||
pulledData.add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls various data.
|
||||
*/
|
||||
@@ -778,16 +728,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
||||
long wallClockNanos = SystemClock.currentTimeMicro() * 1000L;
|
||||
switch (tagId) {
|
||||
|
||||
case StatsLog.DEBUG_ELAPSED_CLOCK: {
|
||||
pullDebugElapsedClock(tagId, elapsedNanos, wallClockNanos, ret);
|
||||
break;
|
||||
}
|
||||
|
||||
case StatsLog.DEBUG_FAILING_ELAPSED_CLOCK: {
|
||||
pullDebugFailingElapsedClock(tagId, elapsedNanos, wallClockNanos, ret);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
Slog.w(TAG, "No such tagId data as " + tagId);
|
||||
return null;
|
||||
|
||||
10
cmds/statsd/src/external/StatsPullerManager.cpp
vendored
10
cmds/statsd/src/external/StatsPullerManager.cpp
vendored
@@ -86,16 +86,6 @@ std::map<PullerKey, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
|
||||
{{.atomTag = android::util::BATTERY_CYCLE_COUNT},
|
||||
{.puller = new ResourceHealthManagerPuller(android::util::BATTERY_CYCLE_COUNT)}},
|
||||
|
||||
// DebugElapsedClock.
|
||||
{{.atomTag = android::util::DEBUG_ELAPSED_CLOCK},
|
||||
{.additiveFields = {1, 2, 3, 4},
|
||||
.puller = new StatsCompanionServicePuller(android::util::DEBUG_ELAPSED_CLOCK)}},
|
||||
|
||||
// DebugFailingElapsedClock.
|
||||
{{.atomTag = android::util::DEBUG_FAILING_ELAPSED_CLOCK},
|
||||
{.additiveFields = {1, 2, 3, 4},
|
||||
.puller = new StatsCompanionServicePuller(android::util::DEBUG_FAILING_ELAPSED_CLOCK)}},
|
||||
|
||||
// TrainInfo.
|
||||
{{.atomTag = android::util::TRAIN_INFO}, {.puller = new TrainInfoPuller()}},
|
||||
|
||||
|
||||
@@ -2274,20 +2274,104 @@ public class StatsPullAtomService extends SystemService {
|
||||
return StatsManager.PULL_SUCCESS;
|
||||
}
|
||||
|
||||
private final Object mDebugElapsedClockLock = new Object();
|
||||
private long mDebugElapsedClockPreviousValue = 0;
|
||||
private long mDebugElapsedClockPullCount = 0;
|
||||
|
||||
private void registerDebugElapsedClock() {
|
||||
// No op.
|
||||
int tagId = StatsLog.DEBUG_ELAPSED_CLOCK;
|
||||
PullAtomMetadata metadata = PullAtomMetadata.newBuilder()
|
||||
.setAdditiveFields(new int[] {1, 2, 3, 4})
|
||||
.build();
|
||||
mStatsManager.registerPullAtomCallback(
|
||||
tagId,
|
||||
metadata,
|
||||
(atomTag, data) -> pullDebugElapsedClock(atomTag, data),
|
||||
BackgroundThread.getExecutor()
|
||||
);
|
||||
}
|
||||
|
||||
private void pullDebugElapsedClock() {
|
||||
// No op.
|
||||
private int pullDebugElapsedClock(int atomTag, List<StatsEvent> pulledData) {
|
||||
final long elapsedMillis = SystemClock.elapsedRealtime();
|
||||
|
||||
synchronized (mDebugElapsedClockLock) {
|
||||
final long clockDiffMillis = mDebugElapsedClockPreviousValue == 0
|
||||
? 0 : elapsedMillis - mDebugElapsedClockPreviousValue;
|
||||
|
||||
StatsEvent e = StatsEvent.newBuilder()
|
||||
.setAtomId(atomTag)
|
||||
.writeLong(mDebugElapsedClockPullCount)
|
||||
.writeLong(elapsedMillis)
|
||||
// Log it twice to be able to test multi-value aggregation from ValueMetric.
|
||||
.writeLong(elapsedMillis)
|
||||
.writeLong(clockDiffMillis)
|
||||
.writeInt(1 /* always set */)
|
||||
.build();
|
||||
pulledData.add(e);
|
||||
|
||||
if (mDebugElapsedClockPullCount % 2 == 1) {
|
||||
StatsEvent e2 = StatsEvent.newBuilder()
|
||||
.setAtomId(atomTag)
|
||||
.writeLong(mDebugElapsedClockPullCount)
|
||||
.writeLong(elapsedMillis)
|
||||
// Log it twice to be able to test multi-value aggregation from ValueMetric.
|
||||
.writeLong(elapsedMillis)
|
||||
.writeLong(clockDiffMillis)
|
||||
.writeInt(2 /* set on odd pulls */)
|
||||
.build();
|
||||
pulledData.add(e2);
|
||||
}
|
||||
|
||||
mDebugElapsedClockPullCount++;
|
||||
mDebugElapsedClockPreviousValue = elapsedMillis;
|
||||
}
|
||||
|
||||
return StatsManager.PULL_SUCCESS;
|
||||
}
|
||||
|
||||
private final Object mDebugFailingElapsedClockLock = new Object();
|
||||
private long mDebugFailingElapsedClockPreviousValue = 0;
|
||||
private long mDebugFailingElapsedClockPullCount = 0;
|
||||
|
||||
private void registerDebugFailingElapsedClock() {
|
||||
// No op.
|
||||
int tagId = StatsLog.DEBUG_FAILING_ELAPSED_CLOCK;
|
||||
PullAtomMetadata metadata = PullAtomMetadata.newBuilder()
|
||||
.setAdditiveFields(new int[] {1, 2, 3, 4})
|
||||
.build();
|
||||
mStatsManager.registerPullAtomCallback(
|
||||
tagId,
|
||||
metadata,
|
||||
(atomTag, data) -> pullDebugFailingElapsedClock(atomTag, data),
|
||||
BackgroundThread.getExecutor()
|
||||
);
|
||||
}
|
||||
|
||||
private void pullDebugFailingElapsedClock() {
|
||||
// No op.
|
||||
private int pullDebugFailingElapsedClock(int atomTag, List<StatsEvent> pulledData) {
|
||||
final long elapsedMillis = SystemClock.elapsedRealtime();
|
||||
|
||||
synchronized (mDebugFailingElapsedClockLock) {
|
||||
// Fails every 5 buckets.
|
||||
if (mDebugFailingElapsedClockPullCount++ % 5 == 0) {
|
||||
mDebugFailingElapsedClockPreviousValue = elapsedMillis;
|
||||
Slog.e(TAG, "Failing debug elapsed clock");
|
||||
return StatsManager.PULL_SKIP;
|
||||
}
|
||||
|
||||
StatsEvent e = StatsEvent.newBuilder()
|
||||
.setAtomId(atomTag)
|
||||
.writeLong(mDebugFailingElapsedClockPullCount)
|
||||
.writeLong(elapsedMillis)
|
||||
// Log it twice to be able to test multi-value aggregation from ValueMetric.
|
||||
.writeLong(elapsedMillis)
|
||||
.writeLong(mDebugFailingElapsedClockPreviousValue == 0
|
||||
? 0 : elapsedMillis - mDebugFailingElapsedClockPreviousValue)
|
||||
.build();
|
||||
pulledData.add(e);
|
||||
|
||||
mDebugFailingElapsedClockPreviousValue = elapsedMillis;
|
||||
}
|
||||
|
||||
return StatsManager.PULL_SUCCESS;
|
||||
}
|
||||
|
||||
private void registerBuildInformation() {
|
||||
|
||||
Reference in New Issue
Block a user