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

Commit 8f42ba0e authored by Yao Chen's avatar Yao Chen
Browse files

Avoid reading logs that were processed before.

This could happen when statsd is disconnected from logd reader. When we reconnect, we are going to
get all events from the buffer again.

Bug: 72379125
Test: manual
Change-Id: Ie0122d5452555500c3bdfc1f905a0b1c646efdf7
parent 3f8237f3
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -72,7 +72,8 @@ StatsLogProcessor::StatsLogProcessor(const sp<UidMap>& uidMap,
    : mUidMap(uidMap),
      mAnomalyMonitor(anomalyMonitor),
      mSendBroadcast(sendBroadcast),
      mTimeBaseSec(timeBaseSec) {
      mTimeBaseSec(timeBaseSec),
      mLastLogTimestamp(0) {
    StatsPullerManager statsPullerManager;
    statsPullerManager.SetTimeBaseSec(mTimeBaseSec);
}
@@ -133,9 +134,12 @@ void StatsLogProcessor::onIsolatedUidChangedEventLocked(const LogEvent& event) {
    }
}

// TODO: what if statsd service restarts? How do we know what logs are already processed before?
void StatsLogProcessor::OnLogEvent(LogEvent* event) {
    std::lock_guard<std::mutex> lock(mMetricsMutex);
    if (event->GetElapsedTimestampNs() < mLastLogTimestamp) {
        return;
    }
    mLastLogTimestamp = event->GetElapsedTimestampNs();
    StatsdStats::getInstance().noteAtomLogged(
        event->GetTagId(), event->GetElapsedTimestampNs() / NS_PER_SEC);

+2 −0
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ private:

    const long mTimeBaseSec;

    int64_t mLastLogTimestamp;

    long mLastPullerCacheClearTimeSec = 0;

    FRIEND_TEST(StatsLogProcessorTest, TestRateLimitByteSize);