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

Commit 35c7a57b authored by Tej Singh's avatar Tej Singh
Browse files

Statsd: support atom counts of new atoms.

In Q, mainline modules will can add atoms after the platform ships.
Statsdstats now supports atom counts of up to 100 atoms that are added
after Q ships. Note: pixel/oem pushed atoms will also get counted now.

Also fixes a typo in prepareFirstBucket

Bug: 131448746
Bug: 128363379
Test: statsd_test
Change-Id: I149c91136fb7649f0c9a0d6e83bc20f8461e45e2
parent 3eb46249
Loading
Loading
Loading
Loading
+18 −5
Original line number Original line Diff line number Diff line
@@ -432,12 +432,13 @@ void StatsdStats::notePullExceedMaxDelay(int pullAtomId) {
void StatsdStats::noteAtomLogged(int atomId, int32_t timeSec) {
void StatsdStats::noteAtomLogged(int atomId, int32_t timeSec) {
    lock_guard<std::mutex> lock(mLock);
    lock_guard<std::mutex> lock(mLock);


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

        mPushedAtomStats[atomId]++;
        mPushedAtomStats[atomId]++;
    } else {
        if (mNonPlatformPushedAtomStats.size() < kMaxNonPlatformPushedAtoms) {
            mNonPlatformPushedAtomStats[atomId]++;
        }
    }
}
}


void StatsdStats::noteSystemServerRestart(int32_t timeSec) {
void StatsdStats::noteSystemServerRestart(int32_t timeSec) {
@@ -551,6 +552,7 @@ void StatsdStats::resetInternalLocked() {
    mStartTimeSec = getWallClockSec();
    mStartTimeSec = getWallClockSec();
    mIceBox.clear();
    mIceBox.clear();
    std::fill(mPushedAtomStats.begin(), mPushedAtomStats.end(), 0);
    std::fill(mPushedAtomStats.begin(), mPushedAtomStats.end(), 0);
    mNonPlatformPushedAtomStats.clear();
    mAnomalyAlarmRegisteredStats = 0;
    mAnomalyAlarmRegisteredStats = 0;
    mPeriodicAlarmRegisteredStats = 0;
    mPeriodicAlarmRegisteredStats = 0;
    mSystemServerRestartSec.clear();
    mSystemServerRestartSec.clear();
@@ -705,6 +707,9 @@ void StatsdStats::dumpStats(int out) const {
            dprintf(out, "Atom %lu->%d\n", (unsigned long)i, mPushedAtomStats[i]);
            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");
    dprintf(out, "********Pulled Atom stats***********\n");
    for (const auto& pair : mPulledAtomStats) {
    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) {
    for (const auto& pair : mPulledAtomStats) {
        android::os::statsd::writePullerStatsToStream(pair, &proto);
        android::os::statsd::writePullerStatsToStream(pair, &proto);
    }
    }
+10 −1
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@
#include <mutex>
#include <mutex>
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <unordered_map>


namespace android {
namespace android {
namespace os {
namespace os {
@@ -160,6 +161,9 @@ public:
    // Max time to do a pull.
    // Max time to do a pull.
    static const int64_t kPullMaxDelayNs = 10 * NS_PER_SEC;
    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.
    // Max platform atom tag number.
    static const int32_t kMaxPlatformAtomTag = 100000;
    static const int32_t kMaxPlatformAtomTag = 100000;


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


    // Stores the number of times a pushed atom is logged.
    // 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
    // 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.
    // This is a vector, not a map because it will be accessed A LOT -- for each stats log.
    std::vector<int> mPushedAtomStats;
    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.
    // Maps PullAtomId to its stats. The size is capped by the puller atom counts.
    std::map<int, PulledAtomStats> mPulledAtomStats;
    std::map<int, PulledAtomStats> mPulledAtomStats;


@@ -587,6 +595,7 @@ private:
    FRIEND_TEST(StatsdStatsTest, TestConfigRemove);
    FRIEND_TEST(StatsdStatsTest, TestConfigRemove);
    FRIEND_TEST(StatsdStatsTest, TestSubStats);
    FRIEND_TEST(StatsdStatsTest, TestSubStats);
    FRIEND_TEST(StatsdStatsTest, TestAtomLog);
    FRIEND_TEST(StatsdStatsTest, TestAtomLog);
    FRIEND_TEST(StatsdStatsTest, TestNonPlatformAtomLog);
    FRIEND_TEST(StatsdStatsTest, TestTimestampThreshold);
    FRIEND_TEST(StatsdStatsTest, TestTimestampThreshold);
    FRIEND_TEST(StatsdStatsTest, TestAnomalyMonitor);
    FRIEND_TEST(StatsdStatsTest, TestAnomalyMonitor);
    FRIEND_TEST(StatsdStatsTest, TestSystemServerCrash);
    FRIEND_TEST(StatsdStatsTest, TestSystemServerCrash);
+1 −1
Original line number Original line 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) {
    if (mIsActive && mIsPulled && mSamplingType == GaugeMetric::RANDOM_ONE_SAMPLE) {
        pullAndMatchEventsLocked(mCurrentBucketStartTimeNs);
        pullAndMatchEventsLocked(mCurrentBucketStartTimeNs);
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -122,7 +122,7 @@ private:
    void flushCurrentBucketLocked(const int64_t& eventTimeNs,
    void flushCurrentBucketLocked(const int64_t& eventTimeNs,
                                  const int64_t& nextBucketStartTimeNs) override;
                                  const int64_t& nextBucketStartTimeNs) override;


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


    void pullAndMatchEventsLocked(const int64_t timestampNs);
    void pullAndMatchEventsLocked(const int64_t timestampNs);


+3 −3
Original line number Original line Diff line number Diff line
@@ -250,9 +250,9 @@ public:
        mActivationType = activationType;
        mActivationType = activationType;
    }
    }


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


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


    void setActiveLocked(int64_t currentTimeNs, int64_t remainingTtlNs);
    void setActiveLocked(int64_t currentTimeNs, int64_t remainingTtlNs);


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