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

Commit 996f40d2 authored by jianjin's avatar jianjin
Browse files

Write active metrics to disk on all shutdown cases

Bug: 126132516
Fixes: 126132516
Test: manual tests
Change-Id: Ic0e897c57d0bf8b55167f185fa4ac80b1d672af0
parent 65e18e43
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -602,6 +602,19 @@ void StatsLogProcessor::WriteDataToDiskLocked(const ConfigKey& key,

void StatsLogProcessor::WriteMetricsActivationToDisk(int64_t currentTimeNs) {
    std::lock_guard<std::mutex> lock(mMetricsMutex);

    const int64_t timeNs = getElapsedRealtimeNs();
    // Do not write to disk if we already have in the last few seconds.
    // This is to avoid overwriting files that would have the same name if we
    //   write twice in the same second.
    if (static_cast<unsigned long long> (timeNs) <
            mLastActiveMetricsWriteNs + WRITE_DATA_COOL_DOWN_SEC * NS_PER_SEC) {
        ALOGI("Statsd skipping writing active metrics to disk. Already wrote data in last %d seconds",
                WRITE_DATA_COOL_DOWN_SEC);
        return;
    }
    mLastActiveMetricsWriteNs = timeNs;

    ProtoOutputStream proto;

    for (const auto& pair : mMetricsManagers) {
+3 −0
Original line number Diff line number Diff line
@@ -207,6 +207,9 @@ private:
    // Last time we wrote data to disk.
    int64_t mLastWriteTimeNs = 0;

    // Last time we wrote active metrics to disk.
    int64_t mLastActiveMetricsWriteNs = 0;

#ifdef VERY_VERBOSE_PRINTING
    bool mPrintAllLogs = false;
#endif
+1 −0
Original line number Diff line number Diff line
@@ -1028,6 +1028,7 @@ void StatsService::Terminate() {
    ALOGI("StatsService::Terminating");
    if (mProcessor != nullptr) {
        mProcessor->WriteDataToDisk(TERMINATION_SIGNAL_RECEIVED, FAST);
        mProcessor->WriteMetricsActivationToDisk(getElapsedRealtimeNs());
    }
}