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

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

Merge "Statsd: support atom counts of new atoms." into qt-dev

parents 0ab51d16 35c7a57b
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -432,12 +432,13 @@ void StatsdStats::notePullExceedMaxDelay(int pullAtomId) {
void StatsdStats::noteAtomLogged(int atomId, int32_t timeSec) {
    lock_guard<std::mutex> lock(mLock);

    if (atomId > android::util::kMaxPushedAtomId) {
        ALOGW("not interested in atom %d", atomId);
        return;
    }

    if (atomId <= android::util::kMaxPushedAtomId) {
        mPushedAtomStats[atomId]++;
    } else {
        if (mNonPlatformPushedAtomStats.size() < kMaxNonPlatformPushedAtoms) {
            mNonPlatformPushedAtomStats[atomId]++;
        }
    }
}

void StatsdStats::noteSystemServerRestart(int32_t timeSec) {
@@ -551,6 +552,7 @@ void StatsdStats::resetInternalLocked() {
    mStartTimeSec = getWallClockSec();
    mIceBox.clear();
    std::fill(mPushedAtomStats.begin(), mPushedAtomStats.end(), 0);
    mNonPlatformPushedAtomStats.clear();
    mAnomalyAlarmRegisteredStats = 0;
    mPeriodicAlarmRegisteredStats = 0;
    mSystemServerRestartSec.clear();
@@ -705,6 +707,9 @@ void StatsdStats::dumpStats(int out) const {
            dprintf(out, "Atom %lu->%d\n", (unsigned long)i, mPushedAtomStats[i]);
        }
    }
    for (const auto& pair : mNonPlatformPushedAtomStats) {
        dprintf(out, "Atom %lu->%d\n", (unsigned long)pair.first, pair.second);
    }

    dprintf(out, "********Pulled Atom stats***********\n");
    for (const auto& pair : mPulledAtomStats) {
@@ -890,6 +895,14 @@ void StatsdStats::dumpStats(std::vector<uint8_t>* output, bool reset) {
        }
    }

    for (const auto& pair : mNonPlatformPushedAtomStats) {
        uint64_t token =
                proto.start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOM_STATS | FIELD_COUNT_REPEATED);
        proto.write(FIELD_TYPE_INT32 | FIELD_ID_ATOM_STATS_TAG, pair.first);
        proto.write(FIELD_TYPE_INT32 | FIELD_ID_ATOM_STATS_COUNT, pair.second);
        proto.end(token);
    }

    for (const auto& pair : mPulledAtomStats) {
        android::os::statsd::writePullerStatsToStream(pair, &proto);
    }
+10 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <mutex>
#include <string>
#include <vector>
#include <unordered_map>

namespace android {
namespace os {
@@ -160,6 +161,9 @@ public:
    // Max time to do a pull.
    static const int64_t kPullMaxDelayNs = 10 * NS_PER_SEC;

    // Maximum number of pushed atoms statsd stats will track above kMaxPushedAtomId.
    static const int kMaxNonPlatformPushedAtoms = 100;

    // Max platform atom tag number.
    static const int32_t kMaxPlatformAtomTag = 100000;

@@ -508,10 +512,14 @@ private:

    // Stores the number of times a pushed atom is logged.
    // The size of the vector is the largest pushed atom id in atoms.proto + 1. Atoms
    // out of that range will be dropped (it's either pulled atoms or test atoms).
    // out of that range will be put in mNonPlatformPushedAtomStats.
    // This is a vector, not a map because it will be accessed A LOT -- for each stats log.
    std::vector<int> mPushedAtomStats;

    // Stores the number of times a pushed atom is logged for atom ids above kMaxPushedAtomId.
    // The max size of the map is kMaxNonPlatformPushedAtoms.
    std::unordered_map<int, int> mNonPlatformPushedAtomStats;

    // Maps PullAtomId to its stats. The size is capped by the puller atom counts.
    std::map<int, PulledAtomStats> mPulledAtomStats;

@@ -587,6 +595,7 @@ private:
    FRIEND_TEST(StatsdStatsTest, TestConfigRemove);
    FRIEND_TEST(StatsdStatsTest, TestSubStats);
    FRIEND_TEST(StatsdStatsTest, TestAtomLog);
    FRIEND_TEST(StatsdStatsTest, TestNonPlatformAtomLog);
    FRIEND_TEST(StatsdStatsTest, TestTimestampThreshold);
    FRIEND_TEST(StatsdStatsTest, TestAnomalyMonitor);
    FRIEND_TEST(StatsdStatsTest, TestSystemServerCrash);
+1 −1
Original line number Diff line number Diff line
@@ -312,7 +312,7 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
    }
}

void GaugeMetricProducer::prepareFistBucketLocked() {
void GaugeMetricProducer::prepareFirstBucketLocked() {
    if (mIsActive && mIsPulled && mSamplingType == GaugeMetric::RANDOM_ONE_SAMPLE) {
        pullAndMatchEventsLocked(mCurrentBucketStartTimeNs);
    }
+1 −1
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ private:
    void flushCurrentBucketLocked(const int64_t& eventTimeNs,
                                  const int64_t& nextBucketStartTimeNs) override;

    void prepareFistBucketLocked() override;
    void prepareFirstBucketLocked() override;

    void pullAndMatchEventsLocked(const int64_t timestampNs);

+3 −3
Original line number Diff line number Diff line
@@ -236,9 +236,9 @@ public:
    void addActivation(int activationTrackerIndex, const ActivationType& activationType,
            int64_t ttl_seconds, int deactivationTrackerIndex = -1);

    void prepareFistBucket() {
    void prepareFirstBucket() {
        std::lock_guard<std::mutex> lock(mMutex);
        prepareFistBucketLocked();
        prepareFirstBucketLocked();
    }

    void flushIfExpire(int64_t elapsedTimestampNs);
@@ -272,7 +272,7 @@ protected:

    void loadActiveMetricLocked(const ActiveMetric& activeMetric, int64_t currentTimeNs);

    virtual void prepareFistBucketLocked() {};
    virtual void prepareFirstBucketLocked() {};
    /**
     * Flushes the current bucket if the eventTime is after the current bucket's end time. This will
       also flush the current partial bucket in memory.
Loading