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

Commit c40a19d2 authored by Yao Chen's avatar Yao Chen
Browse files

Add uid field annotation in atoms.proto and statd memory usage optimization.

[memory]
  statsd binary size from 664k -> 600k
  memory usage 1978k -> 1813k (with no configs)
  + Avoid initialize any static map in statslog.h to avoid many copies of the map in each include.
    - Do it in cpp so that it is initialized only in places that use them

[Uid annotation]
+ Uid annotation is needed for extracting uid from dimension for UidCpuPuller.
+ After the change, stand-alone uids don't need to be in field 1 anymore.
+ Also added exclusive bit annotation in AppDied
+ Currently only allow one uid field in an Atom. This is to keep things simple until
  we find an exception.

Test: statsd_test
Bug: 73958484
Bug: 72129300

Change-Id: I8a916d5c00d5930e24ae7e0825a57dea19c0e744
parent ddbb9d00
Loading
Loading
Loading
Loading
+16 −8
Original line number Original line Diff line number Diff line
@@ -112,8 +112,8 @@ void updateUid(Value* value, int hostUid) {
}
}


void StatsLogProcessor::mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event) const {
void StatsLogProcessor::mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event) const {
    if (android::util::kAtomsWithAttributionChain.find(event->GetTagId()) !=
    if (android::util::AtomsInfo::kAtomsWithAttributionChain.find(event->GetTagId()) !=
        android::util::kAtomsWithAttributionChain.end()) {
        android::util::AtomsInfo::kAtomsWithAttributionChain.end()) {
        for (auto& value : *(event->getMutableValues())) {
        for (auto& value : *(event->getMutableValues())) {
            if (value.mField.getPosAtDepth(0) > kAttributionField) {
            if (value.mField.getPosAtDepth(0) > kAttributionField) {
                break;
                break;
@@ -123,12 +123,20 @@ void StatsLogProcessor::mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event
                updateUid(&value.mValue, hostUid);
                updateUid(&value.mValue, hostUid);
            }
            }
        }
        }
    } else if (android::util::kAtomsWithUidField.find(event->GetTagId()) !=
    } else {
                       android::util::kAtomsWithUidField.end() &&
        auto it = android::util::AtomsInfo::kAtomsWithUidField.find(event->GetTagId());
               event->getValues().size() > 0 && (event->getValues())[0].mValue.getType() == INT) {
        if (it != android::util::AtomsInfo::kAtomsWithUidField.end()) {
        Value& value = (*event->getMutableValues())[0].mValue;
            int uidField = it->second;  // uidField is the field number in proto,
                                        // starting from 1
            if (uidField > 0 && (int)event->getValues().size() >= uidField &&
                (event->getValues())[uidField - 1].mValue.getType() == INT) {
                Value& value = (*event->getMutableValues())[uidField - 1].mValue;
                const int hostUid = mUidMap->getHostUidOrSelf(value.int_value);
                const int hostUid = mUidMap->getHostUidOrSelf(value.int_value);
                updateUid(&value, hostUid);
                updateUid(&value, hostUid);
            } else {
                ALOGE("Malformed log, uid not found. %s", event->ToString().c_str());
            }
        }
    }
    }
}
}


