summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJin Qian2017-02-21 14:09:39 -0600
committerJin Qian2017-02-21 17:33:22 -0600
commit8157775d791c124fcd84cdbeb7a751226bcb285b (patch)
treeafa078019b4535ac95db7314da29cde82e752fea /storaged
parentfba6f2622ff06995b7668926ea32b877a36dc077 (diff)
downloadplatform-system-core-8157775d791c124fcd84cdbeb7a751226bcb285b.tar.gz
platform-system-core-8157775d791c124fcd84cdbeb7a751226bcb285b.tar.xz
platform-system-core-8157775d791c124fcd84cdbeb7a751226bcb285b.zip
storaged: include start time in IO usage dumpsys
New format: starttime1,endtime1 records [starttime2],endtime2 records Note starttime2 is skipped if it equals with endtime1. Bug: 34198239 Change-Id: I8a88a3bf1d50e065510d3ab123422d564fb6159f
Diffstat (limited to 'storaged')
-rw-r--r--storaged/include/storaged.h2
-rw-r--r--storaged/include/storaged_uid_monitor.h13
-rw-r--r--storaged/storaged_service.cpp12
-rw-r--r--storaged/storaged_uid_monitor.cpp40
4 files changed, 44 insertions, 23 deletions
diff --git a/storaged/include/storaged.h b/storaged/include/storaged.h
index 591719e74..c291bd98c 100644
--- a/storaged/include/storaged.h
+++ b/storaged/include/storaged.h
@@ -301,7 +301,7 @@ public:
301 std::unordered_map<uint32_t, struct uid_info> get_uids(void) { 301 std::unordered_map<uint32_t, struct uid_info> get_uids(void) {
302 return mUidm.get_uid_io_stats(); 302 return mUidm.get_uid_io_stats();
303 } 303 }
304 std::map<uint64_t, std::vector<struct uid_record>> get_uid_records( 304 std::map<uint64_t, struct uid_records> get_uid_records(
305 double hours, uint64_t threshold, bool force_report) { 305 double hours, uint64_t threshold, bool force_report) {
306 return mUidm.dump(hours, threshold, force_report); 306 return mUidm.dump(hours, threshold, force_report);
307 } 307 }
diff --git a/storaged/include/storaged_uid_monitor.h b/storaged/include/storaged_uid_monitor.h
index 031b7c4ee..b32c9a095 100644
--- a/storaged/include/storaged_uid_monitor.h
+++ b/storaged/include/storaged_uid_monitor.h
@@ -63,18 +63,25 @@ struct uid_record {
63 struct uid_io_usage ios; 63 struct uid_io_usage ios;
64}; 64};
65 65
66struct uid_records {
67 uint64_t start_ts;
68 std::vector<struct uid_record> entries;
69};
70
66class uid_monitor { 71class uid_monitor {
67private: 72private:
68 // last dump from /proc/uid_io/stats, uid -> uid_info 73 // last dump from /proc/uid_io/stats, uid -> uid_info
69 std::unordered_map<uint32_t, struct uid_info> last_uid_io_stats; 74 std::unordered_map<uint32_t, struct uid_info> last_uid_io_stats;
70 // current io usage for next report, app name -> uid_io_usage 75 // current io usage for next report, app name -> uid_io_usage
71 std::unordered_map<std::string, struct uid_io_usage> curr_io_stats; 76 std::unordered_map<std::string, struct uid_io_usage> curr_io_stats;
72 // io usage records, timestamp -> vector of events 77 // io usage records, end timestamp -> {start timestamp, vector of records}
73 std::map<uint64_t, std::vector<struct uid_record>> records; 78 std::map<uint64_t, struct uid_records> records;
74 // charger ON/OFF 79 // charger ON/OFF
75 charger_stat_t charger_stat; 80 charger_stat_t charger_stat;
76 // protects curr_io_stats, last_uid_io_stats, records and charger_stat 81 // protects curr_io_stats, last_uid_io_stats, records and charger_stat
77 sem_t um_lock; 82 sem_t um_lock;
83 // start time for IO records
84 uint64_t start_ts;
78 85
79 // reads from /proc/uid_io/stats 86 // reads from /proc/uid_io/stats
80 std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats_locked(); 87 std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats_locked();
@@ -91,7 +98,7 @@ public:
91 // called by storaged -u 98 // called by storaged -u
92 std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats(); 99 std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats();
93 // called by dumpsys 100 // called by dumpsys
94 std::map<uint64_t, std::vector<struct uid_record>> dump( 101 std::map<uint64_t, struct uid_records> dump(
95 double hours, uint64_t threshold, bool force_report); 102 double hours, uint64_t threshold, bool force_report);
96 // called by battery properties listener 103 // called by battery properties listener
97 void set_charger_state(charger_stat_t stat); 104 void set_charger_state(charger_stat_t stat);
diff --git a/storaged/storaged_service.cpp b/storaged/storaged_service.cpp
index 9c8cbf0e8..a3352982a 100644
--- a/storaged/storaged_service.cpp
+++ b/storaged/storaged_service.cpp
@@ -118,11 +118,17 @@ status_t Storaged::dump(int fd, const Vector<String16>& args) {
118 } 118 }
119 } 119 }
120 120
121 const std::map<uint64_t, std::vector<struct uid_record>>& records = 121 uint64_t last_ts = 0;
122 const std::map<uint64_t, struct uid_records>& records =
122 storaged.get_uid_records(hours, threshold, force_report); 123 storaged.get_uid_records(hours, threshold, force_report);
123 for (const auto& it : records) { 124 for (const auto& it : records) {
124 dprintf(fd, "%llu\n", (unsigned long long)it.first); 125 if (last_ts != it.second.start_ts) {
125 for (const auto& record : it.second) { 126 dprintf(fd, "%llu", (unsigned long long)it.second.start_ts);
127 }
128 dprintf(fd, ",%llu\n", (unsigned long long)it.first);
129 last_ts = it.first;
130
131 for (const auto& record : it.second.entries) {
126 dprintf(fd, "%s %llu %llu %llu %llu %llu %llu %llu %llu\n", 132 dprintf(fd, "%s %llu %llu %llu %llu %llu %llu %llu %llu\n",
127 record.name.c_str(), 133 record.name.c_str(),
128 (unsigned long long)record.ios.bytes[READ][FOREGROUND][CHARGER_OFF], 134 (unsigned long long)record.ios.bytes[READ][FOREGROUND][CHARGER_OFF],
diff --git a/storaged/storaged_uid_monitor.cpp b/storaged/storaged_uid_monitor.cpp
index 49d0d4861..78e0a832e 100644
--- a/storaged/storaged_uid_monitor.cpp
+++ b/storaged/storaged_uid_monitor.cpp
@@ -103,11 +103,11 @@ std::unordered_map<uint32_t, struct uid_info> uid_monitor::get_uid_io_stats_lock
103static const int MAX_UID_RECORDS_SIZE = 1000 * 48; // 1000 uids in 48 hours 103static const int MAX_UID_RECORDS_SIZE = 1000 * 48; // 1000 uids in 48 hours
104 104
105static inline int records_size( 105static inline int records_size(
106 const std::map<uint64_t, std::vector<struct uid_record>>& records) 106 const std::map<uint64_t, struct uid_records>& curr_records)
107{ 107{
108 int count = 0; 108 int count = 0;
109 for (auto const& it : records) { 109 for (auto const& it : curr_records) {
110 count += it.second.size(); 110 count += it.second.entries.size();
111 } 111 }
112 return count; 112 return count;
113} 113}
@@ -122,34 +122,36 @@ void uid_monitor::add_records_locked(uint64_t curr_ts)
122 records.erase(records.begin(), it); 122 records.erase(records.begin(), it);
123 } 123 }
124 124
125 std::vector<struct uid_record> new_records; 125 struct uid_records new_records;
126 for (const auto& p : curr_io_stats) { 126 for (const auto& p : curr_io_stats) {
127 struct uid_record record = {}; 127 struct uid_record record = {};
128 record.name = p.first; 128 record.name = p.first;
129 record.ios = p.second; 129 record.ios = p.second;
130 if (memcmp(&record.ios, &zero_io_usage, sizeof(struct uid_io_usage))) { 130 if (memcmp(&record.ios, &zero_io_usage, sizeof(struct uid_io_usage))) {
131 new_records.push_back(record); 131 new_records.entries.push_back(record);
132 } 132 }
133 } 133 }
134 134
135 curr_io_stats.clear(); 135 curr_io_stats.clear();
136 new_records.start_ts = start_ts;
137 start_ts = curr_ts;
136 138
137 if (new_records.empty()) 139 if (new_records.entries.empty())
138 return; 140 return;
139 141
140 // make some room for new records 142 // make some room for new records
141 int overflow = records_size(records) + 143 int overflow = records_size(records) +
142 new_records.size() - MAX_UID_RECORDS_SIZE; 144 new_records.entries.size() - MAX_UID_RECORDS_SIZE;
143 while (overflow > 0 && records.size() > 0) { 145 while (overflow > 0 && records.size() > 0) {
144 overflow -= records[0].size(); 146 auto del_it = records.begin();
147 overflow -= del_it->second.entries.size();
145 records.erase(records.begin()); 148 records.erase(records.begin());
146 } 149 }
147 150
148 records[curr_ts].insert(records[curr_ts].end(), 151 records[curr_ts] = new_records;
149 new_records.begin(), new_records.end());
150} 152}
151 153
152std::map<uint64_t, std::vector<struct uid_record>> uid_monitor::dump( 154std::map<uint64_t, struct uid_records> uid_monitor::dump(
153 double hours, uint64_t threshold, bool force_report) 155 double hours, uint64_t threshold, bool force_report)
154{ 156{
155 if (force_report) { 157 if (force_report) {
@@ -158,7 +160,7 @@ std::map<uint64_t, std::vector<struct uid_record>> uid_monitor::dump(
158 160
159 std::unique_ptr<lock_t> lock(new lock_t(&um_lock)); 161 std::unique_ptr<lock_t> lock(new lock_t(&um_lock));
160 162
161 std::map<uint64_t, std::vector<struct uid_record>> dump_records; 163 std::map<uint64_t, struct uid_records> dump_records;
162 uint64_t first_ts = 0; 164 uint64_t first_ts = 0;
163 165
164 if (hours != 0) { 166 if (hours != 0) {
@@ -166,8 +168,8 @@ std::map<uint64_t, std::vector<struct uid_record>> uid_monitor::dump(
166 } 168 }
167 169
168 for (auto it = records.lower_bound(first_ts); it != records.end(); ++it) { 170 for (auto it = records.lower_bound(first_ts); it != records.end(); ++it) {
169 const std::vector<struct uid_record>& recs = it->second; 171 const std::vector<struct uid_record>& recs = it->second.entries;
170 std::vector<struct uid_record> filtered; 172 struct uid_records filtered;
171 173
172 for (const auto& rec : recs) { 174 for (const auto& rec : recs) {
173 if (rec.ios.bytes[READ][FOREGROUND][CHARGER_ON] + 175 if (rec.ios.bytes[READ][FOREGROUND][CHARGER_ON] +
@@ -178,11 +180,16 @@ std::map<uint64_t, std::vector<struct uid_record>> uid_monitor::dump(
178 rec.ios.bytes[WRITE][FOREGROUND][CHARGER_OFF] + 180 rec.ios.bytes[WRITE][FOREGROUND][CHARGER_OFF] +
179 rec.ios.bytes[WRITE][BACKGROUND][CHARGER_ON] + 181 rec.ios.bytes[WRITE][BACKGROUND][CHARGER_ON] +
180 rec.ios.bytes[WRITE][BACKGROUND][CHARGER_OFF] > threshold) { 182 rec.ios.bytes[WRITE][BACKGROUND][CHARGER_OFF] > threshold) {
181 filtered.push_back(rec); 183 filtered.entries.push_back(rec);
182 } 184 }
183 } 185 }
186
187 if (filtered.entries.empty())
188 continue;
189
190 filtered.start_ts = it->second.start_ts;
184 dump_records.insert( 191 dump_records.insert(
185 std::pair<uint64_t, std::vector<struct uid_record>>(it->first, filtered)); 192 std::pair<uint64_t, struct uid_records>(it->first, filtered));
186 } 193 }
187 194
188 return dump_records; 195 return dump_records;
@@ -249,6 +256,7 @@ void uid_monitor::set_charger_state(charger_stat_t stat)
249void uid_monitor::init(charger_stat_t stat) 256void uid_monitor::init(charger_stat_t stat)
250{ 257{
251 charger_stat = stat; 258 charger_stat = stat;
259 start_ts = time(NULL);
252 last_uid_io_stats = get_uid_io_stats(); 260 last_uid_io_stats = get_uid_io_stats();
253} 261}
254 262