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

Commit c39a05d7 authored by Olivier Gaillard's avatar Olivier Gaillard Committed by Android (Google) Code Review
Browse files

Merge "Tracks the delay between the pull and the actual bucket boundary."

parents fe00e4f8 3ba2e933
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -458,6 +458,15 @@ void StatsdStats::noteInvalidatedBucket(int64_t metricId) {
    getAtomMetricStats(metricId).invalidatedBucket++;
}

void StatsdStats::noteBucketBoundaryDelayNs(int64_t metricId, int64_t timeDelayNs) {
    lock_guard<std::mutex> lock(mLock);
    AtomMetricStats& pullStats = getAtomMetricStats(metricId);
    pullStats.maxBucketBoundaryDelayNs =
            std::max(pullStats.maxBucketBoundaryDelayNs, timeDelayNs);
    pullStats.minBucketBoundaryDelayNs =
            std::min(pullStats.minBucketBoundaryDelayNs, timeDelayNs);
}

StatsdStats::AtomMetricStats& StatsdStats::getAtomMetricStats(int metricId) {
    auto atomMetricStatsIter = mAtomMetricStats.find(metricId);
    if (atomMetricStatsIter != mAtomMetricStats.end()) {
+8 −0
Original line number Diff line number Diff line
@@ -374,6 +374,12 @@ public:
     */
    void noteInvalidatedBucket(int64_t metricId);

    /**
     * For pulls at bucket boundaries, it represents the misalignment between the real timestamp and
     * the end of the bucket.
     */
    void noteBucketBoundaryDelayNs(int64_t metricId, int64_t timeDelayNs);

    /**
     * Reset the historical stats. Including all stats in icebox, and the tracked stats about
     * metrics, matchers, and atoms. The active configs will be kept and StatsdStats will continue
@@ -420,6 +426,8 @@ public:
        long conditionChangeInNextBucket = 0;
        long invalidatedBucket = 0;
        long bucketDropped = 0;
        int64_t minBucketBoundaryDelayNs = 0;
        int64_t maxBucketBoundaryDelayNs = 0;
    } AtomMetricStats;

private:
+2 −0
Original line number Diff line number Diff line
@@ -387,6 +387,8 @@ void ValueMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEven
        // If the sleep was very long, we skip more than one bucket before sleep. In this case,
        // if the diff base will be cleared and this new data will serve as new diff base.
        int64_t bucketEndTime = calcPreviousBucketEndTime(originalPullTimeNs) - 1;
        StatsdStats::getInstance().noteBucketBoundaryDelayNs(
                mMetricId, originalPullTimeNs - bucketEndTime);
        accumulateEvents(allData, originalPullTimeNs, bucketEndTime);

        // We can probably flush the bucket. Since we used bucketEndTime when calling
+2 −0
Original line number Diff line number Diff line
@@ -419,6 +419,8 @@ message StatsdStatsReport {
      optional int64 condition_change_in_next_bucket = 6;
      optional int64 invalidated_bucket = 7;
      optional int64 bucket_dropped = 8;
      optional int64 min_bucket_boundary_delay_ns = 9;
      optional int64 max_bucket_boundary_delay_ns = 10;
    }
    repeated AtomMetricStats atom_metric_stats = 17;

+6 −0
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@ const int FIELD_ID_BAD_VALUE_TYPE = 5;
const int FIELD_ID_CONDITION_CHANGE_IN_NEXT_BUCKET = 6;
const int FIELD_ID_INVALIDATED_BUCKET = 7;
const int FIELD_ID_BUCKET_DROPPED = 8;
const int FIELD_ID_MIN_BUCKET_BOUNDARY_DELAY_NS = 9;
const int FIELD_ID_MAX_BUCKET_BOUNDARY_DELAY_NS = 10;

namespace {

@@ -500,6 +502,10 @@ void writeAtomMetricStatsToStream(const std::pair<int, StatsdStats::AtomMetricSt
                       (long long)pair.second.invalidatedBucket);
    protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_BUCKET_DROPPED,
                       (long long)pair.second.bucketDropped);
    protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_MIN_BUCKET_BOUNDARY_DELAY_NS,
                       (long long)pair.second.minBucketBoundaryDelayNs);
    protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_MAX_BUCKET_BOUNDARY_DELAY_NS,
                       (long long)pair.second.maxBucketBoundaryDelayNs);
    protoOutput->end(token);
}