+3 −0
Original line number Original line Diff line number Diff line
@@ -67,4 +67,7 @@ message StateAtomFieldOption {
extend google.protobuf.FieldOptions {
extend google.protobuf.FieldOptions {
    // Flags to decorate an atom that presents a state change.
    // Flags to decorate an atom that presents a state change.
    optional StateAtomFieldOption stateFieldOption = 50000;
    optional StateAtomFieldOption stateFieldOption = 50000;

    // Flags to decorate the uid fields in an atom.
    optional bool is_uid = 50001 [default = false];
}
}
 No newline at end of file
+35 −31
Original line number Original line Diff line number Diff line
@@ -208,7 +208,7 @@ message ScreenStateChanged {
 *   frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
 *   frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
 */
 */
message UidProcessStateChanged {
message UidProcessStateChanged {
    optional int32 uid = 1 [(stateFieldOption).option = PRIMARY];
    optional int32 uid = 1 [(stateFieldOption).option = PRIMARY, (is_uid) = true];


    // The state, from frameworks/base/core/proto/android/app/enums.proto.
    // The state, from frameworks/base/core/proto/android/app/enums.proto.
    optional android.app.ProcessStateEnum state = 2 [(stateFieldOption).option = EXCLUSIVE];
    optional android.app.ProcessStateEnum state = 2 [(stateFieldOption).option = EXCLUSIVE];
@@ -222,7 +222,7 @@ message UidProcessStateChanged {
 */
 */
message ProcessLifeCycleStateChanged {
message ProcessLifeCycleStateChanged {
    // TODO: should be a string tagged w/ uid annotation
    // TODO: should be a string tagged w/ uid annotation
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // The process name (usually same as the app name).
    // The process name (usually same as the app name).
    optional string name = 2;
    optional string name = 2;
@@ -592,7 +592,7 @@ message WakeupAlarmOccurred {
 */
 */
message MobileRadioPowerStateChanged {
message MobileRadioPowerStateChanged {
    // TODO: Add attribution instead of uid?
    // TODO: Add attribution instead of uid?
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // Power state, from frameworks/base/core/proto/android/telephony/enums.proto.
    // Power state, from frameworks/base/core/proto/android/telephony/enums.proto.
    optional android.telephony.DataConnectionPowerStateEnum state = 2;
    optional android.telephony.DataConnectionPowerStateEnum state = 2;
@@ -607,7 +607,7 @@ message MobileRadioPowerStateChanged {
 */
 */
message WifiRadioPowerStateChanged {
message WifiRadioPowerStateChanged {
    // TODO: Add attribution instead of uid?
    // TODO: Add attribution instead of uid?
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // Power state, from frameworks/base/core/proto/android/telephony/enums.proto.
    // Power state, from frameworks/base/core/proto/android/telephony/enums.proto.
    optional android.telephony.DataConnectionPowerStateEnum state = 2;
    optional android.telephony.DataConnectionPowerStateEnum state = 2;
@@ -1079,7 +1079,8 @@ message ChargeCyclesReported {
 */
 */
message DaveyOccurred {
message DaveyOccurred {
    // The UID that logged this atom.
    // The UID that logged this atom.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];
    ;


    // Amount of time it took to render the frame. Should be >=700ms.
    // Amount of time it took to render the frame. Should be >=700ms.
    optional int64 jank_duration_millis = 2;
    optional int64 jank_duration_millis = 2;
@@ -1136,7 +1137,7 @@ message SettingChanged {
  *   frameworks/base/services/core/java/com/android/server/am/ActivityRecord.java
  *   frameworks/base/services/core/java/com/android/server/am/ActivityRecord.java
 */
 */
message ActivityForegroundStateChanged {
message ActivityForegroundStateChanged {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];
    optional string pkg_name = 2;
    optional string pkg_name = 2;
    optional string class_name = 3;
    optional string class_name = 3;


@@ -1154,7 +1155,7 @@ message ActivityForegroundStateChanged {
 */
 */
message DropboxErrorChanged {
message DropboxErrorChanged {
    // The uid if available. -1 means not available.
    // The uid if available. -1 means not available.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // Tag used when recording this error to dropbox. Contains data_ or system_ prefix.
    // Tag used when recording this error to dropbox. Contains data_ or system_ prefix.
    optional string tag = 2;
    optional string tag = 2;
@@ -1185,7 +1186,7 @@ message DropboxErrorChanged {
 */
 */
message AppBreadcrumbReported {
message AppBreadcrumbReported {
    // The uid of the application that sent this custom atom.
    // The uid of the application that sent this custom atom.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // An arbitrary label chosen by the developer. For Android P, the label should be in [0, 16).
    // An arbitrary label chosen by the developer. For Android P, the label should be in [0, 16).
    optional int32 label = 2;
    optional int32 label = 2;
@@ -1209,7 +1210,7 @@ message AppBreadcrumbReported {
 */
 */
message AnomalyDetected {
message AnomalyDetected {
    // Uid that owns the config whose anomaly detection alert fired.
    // Uid that owns the config whose anomaly detection alert fired.
    optional int32 config_uid = 1;
    optional int32 config_uid = 1 [(is_uid) = true];


    // Id of the config whose anomaly detection alert fired.
    // Id of the config whose anomaly detection alert fired.
    optional int64 config_id = 2;
    optional int64 config_id = 2;
@@ -1220,7 +1221,7 @@ message AnomalyDetected {


message AppStartChanged {
message AppStartChanged {
    // The uid if available. -1 means not available.
    // The uid if available. -1 means not available.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // The app package name.
    // The app package name.
    optional string pkg_name = 2;
    optional string pkg_name = 2;
@@ -1267,7 +1268,7 @@ message AppStartChanged {


message AppStartCancelChanged {
message AppStartCancelChanged {
    // The uid if available. -1 means not available.
    // The uid if available. -1 means not available.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // The app package name.
    // The app package name.
    optional string pkg_name = 2;
    optional string pkg_name = 2;
@@ -1287,7 +1288,7 @@ message AppStartCancelChanged {


message AppStartFullyDrawnChanged {
message AppStartFullyDrawnChanged {
    // The uid if available. -1 means not available.
    // The uid if available. -1 means not available.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // The app package name.
    // The app package name.
    optional string pkg_name = 2;
    optional string pkg_name = 2;
@@ -1318,7 +1319,7 @@ message AppStartFullyDrawnChanged {
 */
 */
message PictureInPictureStateChanged {
message PictureInPictureStateChanged {
    // -1 if it is not available
    // -1 if it is not available
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    optional string short_name = 2;
    optional string short_name = 2;


@@ -1337,7 +1338,7 @@ message PictureInPictureStateChanged {
 *     services/core/java/com/android/server/wm/Session.java
 *     services/core/java/com/android/server/wm/Session.java
 */
 */
message OverlayStateChanged {
message OverlayStateChanged {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    optional string package_name = 2;
    optional string package_name = 2;


@@ -1358,7 +1359,7 @@ message OverlayStateChanged {
 *     //frameworks/base/services/core/java/com/android/server/am/ActiveServices.java
 *     //frameworks/base/services/core/java/com/android/server/am/ActiveServices.java
 */
 */
message ForegroundServiceStateChanged {
message ForegroundServiceStateChanged {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];
    // package_name + "/" + class_name
    // package_name + "/" + class_name
    optional string short_name = 2;
    optional string short_name = 2;


@@ -1378,6 +1379,7 @@ message ForegroundServiceStateChanged {
 *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 */
 */
message IsolatedUidChanged {
message IsolatedUidChanged {
    // NOTE: DO NOT annotate uid field in this atom. This atom is specially handled in statsd.
    // The host UID. Generally, we should attribute metrics from the isolated uid to the host uid.
    // The host UID. Generally, we should attribute metrics from the isolated uid to the host uid.
    optional int32 parent_uid = 1;
    optional int32 parent_uid = 1;


@@ -1399,7 +1401,7 @@ message IsolatedUidChanged {
message PacketWakeupOccurred {
message PacketWakeupOccurred {
    // The uid owning the socket into which the packet was delivered, or -1 if the packet was
    // The uid owning the socket into which the packet was delivered, or -1 if the packet was
    // delivered nowhere.
    // delivered nowhere.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];
    // The interface name on which the packet was received.
    // The interface name on which the packet was received.
    optional string iface = 2;
    optional string iface = 2;
    // The ethertype value of the packet.
    // The ethertype value of the packet.
@@ -1427,7 +1429,7 @@ message PacketWakeupOccurred {
 */
 */
message AppStartMemoryStateCaptured {
message AppStartMemoryStateCaptured {
    // The uid if available. -1 means not available.
    // The uid if available. -1 means not available.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // The process name.
    // The process name.
    optional string process_name = 2;
    optional string process_name = 2;
@@ -1473,7 +1475,7 @@ message LmkStateChanged {
 */
 */
message LmkKillOccurred {
message LmkKillOccurred {
    // The uid if available. -1 means not available.
    // The uid if available. -1 means not available.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // The process name.
    // The process name.
    optional string process_name = 2;
    optional string process_name = 2;
@@ -1505,7 +1507,7 @@ message LmkKillOccurred {
 */
 */
message AppDied {
message AppDied {
    // timestamp(elapsedRealtime) of record creation
    // timestamp(elapsedRealtime) of record creation
    optional uint64 timestamp_millis = 1;
    optional uint64 timestamp_millis = 1 [(stateFieldOption).option = EXCLUSIVE];
}
}


//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
@@ -1519,7 +1521,7 @@ message AppDied {
 *   StatsCompanionService (using BatteryStats to get which interfaces are wifi)
 *   StatsCompanionService (using BatteryStats to get which interfaces are wifi)
 */
 */
message WifiBytesTransfer {
message WifiBytesTransfer {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    optional int64 rx_bytes = 2;
    optional int64 rx_bytes = 2;


@@ -1537,9 +1539,10 @@ message WifiBytesTransfer {
 *   StatsCompanionService (using BatteryStats to get which interfaces are wifi)
 *   StatsCompanionService (using BatteryStats to get which interfaces are wifi)
 */
 */
message WifiBytesTransferByFgBg {
message WifiBytesTransferByFgBg {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // 1 denotes foreground and 0 denotes background. This is called Set in NetworkStats.
    // 1 denotes foreground and 0 denotes background. This is called Set in
    // NetworkStats.
    optional int32 is_foreground = 2;
    optional int32 is_foreground = 2;


    optional int64 rx_bytes = 3;
    optional int64 rx_bytes = 3;
@@ -1558,7 +1561,7 @@ message WifiBytesTransferByFgBg {
 *   StatsCompanionService (using BatteryStats to get which interfaces are mobile data)
 *   StatsCompanionService (using BatteryStats to get which interfaces are mobile data)
 */
 */
message MobileBytesTransfer {
message MobileBytesTransfer {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    optional int64 rx_bytes = 2;
    optional int64 rx_bytes = 2;


@@ -1576,9 +1579,10 @@ message MobileBytesTransfer {
 *   StatsCompanionService (using BatteryStats to get which interfaces are mobile data)
 *   StatsCompanionService (using BatteryStats to get which interfaces are mobile data)
 */
 */
message MobileBytesTransferByFgBg {
message MobileBytesTransferByFgBg {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // 1 denotes foreground and 0 denotes background. This is called Set in NetworkStats.
    // 1 denotes foreground and 0 denotes background. This is called Set in
    // NetworkStats.
    optional int32 is_foreground = 2;
    optional int32 is_foreground = 2;


    optional int64 rx_bytes = 3;
    optional int64 rx_bytes = 3;
@@ -1597,7 +1601,7 @@ message MobileBytesTransferByFgBg {
 *   StatsCompanionService
 *   StatsCompanionService
 */
 */
message BluetoothBytesTransfer {
message BluetoothBytesTransfer {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    optional int64 rx_bytes = 2;
    optional int64 rx_bytes = 2;


@@ -1657,7 +1661,7 @@ message CpuTimePerFreq {
 * Note that isolated process uid time should be attributed to host uids.
 * Note that isolated process uid time should be attributed to host uids.
 */
 */
message CpuTimePerUid {
message CpuTimePerUid {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];
    optional uint64 user_time_millis = 2;
    optional uint64 user_time_millis = 2;
    optional uint64 sys_time_millis = 3;
    optional uint64 sys_time_millis = 3;
}
}
@@ -1668,7 +1672,7 @@ message CpuTimePerUid {
 * For each uid, we order the time by descending frequencies.
 * For each uid, we order the time by descending frequencies.
 */
 */
message CpuTimePerUidFreq {
message CpuTimePerUidFreq {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];
    optional uint32 freq_index = 2;
    optional uint32 freq_index = 2;
    optional uint64 time_millis = 3;
    optional uint64 time_millis = 3;
}
}
@@ -1750,7 +1754,7 @@ message BluetoothActivityInfo {
 */
 */
message ProcessMemoryState {
message ProcessMemoryState {
    // The uid if available. -1 means not available.
    // The uid if available. -1 means not available.
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];


    // The process name.
    // The process name.
    optional string process_name = 2;
    optional string process_name = 2;
@@ -1802,7 +1806,7 @@ message SystemUptime {
 * The file contains a monotonically increasing count of time for a single boot.
 * The file contains a monotonically increasing count of time for a single boot.
 */
 */
message CpuActiveTime {
message CpuActiveTime {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];
    optional uint64 time_millis = 2;
    optional uint64 time_millis = 2;
}
}


@@ -1816,7 +1820,7 @@ message CpuActiveTime {
 * The file contains a monotonically increasing count of time for a single boot.
 * The file contains a monotonically increasing count of time for a single boot.
 */
 */
message CpuClusterTime {
message CpuClusterTime {
    optional int32 uid = 1;
    optional int32 uid = 1 [(is_uid) = true];
    optional int32 cluster_index = 2;
    optional int32 cluster_index = 2;
    optional uint64 time_millis = 3;
    optional uint64 time_millis = 3;
}
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -112,7 +112,8 @@ void mergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const sp<Uid
        VLOG("Unknown pull atom id %d", tagId);
        VLOG("Unknown pull atom id %d", tagId);
        return;
        return;
    }
    }
    if (android::util::kAtomsWithUidField.find(tagId) == android::util::kAtomsWithUidField.end()) {
    if (android::util::AtomsInfo::kAtomsWithUidField.find(tagId) ==
        android::util::AtomsInfo::kAtomsWithUidField.end()) {
        VLOG("No uid to merge for atom %d", tagId);
        VLOG("No uid to merge for atom %d", tagId);
        return;
        return;
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -134,8 +134,8 @@ void EventMetricProducer::onMatchedLogEventInternalLocked(
    uint64_t wrapperToken =
    uint64_t wrapperToken =
            mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA);
            mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA);
    const bool truncateTimestamp =
    const bool truncateTimestamp =
        android::util::kNotTruncatingTimestampAtomWhiteList.find(event.GetTagId()) ==
            android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.find(event.GetTagId()) ==
        android::util::kNotTruncatingTimestampAtomWhiteList.end();
            android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.end();
    if (truncateTimestamp) {
    if (truncateTimestamp) {
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
            (long long)truncateTimestampNsToFiveMinutes(event.GetElapsedTimestampNs()));
            (long long)truncateTimestampNsToFiveMinutes(event.GetElapsedTimestampNs()));
Loading