Merge "Fix test failure in testProcessStateByPulling" into rvc-dev

This commit is contained in:
Jing Ji
2020-04-24 23:05:08 +00:00
committed by Android (Google) Code Review
6 changed files with 67 additions and 23 deletions

View File

@@ -32,14 +32,24 @@ public class ProtoUtils {
* Dump AggStats to ProtoOutputStream
*/
public static void toAggStatsProto(ProtoOutputStream proto, long fieldId,
long min, long average, long max) {
long min, long average, long max, int meanKb, int maxKb) {
final long aggStatsToken = proto.start(fieldId);
proto.write(AggStats.MIN, min);
proto.write(AggStats.AVERAGE, average);
proto.write(AggStats.MAX, max);
proto.write(AggStats.MEAN_KB, meanKb);
proto.write(AggStats.MAX_KB, maxKb);
proto.end(aggStatsToken);
}
/**
* Dump AggStats to ProtoOutputStream
*/
public static void toAggStatsProto(ProtoOutputStream proto, long fieldId,
long min, long average, long max) {
toAggStatsProto(proto, fieldId, min, average, max, 0, 0);
}
/**
* Dump Duration to ProtoOutputStream
*/

View File

@@ -550,7 +550,7 @@ public final class DumpUtils {
// screen state is in lowest 0xf bits, process state is in next 0xf bits up
try {
proto.write(stateId, STATE_PROTO_ENUMS[state >> 0xf]);
proto.write(stateId, state >> 0xf);
} catch (IndexOutOfBoundsException e) {
proto.write(stateId, ProcessStatsEnums.PROCESS_STATE_UNKNOWN);
}

View File

@@ -1459,16 +1459,16 @@ public final class ProcessState {
for (int i = 0; i < mPssTable.getKeyCount(); i++) {
final int key = mPssTable.getKeyAt(i);
final int type = SparseMappingTable.getIdFromKey(key);
if (durationByState.indexOfKey(type) < 0) {
final int aggregatedType = DumpUtils.aggregateCurrentProcessState(type);
if (durationByState.indexOfKey(aggregatedType) < 0) {
// state without duration should not have stats!
continue;
}
final int aggregatedType = DumpUtils.aggregateCurrentProcessState(type);
long[] rssMeanAndMax = mPssTable.getRssMeanAndMax(key);
// compute mean * duration, then store sum of that in meanRssByState
long meanTimesDuration = rssMeanAndMax[0] * mDurations.getValue(key);
long meanTimesDuration = rssMeanAndMax[0] * mDurations.getValueForId((byte) type);
if (meanRssByState.indexOfKey(aggregatedType) >= 0) {
meanRssByState.put(aggregatedType,
meanTimesDuration + meanRssByState.get(aggregatedType));
@@ -1492,8 +1492,10 @@ public final class ProcessState {
// these data structures should be consistent
continue;
}
final long duration = durationByState.get(aggregatedKey);
meanRssByState.put(aggregatedKey,
meanRssByState.get(aggregatedKey) / durationByState.get(aggregatedKey));
duration > 0 ? (meanRssByState.get(aggregatedKey) / duration)
: meanRssByState.get(aggregatedKey));
}
// build the output
@@ -1508,14 +1510,16 @@ public final class ProcessState {
DumpUtils.printAggregatedProcStateTagProto(proto,
ProcessStatsStateProto.SCREEN_STATE,
ProcessStatsStateProto.PROCESS_STATE,
ProcessStatsStateProto.PROCESS_STATE_AGGREGATED,
aggregatedKey);
proto.write(ProcessStatsStateProto.DURATION_MS, durationByState.get(aggregatedKey));
ProtoUtils.toAggStatsProto(proto, ProcessStatsStateProto.RSS,
0, /* do not output a minimum value */
meanRssByState.get(aggregatedKey),
maxRssByState.get(aggregatedKey));
0, /* do not output an average value */
0, /* do not output a max value */
(int) meanRssByState.get(aggregatedKey),
(int) maxRssByState.get(aggregatedKey));
proto.end(stateToken);
}

View File

@@ -104,7 +104,7 @@ message ProcessStatsAvailablePagesProto {
repeated int32 pages_per_order = 4;
}
// Next Tag: 10
// Next Tag: 13
message ProcessStatsStateProto {
option (android.msg_privacy).dest = DEST_AUTOMATIC;
@@ -114,13 +114,20 @@ message ProcessStatsStateProto {
// this enum list is from frameworks/base/core/java/com/android/internal/app/procstats/ProcessStats.java
// and not frameworks/base/core/java/android/app/ActivityManager.java
optional ProcessState process_state = 3;
optional ProcessState process_state = 3 [deprecated = true];
// the AggregatedProcessState needs to keep sync with ProcessStateAggregated
optional AggregatedProcessState process_state_aggregated = 10;
// Millisecond uptime duration spent in this state
optional int64 duration_ms = 4;
optional int64 duration_ms = 4 [deprecated = true];
// Same as above, but with minute resolution so it fits into an int32.
optional int32 duration_minutes = 11;
// Millisecond elapsed realtime duration spent in this state
optional int64 realtime_duration_ms = 9;
optional int64 realtime_duration_ms = 9 [deprecated = true];
// Same as above, but with minute resolution so it fits into an int32.
optional int32 realtime_duration_minutes = 12;
// # of samples taken
optional int32 sample_size = 5;

View File

@@ -27,11 +27,16 @@ option java_multiple_files = true;
message AggStats {
option (android.msg_privacy).dest = DEST_AUTOMATIC;
optional int64 min = 1;
optional int64 min = 1 [deprecated = true];
optional int64 average = 2;
optional int64 average = 2 [deprecated = true];
optional int64 max = 3;
optional int64 max = 3 [deprecated = true];
// These are all in kilobyte resolution. Can fit in int32, so smaller on the wire than the above
// int64 fields.
optional int32 mean_kb = 4;
optional int32 max_kb = 5;
}
/**
@@ -43,4 +48,4 @@ message Duration {
optional int64 start_ms = 1;
optional int64 end_ms = 2;
}
}

View File

@@ -590,7 +590,7 @@ public final class ProcessStatsService extends IProcessStats.Stub {
}
if (doAggregate) {
mergedStats.add(stats);
} else {
} else if (committedStats != null) {
committedStats.add(protoToParcelFileDescriptor(stats, section));
}
if (stats.mReadError != null) {
@@ -604,7 +604,7 @@ public final class ProcessStatsService extends IProcessStats.Stub {
Slog.w(TAG, "Failure to read and parse commit file " + fileName, e);
}
}
if (doAggregate) {
if (doAggregate && committedStats != null) {
committedStats.add(protoToParcelFileDescriptor(mergedStats, section));
}
return newHighWaterMark;
@@ -789,11 +789,16 @@ public final class ProcessStatsService extends IProcessStats.Stub {
long ident = Binder.clearCallingIdentity();
try {
if (args.length > 0 && "--proto".equals(args[0])) {
dumpProto(fd);
} else {
dumpInner(pw, args);
if (args.length > 0) {
if ("--proto".equals(args[0])) {
dumpProto(fd);
return;
} else if ("--statsd".equals(args[0])) {
dumpProtoForStatsd(fd);
return;
}
}
dumpInner(pw, args);
} finally {
Binder.restoreCallingIdentity(ident);
}
@@ -1251,4 +1256,17 @@ public final class ProcessStatsService extends IProcessStats.Stub {
proto.flush();
}
/**
* Dump proto for the statsd, mainly for testing.
*/
private void dumpProtoForStatsd(FileDescriptor fd) {
final ProtoOutputStream proto = new ProtoOutputStream(fd);
ProcessStats procStats = new ProcessStats(false);
getCommittedStatsMerged(0, 0, true, null, procStats);
procStats.dumpAggregatedProtoForStatsd(proto);
proto.flush();
}
}