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

Commit c7ce1a09 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add wall clock timestamp for ConfigMetricsReport and gauge atoms." into pi-dev

parents a9e73469 3fa5d7fb
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -196,7 +196,7 @@ LOCAL_SRC_FILES := \
    tests/e2e/WakelockDuration_e2e_test.cpp \
    tests/e2e/WakelockDuration_e2e_test.cpp \
    tests/e2e/MetricConditionLink_e2e_test.cpp \
    tests/e2e/MetricConditionLink_e2e_test.cpp \
    tests/e2e/Attribution_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_AND_cond_test.cpp \
    tests/e2e/DimensionInCondition_e2e_combination_OR_cond_test.cpp \
    tests/e2e/DimensionInCondition_e2e_combination_OR_cond_test.cpp \
    tests/e2e/DimensionInCondition_e2e_simple_cond_test.cpp
    tests/e2e/DimensionInCondition_e2e_simple_cond_test.cpp
+9 −0
Original line number Original line 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_UID_MAP = 2;
const int FIELD_ID_LAST_REPORT_ELAPSED_NANOS = 3;
const int FIELD_ID_LAST_REPORT_ELAPSED_NANOS = 3;
const int FIELD_ID_CURRENT_REPORT_ELAPSED_NANOS = 4;
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"
#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);
            proto.start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_REPORTS);


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

    // First, fill in ConfigMetricsReport using current data on memory, which
    // First, fill in ConfigMetricsReport using current data on memory, which
    // starts from filling in StatsLogReport's.
    // starts from filling in StatsLogReport's.
    it->second->onDumpReport(dumpTimeStampNs, &proto);
    it->second->onDumpReport(dumpTimeStampNs, &proto);
@@ -276,6 +281,10 @@ void StatsLogProcessor::onDumpReportLocked(const ConfigKey& key, const uint64_t
                (long long)lastReportTimeNs);
                (long long)lastReportTimeNs);
    proto.write(FIELD_TYPE_INT64 | FIELD_ID_CURRENT_REPORT_ELAPSED_NANOS,
    proto.write(FIELD_TYPE_INT64 | FIELD_ID_CURRENT_REPORT_ELAPSED_NANOS,
                (long long)dumpTimeStampNs);
                (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).
    // End of ConfigMetricsReport (reports).
    proto.end(reportsToken);
    proto.end(reportsToken);
+14 −6
Original line number Original line 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_END_BUCKET_ELAPSED_NANOS = 2;
const int FIELD_ID_ATOM = 3;
const int FIELD_ID_ATOM = 3;
const int FIELD_ID_ELAPSED_ATOM_TIMESTAMP = 4;
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,
GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric& metric,
                                         const int conditionIndex,
                                         const int conditionIndex,
@@ -186,21 +187,28 @@ void GaugeMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
                               (long long)bucket.mBucketEndNs);
                               (long long)bucket.mBucketEndNs);


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


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


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


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

    virtual void dropData(const uint64_t dropTimeNs);
    virtual void dropData(const uint64_t dropTimeNs);


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


    bool mConfigValid = false;
    bool mConfigValid = false;


    uint64_t mLastReportTimeNs;
    int64_t mLastReportTimeNs;
    int64_t mLastReportWallClockNs;


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