From c71d901ddea1b9538ab50fae8094e46ecca4b072 Mon Sep 17 00:00:00 2001 From: Bookatz Date: Wed, 19 Dec 2018 12:28:38 -0800 Subject: [PATCH] Statsd dumpsys handles multiple and saved configs Statsd dumpsys wasn't handling multiple configs properly. Also, doing a dump would delete the data that had been saved to disk. This cl fixes both those issues. Test: run cts-dev -m CtsStatsdHostTestCases -t android.cts.statsd.atom.HostAtomTests#testDumpsysStats Change-Id: I5f2f86c70fbcbc1407aae1b1ffeb7fbdb9f67d0e --- cmds/statsd/src/StatsLogProcessor.cpp | 2 +- cmds/statsd/src/StatsService.cpp | 1 + cmds/statsd/src/storage/StorageManager.cpp | 9 ++++++--- cmds/statsd/src/storage/StorageManager.h | 8 +++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmds/statsd/src/StatsLogProcessor.cpp b/cmds/statsd/src/StatsLogProcessor.cpp index a9819972cfc76..69cb264ef2373 100644 --- a/cmds/statsd/src/StatsLogProcessor.cpp +++ b/cmds/statsd/src/StatsLogProcessor.cpp @@ -293,7 +293,7 @@ void StatsLogProcessor::onDumpReport(const ConfigKey& key, const int64_t dumpTim // Then, check stats-data directory to see there's any file containing // ConfigMetricsReport from previous shutdowns to concatenate to reports. - StorageManager::appendConfigMetricsReport(key, proto); + StorageManager::appendConfigMetricsReport(key, proto, erase_data); auto it = mMetricsManagers.find(key); if (it != mMetricsManagers.end()) { diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp index 04173b217dcb7..bd207288469ed 100644 --- a/cmds/statsd/src/StatsService.cpp +++ b/cmds/statsd/src/StatsService.cpp @@ -296,6 +296,7 @@ void StatsService::dumpIncidentSection(int out) { ADB_DUMP, &proto); proto.end(reportsListToken); proto.flush(out); + proto.clear(); } } diff --git a/cmds/statsd/src/storage/StorageManager.cpp b/cmds/statsd/src/storage/StorageManager.cpp index 2f19a02ecafe1..90f641a34b858 100644 --- a/cmds/statsd/src/storage/StorageManager.cpp +++ b/cmds/statsd/src/storage/StorageManager.cpp @@ -188,7 +188,9 @@ bool StorageManager::hasConfigMetricsReport(const ConfigKey& key) { return false; } -void StorageManager::appendConfigMetricsReport(const ConfigKey& key, ProtoOutputStream* proto) { +void StorageManager::appendConfigMetricsReport(const ConfigKey& key, + ProtoOutputStream* proto, + bool erasa_data) { unique_ptr dir(opendir(STATS_DATA_DIR), closedir); if (dir == NULL) { VLOG("Path %s does not exist", STATS_DATA_DIR); @@ -224,8 +226,9 @@ void StorageManager::appendConfigMetricsReport(const ConfigKey& key, ProtoOutput close(fd); } - // Remove file from disk after reading. - remove(file_name.c_str()); + if (erasa_data) { + remove(file_name.c_str()); + } } } } diff --git a/cmds/statsd/src/storage/StorageManager.h b/cmds/statsd/src/storage/StorageManager.h index 8fbc89e4f657f..dcf3bb607380f 100644 --- a/cmds/statsd/src/storage/StorageManager.h +++ b/cmds/statsd/src/storage/StorageManager.h @@ -68,10 +68,12 @@ public: static bool hasConfigMetricsReport(const ConfigKey& key); /** - * Appends ConfigMetricsReport found on disk to the specific proto and - * delete it. + * Appends the ConfigMetricsReport found on disk to the specifid proto + * and, if erase_data, deletes it from disk. */ - static void appendConfigMetricsReport(const ConfigKey& key, ProtoOutputStream* proto); + static void appendConfigMetricsReport(const ConfigKey& key, + ProtoOutputStream* proto, + bool erase_data); /** * Call to load the saved configs from disk.