From e5ea17c84024badac9498bd61d1c07f253d75cac Mon Sep 17 00:00:00 2001 From: Jin Qian Date: Fri, 10 Feb 2017 10:50:03 -0800 Subject: [PATCH] storaged: add dumpsys flags to limit data size --threshold This skips io usage not greater than for current report. --time_window This sets uid_io collection interval to for future reports. The new interval will be ignore if it's less than 5 minutes. Test: adb shell dumpsys --threshold 4096 --time_window 300 Bug: 33086174 Bug: 34198239 Change-Id: I723c0850fa504a113da0a14945c4fbc64ea47659 --- storaged/include/storaged.h | 11 +++++++++-- storaged/include/storaged_uid_monitor.h | 2 +- storaged/storaged_service.cpp | 21 ++++++++++++++++++++- storaged/storaged_uid_monitor.cpp | 23 +++++++++++++++++++++-- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/storaged/include/storaged.h b/storaged/include/storaged.h index 7e5048fc4..a16be27db 100644 --- a/storaged/include/storaged.h +++ b/storaged/include/storaged.h @@ -257,6 +257,7 @@ public: #define DEFAULT_PERIODIC_CHORES_INTERVAL_DISK_STATS_PUBLISH ( 3600 ) #define DEFAULT_PERIODIC_CHORES_INTERVAL_EMMC_INFO_PUBLISH ( 86400 ) #define DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO ( 3600 ) +#define DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO_LIMIT (300) // UID IO threshold in bytes #define DEFAULT_PERIODIC_CHORES_UID_IO_THRESHOLD ( 1024 * 1024 * 1024ULL ) @@ -300,8 +301,14 @@ public: std::unordered_map get_uids(void) { return mUidm.get_uid_io_stats(); } - std::map> get_uid_records(int hours) { - return mUidm.dump(hours); + std::map> get_uid_records( + int hours, uint64_t threshold) { + return mUidm.dump(hours, threshold); + } + void update_uid_io_interval(int interval) { + if (interval >= DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO_LIMIT) { + mConfig.periodic_chores_interval_uid_io = interval; + } } void init_battery_service(); diff --git a/storaged/include/storaged_uid_monitor.h b/storaged/include/storaged_uid_monitor.h index 07e6daa3e..ae850167d 100644 --- a/storaged/include/storaged_uid_monitor.h +++ b/storaged/include/storaged_uid_monitor.h @@ -91,7 +91,7 @@ public: // called by storaged -u std::unordered_map get_uid_io_stats(); // called by dumpsys - std::map> dump(int hours); + std::map> dump(int hours, uint64_t threshold); // called by battery properties listener void set_charger_state(charger_stat_t stat); // called by storaged periodic_chore diff --git a/storaged/storaged_service.cpp b/storaged/storaged_service.cpp index 66354314e..007b75c41 100644 --- a/storaged/storaged_service.cpp +++ b/storaged/storaged_service.cpp @@ -89,6 +89,8 @@ status_t Storaged::dump(int fd, const Vector& args) { } int hours = 0; + int time_window = 0; + uint64_t threshold = 0; for (size_t i = 0; i < args.size(); i++) { const auto& arg = args[i]; if (arg == String16("--hours")) { @@ -97,10 +99,22 @@ status_t Storaged::dump(int fd, const Vector& args) { hours = stoi(String16::std_string(args[i])); continue; } + if (arg == String16("--time_window")) { + if (++i >= args.size()) + break; + time_window = stoi(String16::std_string(args[i])); + continue; + } + if (arg == String16("--threshold")) { + if (++i >= args.size()) + break; + threshold = stoll(String16::std_string(args[i])); + continue; + } } const std::map>& records = - storaged.get_uid_records(hours); + storaged.get_uid_records(hours, threshold); for (const auto& it : records) { dprintf(fd, "%llu\n", (unsigned long long)it.first); for (const auto& record : it.second) { @@ -116,6 +130,11 @@ status_t Storaged::dump(int fd, const Vector& args) { (unsigned long long)record.ios.bytes[WRITE][BACKGROUND][CHARGER_ON]); } } + + if (time_window) { + storaged.update_uid_io_interval(time_window); + } + return NO_ERROR; } diff --git a/storaged/storaged_uid_monitor.cpp b/storaged/storaged_uid_monitor.cpp index b46d09a75..a186b7346 100644 --- a/storaged/storaged_uid_monitor.cpp +++ b/storaged/storaged_uid_monitor.cpp @@ -149,7 +149,8 @@ void uid_monitor::add_records_locked(uint64_t curr_ts) new_records.begin(), new_records.end()); } -std::map> uid_monitor::dump(int hours) +std::map> uid_monitor::dump( + int hours, uint64_t threshold) { std::unique_ptr lock(new lock_t(&um_lock)); @@ -160,7 +161,25 @@ std::map> uid_monitor::dump(int hours) first_ts = time(NULL) - (uint64_t)hours * HOUR_TO_SEC; } - dump_records.insert(records.lower_bound(first_ts), records.end()); + for (auto it = records.lower_bound(first_ts); it != records.end(); ++it) { + const std::vector& recs = it->second; + std::vector filtered; + + for (const auto& rec : recs) { + if (rec.ios.bytes[READ][FOREGROUND][CHARGER_ON] + + rec.ios.bytes[READ][FOREGROUND][CHARGER_OFF] + + rec.ios.bytes[READ][BACKGROUND][CHARGER_ON] + + rec.ios.bytes[READ][BACKGROUND][CHARGER_OFF] + + rec.ios.bytes[WRITE][FOREGROUND][CHARGER_ON] + + rec.ios.bytes[WRITE][FOREGROUND][CHARGER_OFF] + + rec.ios.bytes[WRITE][BACKGROUND][CHARGER_ON] + + rec.ios.bytes[WRITE][BACKGROUND][CHARGER_OFF] > threshold) { + filtered.push_back(rec); + } + } + dump_records.insert( + std::pair>(it->first, filtered)); + } return dump_records; }