summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJin Qian2017-03-02 18:16:54 -0600
committerJin Qian2017-03-02 18:16:54 -0600
commite83a6107c7b5c4e5bc4cca56012025de301212e7 (patch)
tree8c2b42c4ba9d8b4ee5299ae0a0a25f9959c71fc3 /storaged
parent135f161bae64d04e33574fb7309b0890d85d6b84 (diff)
downloadplatform-system-core-e83a6107c7b5c4e5bc4cca56012025de301212e7.tar.gz
platform-system-core-e83a6107c7b5c4e5bc4cca56012025de301212e7.tar.xz
platform-system-core-e83a6107c7b5c4e5bc4cca56012025de301212e7.zip
storaged: track fsync calls
Change-Id: Ibdb6a1703245a5de04cb4a2ee5b8ecfbed8b86fc
Diffstat (limited to 'storaged')
-rw-r--r--storaged/include/storaged_uid_monitor.h1
-rw-r--r--storaged/storaged_uid_monitor.cpp41
-rw-r--r--storaged/storaged_utils.cpp11
3 files changed, 32 insertions, 21 deletions
diff --git a/storaged/include/storaged_uid_monitor.h b/storaged/include/storaged_uid_monitor.h
index b32c9a095..901a8721b 100644
--- a/storaged/include/storaged_uid_monitor.h
+++ b/storaged/include/storaged_uid_monitor.h
@@ -46,6 +46,7 @@ struct uid_io_stats {
46 uint64_t wchar; // characters written 46 uint64_t wchar; // characters written
47 uint64_t read_bytes; // bytes read (from storage layer) 47 uint64_t read_bytes; // bytes read (from storage layer)
48 uint64_t write_bytes; // bytes written (to storage layer) 48 uint64_t write_bytes; // bytes written (to storage layer)
49 uint64_t fsync; // number of fsync syscalls
49}; 50};
50 51
51struct uid_info { 52struct uid_info {
diff --git a/storaged/storaged_uid_monitor.cpp b/storaged/storaged_uid_monitor.cpp
index 78e0a832e..8bb6bf30b 100644
--- a/storaged/storaged_uid_monitor.cpp
+++ b/storaged/storaged_uid_monitor.cpp
@@ -20,12 +20,12 @@
20#include <time.h> 20#include <time.h>
21 21
22#include <string> 22#include <string>
23#include <sstream>
24#include <unordered_map> 23#include <unordered_map>
25 24
26#include <android-base/file.h> 25#include <android-base/file.h>
27#include <android-base/logging.h> 26#include <android-base/logging.h>
28#include <android-base/macros.h> 27#include <android-base/macros.h>
28#include <android-base/strings.h>
29#include <android-base/stringprintf.h> 29#include <android-base/stringprintf.h>
30#include <log/log_event_list.h> 30#include <log/log_event_list.h>
31#include <packagelistparser/packagelistparser.h> 31#include <packagelistparser/packagelistparser.h>
@@ -64,19 +64,33 @@ std::unordered_map<uint32_t, struct uid_info> uid_monitor::get_uid_io_stats_lock
64 return uid_io_stats; 64 return uid_io_stats;
65 } 65 }
66 66
67 std::stringstream ss(buffer); 67 std::vector<std::string> io_stats = android::base::Split(buffer, "\n");
68 struct uid_info u; 68 struct uid_info u;
69 bool refresh_uid = false; 69 bool refresh_uid = false;
70 70
71 while (ss >> u.uid) { 71 for (uint32_t i = 0; i < io_stats.size(); i++) {
72 ss >> u.io[FOREGROUND].rchar >> u.io[FOREGROUND].wchar 72 if (io_stats[i].empty()) {
73 >> u.io[FOREGROUND].read_bytes >> u.io[FOREGROUND].write_bytes 73 continue;
74 >> u.io[BACKGROUND].rchar >> u.io[BACKGROUND].wchar 74 }
75 >> u.io[BACKGROUND].read_bytes >> u.io[BACKGROUND].write_bytes; 75 std::vector<std::string> fields = android::base::Split(io_stats[i], " ");
76 76 if (fields.size() < 9) {
77 if (!ss.good()) { 77 LOG_TO(SYSTEM, WARNING) << "Invalid io stats: \""
78 ss.clear(std::ios_base::badbit); 78 << io_stats[i] << "\"";
79 break; 79 continue;
80 }
81 u.uid = stoul(fields[0]);
82 u.io[FOREGROUND].rchar = stoull(fields[1]);
83 u.io[FOREGROUND].wchar = stoull(fields[2]);
84 u.io[FOREGROUND].read_bytes = stoull(fields[3]);
85 u.io[FOREGROUND].write_bytes = stoull(fields[4]);
86 u.io[BACKGROUND].rchar = stoull(fields[5]);
87 u.io[BACKGROUND].wchar = stoull(fields[6]);
88 u.io[BACKGROUND].read_bytes = stoull(fields[7]);
89 u.io[BACKGROUND].write_bytes = stoull(fields[8]);
90
91 if (fields.size() == 11) {
92 u.io[FOREGROUND].fsync = stoull(fields[9]);
93 u.io[BACKGROUND].fsync = stoull(fields[10]);
80 } 94 }
81 95
82 if (last_uid_io_stats.find(u.uid) == last_uid_io_stats.end()) { 96 if (last_uid_io_stats.find(u.uid) == last_uid_io_stats.end()) {
@@ -88,11 +102,6 @@ std::unordered_map<uint32_t, struct uid_info> uid_monitor::get_uid_io_stats_lock
88 uid_io_stats[u.uid] = u; 102 uid_io_stats[u.uid] = u;
89 } 103 }
90 104
91 if (!ss.eof() || ss.bad()) {
92 uid_io_stats.clear();
93 LOG_TO(SYSTEM, ERROR) << "read UID IO stats failed";
94 }
95
96 if (refresh_uid) { 105 if (refresh_uid) {
97 packagelist_parse(packagelist_parse_cb, &uid_io_stats); 106 packagelist_parse(packagelist_parse_cb, &uid_io_stats);
98 } 107 }
diff --git a/storaged/storaged_utils.cpp b/storaged/storaged_utils.cpp
index 1ef89af68..5df018581 100644
--- a/storaged/storaged_utils.cpp
+++ b/storaged/storaged_utils.cpp
@@ -281,14 +281,15 @@ void log_console_running_uids_info(std::vector<struct uid_info> uids) {
281 281
282 // Title 282 // Title
283 printf("Per-UID I/O stats\n"); 283 printf("Per-UID I/O stats\n");
284 printf(" Application FG Read FG Write FG Read FG Write BG Read BG Write BG Read BG Write\n" 284 printf(" Application FG Read FG Write FG Read FG Write BG Read BG Write BG Read BG Write FG fsync BG fsync\n"
285 " NAME/UID Characters Characters Bytes Bytes Characters Characters Bytes Bytes\n" 285 " NAME/UID Characters Characters Bytes Bytes Characters Characters Bytes Bytes \n"
286 " ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------\n"); 286 " ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------\n");
287 287
288 for (const auto& uid : uids) { 288 for (const auto& uid : uids) {
289 printf("%50s%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju\n", uid.name.c_str(), 289 printf("%50s%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju\n", uid.name.c_str(),
290 uid.io[0].rchar, uid.io[0].wchar, uid.io[0].read_bytes, uid.io[0].write_bytes, 290 uid.io[0].rchar, uid.io[0].wchar, uid.io[0].read_bytes, uid.io[0].write_bytes,
291 uid.io[1].rchar, uid.io[1].wchar, uid.io[1].read_bytes, uid.io[1].write_bytes); 291 uid.io[1].rchar, uid.io[1].wchar, uid.io[1].read_bytes, uid.io[1].write_bytes,
292 uid.io[0].fsync, uid.io[1].fsync);
292 } 293 }
293 fflush(stdout); 294 fflush(stdout);
294} 295}