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

Commit 12942956 authored by David Chen's avatar David Chen
Browse files

Tiny fix to bug when statsd should clear data.

Previously, we always sent a broadcast, even after we have exceeded
the memory limit for this config key. We switch the order so that
we drop the data if the limit is exceeded. If greater than 90% of the
way to the limit, we send the broadcast.

We need to find a way to unit-test this behavior.

Test: N/A.
Change-Id: I6ea40b9e34dceb19805d9af24495d72878f787e0
parent 2e8f3807
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -221,7 +221,14 @@ void StatsLogProcessor::flushIfNecessary(uint64_t timestampNs,
    std::lock_guard<std::mutex> lock(mBroadcastTimesMutex);

    size_t totalBytes = metricsManager->byteSize() + mUidMap->getBytesUsed();
    if (totalBytes > .9 * kMaxSerializedBytes) { // Send broadcast so that receivers can pull data.
    // TODO: Find a way to test that the dropping and broadcasts are sent when memory is exceeded.
    if (totalBytes > kMaxSerializedBytes) {  // Too late. We need to start clearing data.
        // We ignore the return value so we force each metric producer to clear its contents.
        metricsManager->onDumpReport();
        StatsdStats::getInstance().noteDataDropped(key);
        VLOG("StatsD had to toss out metrics for %s", key.ToString().c_str());
    } else if (totalBytes >
               .9 * kMaxSerializedBytes) {  // Send broadcast so that receivers can pull data.
        auto lastFlushNs = mLastBroadcastTimes.find(key);
        if (lastFlushNs != mLastBroadcastTimes.end()) {
            if (timestampNs - lastFlushNs->second < kMinBroadcastPeriod) {
@@ -232,11 +239,6 @@ void StatsLogProcessor::flushIfNecessary(uint64_t timestampNs,
        VLOG("StatsD requesting broadcast for %s", key.ToString().c_str());
        mSendBroadcast(key);
        StatsdStats::getInstance().noteBroadcastSent(key);
    } else if (totalBytes > kMaxSerializedBytes) { // Too late. We need to start clearing data.
        // We ignore the return value so we force each metric producer to clear its contents.
        metricsManager->onDumpReport();
        StatsdStats::getInstance().noteDataDropped(key);
        VLOG("StatsD had to toss out metrics for %s", key.ToString().c_str());
    }
}