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

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

Merge "Tiny fix to bug when statsd should clear data."

parents 742fd61d 12942956
Loading
Loading
Loading
Loading
+8 −6
Original line number Original line Diff line number Diff line
@@ -221,7 +221,14 @@ void StatsLogProcessor::flushIfNecessary(uint64_t timestampNs,
    std::lock_guard<std::mutex> lock(mBroadcastTimesMutex);
    std::lock_guard<std::mutex> lock(mBroadcastTimesMutex);


    size_t totalBytes = metricsManager->byteSize() + mUidMap->getBytesUsed();
    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);
        auto lastFlushNs = mLastBroadcastTimes.find(key);
        if (lastFlushNs != mLastBroadcastTimes.end()) {
        if (lastFlushNs != mLastBroadcastTimes.end()) {
            if (timestampNs - lastFlushNs->second < kMinBroadcastPeriod) {
            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());
        VLOG("StatsD requesting broadcast for %s", key.ToString().c_str());
        mSendBroadcast(key);
        mSendBroadcast(key);
        StatsdStats::getInstance().noteBroadcastSent(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());
    }
    }
}
}