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) {
// 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
ALOGI("StatsService::Terminating");
if (mProcessor != nullptr) {
mProcessor->WriteDataToDisk(TERMINATION_SIGNAL_RECEIVED, FAST);
+ mProcessor->WriteMetricsActivationToDisk(getElapsedRealtimeNs());
}
}