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

Commit fe2dde81 authored by Bookatz's avatar Bookatz
Browse files

statsd events/gauge: remove WallClockTime

EventMetricData stores wall_clock_timestamp_nanos.
It is expensive, costing 10 bytes per event and evidently not needed.
Similar for GaugeMetricData.

Bug: 113072343
Test: make -j8 statsd_test && adb sync data && adb shell data/nativetest64/statsd_test/statsd_test
Test: run cts-dev -m CtsStatsdHostTestCases
Test: Manually confirm that events/gauges don't have wallclock
Change-Id: Iae978a434354c049e1fa61d42536be981c862b4f
parent 2aba8d3d
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ const int FIELD_ID_DATA = 1;
// for EventMetricData
const int FIELD_ID_ELAPSED_TIMESTAMP_NANOS = 1;
const int FIELD_ID_ATOMS = 2;
const int FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS = 3;

EventMetricProducer::EventMetricProducer(const ConfigKey& key, const EventMetric& metric,
                                         const int conditionIndex,
@@ -146,13 +145,9 @@ void EventMetricProducer::onMatchedLogEventInternalLocked(
    if (truncateTimestamp) {
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
            (long long)truncateTimestampNsToFiveMinutes(event.GetElapsedTimestampNs()));
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS,
            (long long)truncateTimestampNsToFiveMinutes(getWallClockNs()));
    } else {
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
            (long long)event.GetElapsedTimestampNs());
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS,
            (long long)getWallClockNs());
    }

    uint64_t eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS);
+1 −9
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ const int FIELD_ID_DIMENSION_LEAF_IN_CONDITION = 5;
// for GaugeBucketInfo
const int FIELD_ID_ATOM = 3;
const int FIELD_ID_ELAPSED_ATOM_TIMESTAMP = 4;
const int FIELD_ID_WALL_CLOCK_ATOM_TIMESTAMP = 5;
const int FIELD_ID_BUCKET_NUM = 6;
const int FIELD_ID_START_BUCKET_ELAPSED_MILLIS = 7;
const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 8;
@@ -286,16 +285,9 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
                    const int64_t elapsedTimestampNs =  truncateTimestamp ?
                        truncateTimestampNsToFiveMinutes(atom.mElapsedTimestamps) :
                            atom.mElapsedTimestamps;
                    const int64_t wallClockNs = truncateTimestamp ?
                        truncateTimestampNsToFiveMinutes(atom.mWallClockTimestampNs) :
                            atom.mWallClockTimestampNs;
                    protoOutput->write(
                        FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP,
                        (long long)elapsedTimestampNs);
                    protoOutput->write(
                        FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED |
                            FIELD_ID_WALL_CLOCK_ATOM_TIMESTAMP,
                        (long long)wallClockNs);
                }
            }
            protoOutput->end(bucketInfoToken);
@@ -437,7 +429,7 @@ void GaugeMetricProducer::onMatchedLogEventInternalLocked(
    if ((*mCurrentSlicedBucket)[eventKey].size() >= mGaugeAtomsPerDimensionLimit) {
        return;
    }
    GaugeAtom gaugeAtom(getGaugeFields(event), eventTimeNs, getWallClockNs());
    GaugeAtom gaugeAtom(getGaugeFields(event), eventTimeNs);
    (*mCurrentSlicedBucket)[eventKey].push_back(gaugeAtom);
    // Anomaly detection on gauge metric only works when there is one numeric
    // field specified.
+2 −3
Original line number Diff line number Diff line
@@ -33,12 +33,11 @@ namespace os {
namespace statsd {

struct GaugeAtom {
    GaugeAtom(std::shared_ptr<vector<FieldValue>> fields, int64_t elapsedTimeNs, int64_t wallClockNs)
        : mFields(fields), mElapsedTimestamps(elapsedTimeNs), mWallClockTimestampNs(wallClockNs) {
    GaugeAtom(std::shared_ptr<vector<FieldValue>> fields, int64_t elapsedTimeNs)
        : mFields(fields), mElapsedTimestamps(elapsedTimeNs) {
    }
    std::shared_ptr<vector<FieldValue>> mFields;
    int64_t mElapsedTimestamps;
    int64_t mWallClockTimestampNs;
};

struct GaugeBucket {
+2 −2
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ message EventMetricData {

  optional Atom atom = 2;

  optional int64 wall_clock_timestamp_nanos = 3;
  optional int64 wall_clock_timestamp_nanos = 3 [deprecated = true];
}

message CountBucketInfo {
@@ -142,7 +142,7 @@ message GaugeBucketInfo {

  repeated int64 elapsed_timestamp_nanos = 4;

  repeated int64 wall_clock_timestamp_nanos = 5;
  repeated int64 wall_clock_timestamp_nanos = 5 [deprecated = true];

  optional int64 bucket_num = 6;

+2 −3
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvents) {
    EXPECT_EQ(1, data.bucket_info(0).atom_size());
    EXPECT_EQ(1, data.bucket_info(0).elapsed_timestamp_nanos_size());
    EXPECT_EQ(configAddedTimeNs + 55, data.bucket_info(0).elapsed_timestamp_nanos(0));
    EXPECT_EQ(1, data.bucket_info(0).wall_clock_timestamp_nanos_size());
    EXPECT_EQ(0, data.bucket_info(0).wall_clock_timestamp_nanos_size());
    EXPECT_EQ(baseTimeNs + 2 * bucketSizeNs, data.bucket_info(0).start_bucket_elapsed_nanos());
    EXPECT_EQ(baseTimeNs + 3 * bucketSizeNs, data.bucket_info(0).end_bucket_elapsed_nanos());
    EXPECT_FALSE(data.bucket_info(0).atom(0).temperature().sensor_name().empty());
@@ -270,7 +270,7 @@ TEST(GaugeMetricE2eTest, TestAllConditionChangesSamplePulledEvents) {
    EXPECT_EQ(1, data.bucket_info(0).atom_size());
    EXPECT_EQ(1, data.bucket_info(0).elapsed_timestamp_nanos_size());
    EXPECT_EQ(configAddedTimeNs + 55, data.bucket_info(0).elapsed_timestamp_nanos(0));
    EXPECT_EQ(1, data.bucket_info(0).wall_clock_timestamp_nanos_size());
    EXPECT_EQ(0, data.bucket_info(0).wall_clock_timestamp_nanos_size());
    EXPECT_EQ(baseTimeNs + 2 * bucketSizeNs, data.bucket_info(0).start_bucket_elapsed_nanos());
    EXPECT_EQ(baseTimeNs + 3 * bucketSizeNs, data.bucket_info(0).end_bucket_elapsed_nanos());
    EXPECT_FALSE(data.bucket_info(0).atom(0).temperature().sensor_name().empty());
@@ -374,7 +374,6 @@ TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvent_LateAlarm) {
    EXPECT_EQ(1, data.bucket_info(0).atom_size());
    EXPECT_EQ(1, data.bucket_info(0).elapsed_timestamp_nanos_size());
    EXPECT_EQ(configAddedTimeNs + 55, data.bucket_info(0).elapsed_timestamp_nanos(0));
    EXPECT_EQ(1, data.bucket_info(0).wall_clock_timestamp_nanos_size());
    EXPECT_EQ(baseTimeNs + 2 * bucketSizeNs, data.bucket_info(0).start_bucket_elapsed_nanos());
    EXPECT_EQ(baseTimeNs + 3 * bucketSizeNs, data.bucket_info(0).end_bucket_elapsed_nanos());
    EXPECT_FALSE(data.bucket_info(0).atom(0).temperature().sensor_name().empty());
Loading