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

Commit 3fa5d7fb authored by Yangster-mac's avatar Yangster-mac
Browse files

Add wall clock timestamp for ConfigMetricsReport and gauge atoms.

Fix the bug when serializing multiple atoms in gauge metric

BUG: b/74159560

Test: new test for ALL_CONDITION_CHANGES sampling method.
Change-Id: I6d33c1efbac92b6e13be2d64c323e090cb1f84aa
parent 3dc91c14
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ LOCAL_SRC_FILES := \
    tests/e2e/WakelockDuration_e2e_test.cpp \
    tests/e2e/MetricConditionLink_e2e_test.cpp \
    tests/e2e/Attribution_e2e_test.cpp \
    tests/e2e/GaugeMetric_e2e_test.cpp \
    tests/e2e/GaugeMetric_e2e_push_test.cpp \
    tests/e2e/DimensionInCondition_e2e_combination_AND_cond_test.cpp \
    tests/e2e/DimensionInCondition_e2e_combination_OR_cond_test.cpp \
    tests/e2e/DimensionInCondition_e2e_simple_cond_test.cpp
+9 −0
Original line number Diff line number Diff line
@@ -62,6 +62,9 @@ const int FIELD_ID_ID = 2;
const int FIELD_ID_UID_MAP = 2;
const int FIELD_ID_LAST_REPORT_ELAPSED_NANOS = 3;
const int FIELD_ID_CURRENT_REPORT_ELAPSED_NANOS = 4;
const int FIELD_ID_LAST_REPORT_WALL_CLOCK_NANOS = 5;
const int FIELD_ID_CURRENT_REPORT_WALL_CLOCK_NANOS = 6;


#define STATS_DATA_DIR "/data/misc/stats-data"

@@ -260,6 +263,8 @@ void StatsLogProcessor::onDumpReportLocked(const ConfigKey& key, const uint64_t
            proto.start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_REPORTS);

    int64_t lastReportTimeNs = it->second->getLastReportTimeNs();
    int64_t lastReportWallClockNs = it->second->getLastReportWallClockNs();

    // First, fill in ConfigMetricsReport using current data on memory, which
    // starts from filling in StatsLogReport's.
    it->second->onDumpReport(dumpTimeStampNs, &proto);
@@ -276,6 +281,10 @@ void StatsLogProcessor::onDumpReportLocked(const ConfigKey& key, const uint64_t
                (long long)lastReportTimeNs);
    proto.write(FIELD_TYPE_INT64 | FIELD_ID_CURRENT_REPORT_ELAPSED_NANOS,
                (long long)dumpTimeStampNs);
    proto.write(FIELD_TYPE_INT64 | FIELD_ID_LAST_REPORT_WALL_CLOCK_NANOS,
                (long long)lastReportWallClockNs);
    proto.write(FIELD_TYPE_INT64 | FIELD_ID_CURRENT_REPORT_WALL_CLOCK_NANOS,
                (long long)getWallClockNs());

    // End of ConfigMetricsReport (reports).
    proto.end(reportsToken);
+14 −6
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ const int FIELD_ID_START_BUCKET_ELAPSED_NANOS = 1;
const int FIELD_ID_END_BUCKET_ELAPSED_NANOS = 2;
const int FIELD_ID_ATOM = 3;
const int FIELD_ID_ELAPSED_ATOM_TIMESTAMP = 4;
const int FIELD_ID_WALL_CLOCK_ATOM_TIMESTAMP = 5;

GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric& metric,
                                         const int conditionIndex,
@@ -168,21 +169,28 @@ void GaugeMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
                               (long long)bucket.mBucketEndNs);

            if (!bucket.mGaugeAtoms.empty()) {
                uint64_t atomsToken =
                    protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_ATOM);
                for (const auto& atom : bucket.mGaugeAtoms) {
                    uint64_t atomsToken =
                        protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED |
                                           FIELD_ID_ATOM);
                    writeFieldValueTreeToStream(mTagId, *(atom.mFields), protoOutput);
                }
                    protoOutput->end(atomsToken);
                for (const auto& atom : bucket.mGaugeAtoms) {
                }
                const bool truncateTimestamp =
                    android::util::kNotTruncatingTimestampAtomWhiteList.find(mTagId) ==
                    android::util::kNotTruncatingTimestampAtomWhiteList.end();
                const int64_t wall_clock_ns = truncateTimestamp ?
                    truncateTimestampNsToFiveMinutes(getWallClockNs()) : getWallClockNs();
                for (const auto& atom : bucket.mGaugeAtoms) {
                    int64_t timestampNs =  truncateTimestamp ?
                        truncateTimestampNsToFiveMinutes(atom.mTimestamps) : atom.mTimestamps;
                    protoOutput->write(
                        FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP,
                        (long long)timestampNs);
                    protoOutput->write(
                        FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED |
                            FIELD_ID_WALL_CLOCK_ATOM_TIMESTAMP,
                        (long long)wall_clock_ns);
                }
            }
            protoOutput->end(bucketInfoToken);
+4 −1
Original line number Diff line number Diff line
@@ -53,7 +53,9 @@ MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config,
                               const sp<UidMap> &uidMap,
                               const sp<AlarmMonitor>& anomalyAlarmMonitor,
                               const sp<AlarmMonitor>& periodicAlarmMonitor)
    : mConfigKey(key), mUidMap(uidMap), mLastReportTimeNs(timeBaseSec * NS_PER_SEC) {
    : mConfigKey(key), mUidMap(uidMap),
      mLastReportTimeNs(timeBaseSec * NS_PER_SEC),
      mLastReportWallClockNs(getWallClockNs()) {
    mConfigValid =
            initStatsdConfig(key, config, *uidMap, anomalyAlarmMonitor, periodicAlarmMonitor,
                             timeBaseSec, mTagIds, mAllAtomMatchers,
@@ -193,6 +195,7 @@ void MetricsManager::onDumpReport(const uint64_t dumpTimeStampNs, ProtoOutputStr
        }
    }
    mLastReportTimeNs = dumpTimeStampNs;
    mLastReportWallClockNs = getWallClockNs();
    VLOG("=========================Metric Reports End==========================");
}

+7 −2
Original line number Diff line number Diff line
@@ -69,10 +69,14 @@ public:
    void dumpStates(FILE* out, bool verbose);

    // Returns the elapsed realtime when this metric manager last reported metrics.
    uint64_t getLastReportTimeNs() {
    inline int64_t getLastReportTimeNs() const {
        return mLastReportTimeNs;
    };

    inline int64_t getLastReportWallClockNs() const {
        return mLastReportWallClockNs;
    };

    virtual void dropData(const uint64_t dropTimeNs);

    // Config source owner can call onDumpReport() to get all the metrics collected.
@@ -89,7 +93,8 @@ private:

    bool mConfigValid = false;

    uint64_t mLastReportTimeNs;
    int64_t mLastReportTimeNs;
    int64_t mLastReportWallClockNs;

    // The uid log sources from StatsdConfig.
    std::vector<int32_t> mAllowedUid;
Loading