diff options
| author | 2018-11-09 21:59:32 +0000 | |
|---|---|---|
| committer | 2018-11-09 21:59:32 +0000 | |
| commit | 0cc63ef090d3a3a3f666e48202da00efc975d55c (patch) | |
| tree | 26d100ad3752e71f3ef4fa4257eb8af786029a81 | |
| parent | f3375f360ea6875e4d70f2fc6d3074d159a74998 (diff) | |
| parent | 42f9e06418291828fb3196180fdfd08c5d1df434 (diff) | |
Merge "Thermal shutdown fix: cool down on writing to disk" into pi-dev
| -rw-r--r-- | cmds/statsd/src/StatsLogProcessor.cpp | 13 | ||||
| -rw-r--r-- | cmds/statsd/src/StatsLogProcessor.h | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/cmds/statsd/src/StatsLogProcessor.cpp b/cmds/statsd/src/StatsLogProcessor.cpp index e7f1caf26932..e7adba4d194a 100644 --- a/cmds/statsd/src/StatsLogProcessor.cpp +++ b/cmds/statsd/src/StatsLogProcessor.cpp @@ -71,6 +71,9 @@ const int FIELD_ID_STRINGS = 9; #define STATS_DATA_DIR "/data/misc/stats-data" +// Cool down period for writing data to disk to avoid overwriting files. +#define WRITE_DATA_COOL_DOWN_SEC 5 + StatsLogProcessor::StatsLogProcessor(const sp<UidMap>& uidMap, const sp<AlarmMonitor>& anomalyAlarmMonitor, const sp<AlarmMonitor>& periodicAlarmMonitor, @@ -526,6 +529,16 @@ void StatsLogProcessor::WriteDataToDiskLocked(const ConfigKey& key, void StatsLogProcessor::WriteDataToDiskLocked(const DumpReportReason dumpReportReason) { 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) < + mLastWriteTimeNs + WRITE_DATA_COOL_DOWN_SEC * NS_PER_SEC) { + ALOGI("Statsd skipping writing data to disk. Already wrote data in last %d seconds", + WRITE_DATA_COOL_DOWN_SEC); + return; + } + mLastWriteTimeNs = timeNs; for (auto& pair : mMetricsManagers) { WriteDataToDiskLocked(pair.first, timeNs, dumpReportReason); } diff --git a/cmds/statsd/src/StatsLogProcessor.h b/cmds/statsd/src/StatsLogProcessor.h index 9ed4ed04a4d5..86eb855825aa 100644 --- a/cmds/statsd/src/StatsLogProcessor.h +++ b/cmds/statsd/src/StatsLogProcessor.h @@ -184,6 +184,9 @@ private: long mLastPullerCacheClearTimeSec = 0; + // Last time we wrote data to disk. + int64_t mLastWriteTimeNs = 0; + #ifdef VERY_VERBOSE_PRINTING bool mPrintAllLogs = false; #endif |