summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJin Qian2017-02-10 12:50:03 -0600
committerJin Qian2017-02-10 17:28:34 -0600
commite5ea17c84024badac9498bd61d1c07f253d75cac (patch)
tree85e7f263a59fe7ae2ba69d22845661d40ad2b368 /storaged
parent9eaeba9040049dcfa9cc54fdb81ced6f3130a9c5 (diff)
downloadplatform-system-core-e5ea17c84024badac9498bd61d1c07f253d75cac.tar.gz
platform-system-core-e5ea17c84024badac9498bd61d1c07f253d75cac.tar.xz
platform-system-core-e5ea17c84024badac9498bd61d1c07f253d75cac.zip
storaged: add dumpsys flags to limit data size
--threshold <bytes> This skips io usage not greater than <bytes> for current report. --time_window <secs> This sets uid_io collection interval to <secs> 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
Diffstat (limited to 'storaged')
-rw-r--r--storaged/include/storaged.h11
-rw-r--r--storaged/include/storaged_uid_monitor.h2
-rw-r--r--storaged/storaged_service.cpp21
-rw-r--r--storaged/storaged_uid_monitor.cpp23
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:
257#define DEFAULT_PERIODIC_CHORES_INTERVAL_DISK_STATS_PUBLISH ( 3600 ) 257#define DEFAULT_PERIODIC_CHORES_INTERVAL_DISK_STATS_PUBLISH ( 3600 )
258#define DEFAULT_PERIODIC_CHORES_INTERVAL_EMMC_INFO_PUBLISH ( 86400 ) 258#define DEFAULT_PERIODIC_CHORES_INTERVAL_EMMC_INFO_PUBLISH ( 86400 )
259#define DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO ( 3600 ) 259#define DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO ( 3600 )
260#define DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO_LIMIT (300)
260 261
261// UID IO threshold in bytes 262// UID IO threshold in bytes
262#define DEFAULT_PERIODIC_CHORES_UID_IO_THRESHOLD ( 1024 * 1024 * 1024ULL ) 263#define DEFAULT_PERIODIC_CHORES_UID_IO_THRESHOLD ( 1024 * 1024 * 1024ULL )
@@ -300,8 +301,14 @@ public:
300 std::unordered_map<uint32_t, struct uid_info> get_uids(void) { 301 std::unordered_map<uint32_t, struct uid_info> get_uids(void) {
301 return mUidm.get_uid_io_stats(); 302 return mUidm.get_uid_io_stats();
302 } 303 }
303 std::map<uint64_t, std::vector<struct uid_record>> get_uid_records(int hours) { 304 std::map<uint64_t, std::vector<struct uid_record>> get_uid_records(
304 return mUidm.dump(hours); 305 int hours, uint64_t threshold) {
306 return mUidm.dump(hours, threshold);
307 }
308 void update_uid_io_interval(int interval) {
309 if (interval >= DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO_LIMIT) {
310 mConfig.periodic_chores_interval_uid_io = interval;
311 }
305 } 312 }
306 313
307 void init_battery_service(); 314 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:
91 // called by storaged -u 91 // called by storaged -u
92 std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats(); 92 std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats();
93 // called by dumpsys 93 // called by dumpsys
94 std::map<uint64_t, std::vector<struct uid_record>> dump(int hours); 94 std::map<uint64_t, std::vector<struct uid_record>> dump(int hours, uint64_t threshold);
95 // called by battery properties listener 95 // called by battery properties listener
96 void set_charger_state(charger_stat_t stat); 96 void set_charger_state(charger_stat_t stat);
97 // called by storaged periodic_chore 97 // 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<String16>& args) {
89 } 89 }
90 90
91 int hours = 0; 91 int hours = 0;
92 int time_window = 0;
93 uint64_t threshold = 0;
92 for (size_t i = 0; i < args.size(); i++) { 94 for (size_t i = 0; i < args.size(); i++) {
93 const auto& arg = args[i]; 95 const auto& arg = args[i];
94 if (arg == String16("--hours")) { 96 if (arg == String16("--hours")) {
@@ -97,10 +99,22 @@ status_t Storaged::dump(int fd, const Vector<String16>& args) {
97 hours = stoi(String16::std_string(args[i])); 99 hours = stoi(String16::std_string(args[i]));
98 continue; 100 continue;
99 } 101 }
102 if (arg == String16("--time_window")) {
103 if (++i >= args.size())
104 break;
105 time_window = stoi(String16::std_string(args[i]));
106 continue;
107 }
108 if (arg == String16("--threshold")) {
109 if (++i >= args.size())
110 break;
111 threshold = stoll(String16::std_string(args[i]));
112 continue;
113 }
100 } 114 }
101 115
102 const std::map<uint64_t, std::vector<struct uid_record>>& records = 116 const std::map<uint64_t, std::vector<struct uid_record>>& records =
103 storaged.get_uid_records(hours); 117 storaged.get_uid_records(hours, threshold);
104 for (const auto& it : records) { 118 for (const auto& it : records) {
105 dprintf(fd, "%llu\n", (unsigned long long)it.first); 119 dprintf(fd, "%llu\n", (unsigned long long)it.first);
106 for (const auto& record : it.second) { 120 for (const auto& record : it.second) {
@@ -116,6 +130,11 @@ status_t Storaged::dump(int fd, const Vector<String16>& args) {
116 (unsigned long long)record.ios.bytes[WRITE][BACKGROUND][CHARGER_ON]); 130 (unsigned long long)record.ios.bytes[WRITE][BACKGROUND][CHARGER_ON]);
117 } 131 }
118 } 132 }
133
134 if (time_window) {
135 storaged.update_uid_io_interval(time_window);
136 }
137
119 return NO_ERROR; 138 return NO_ERROR;
120} 139}
121 140
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)
149 new_records.begin(), new_records.end()); 149 new_records.begin(), new_records.end());
150} 150}
151 151
152std::map<uint64_t, std::vector<struct uid_record>> uid_monitor::dump(int hours) 152std::map<uint64_t, std::vector<struct uid_record>> uid_monitor::dump(
153 int hours, uint64_t threshold)
153{ 154{
154 std::unique_ptr<lock_t> lock(new lock_t(&um_lock)); 155 std::unique_ptr<lock_t> lock(new lock_t(&um_lock));
155 156
@@ -160,7 +161,25 @@ std::map<uint64_t, std::vector<struct uid_record>> uid_monitor::dump(int hours)
160 first_ts = time(NULL) - (uint64_t)hours * HOUR_TO_SEC; 161 first_ts = time(NULL) - (uint64_t)hours * HOUR_TO_SEC;
161 } 162 }
162 163
163 dump_records.insert(records.lower_bound(first_ts), records.end()); 164 for (auto it = records.lower_bound(first_ts); it != records.end(); ++it) {
165 const std::vector<struct uid_record>& recs = it->second;
166 std::vector<struct uid_record> filtered;
167
168 for (const auto& rec : recs) {
169 if (rec.ios.bytes[READ][FOREGROUND][CHARGER_ON] +
170 rec.ios.bytes[READ][FOREGROUND][CHARGER_OFF] +
171 rec.ios.bytes[READ][BACKGROUND][CHARGER_ON] +
172 rec.ios.bytes[READ][BACKGROUND][CHARGER_OFF] +
173 rec.ios.bytes[WRITE][FOREGROUND][CHARGER_ON] +
174 rec.ios.bytes[WRITE][FOREGROUND][CHARGER_OFF] +
175 rec.ios.bytes[WRITE][BACKGROUND][CHARGER_ON] +
176 rec.ios.bytes[WRITE][BACKGROUND][CHARGER_OFF] > threshold) {
177 filtered.push_back(rec);
178 }
179 }
180 dump_records.insert(
181 std::pair<uint64_t, std::vector<struct uid_record>>(it->first, filtered));
182 }
164 183
165 return dump_records; 184 return dump_records;
166} 185}