From e83a6107c7b5c4e5bc4cca56012025de301212e7 Mon Sep 17 00:00:00 2001 From: Jin Qian Date: Thu, 2 Mar 2017 16:16:54 -0800 Subject: [PATCH] storaged: track fsync calls Change-Id: Ibdb6a1703245a5de04cb4a2ee5b8ecfbed8b86fc --- storaged/include/storaged_uid_monitor.h | 1 + storaged/storaged_uid_monitor.cpp | 39 +++++++++++++++---------- storaged/storaged_utils.cpp | 11 +++---- 3 files changed, 31 insertions(+), 20 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 { uint64_t wchar; // characters written uint64_t read_bytes; // bytes read (from storage layer) uint64_t write_bytes; // bytes written (to storage layer) + uint64_t fsync; // number of fsync syscalls }; struct 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 @@ #include #include -#include #include #include #include #include +#include #include #include #include @@ -64,19 +64,33 @@ std::unordered_map uid_monitor::get_uid_io_stats_lock return uid_io_stats; } - std::stringstream ss(buffer); + std::vector io_stats = android::base::Split(buffer, "\n"); struct uid_info u; bool refresh_uid = false; - while (ss >> u.uid) { - ss >> u.io[FOREGROUND].rchar >> u.io[FOREGROUND].wchar - >> u.io[FOREGROUND].read_bytes >> u.io[FOREGROUND].write_bytes - >> u.io[BACKGROUND].rchar >> u.io[BACKGROUND].wchar - >> u.io[BACKGROUND].read_bytes >> u.io[BACKGROUND].write_bytes; + for (uint32_t i = 0; i < io_stats.size(); i++) { + if (io_stats[i].empty()) { + continue; + } + std::vector fields = android::base::Split(io_stats[i], " "); + if (fields.size() < 9) { + LOG_TO(SYSTEM, WARNING) << "Invalid io stats: \"" + << io_stats[i] << "\""; + continue; + } + u.uid = stoul(fields[0]); + u.io[FOREGROUND].rchar = stoull(fields[1]); + u.io[FOREGROUND].wchar = stoull(fields[2]); + u.io[FOREGROUND].read_bytes = stoull(fields[3]); + u.io[FOREGROUND].write_bytes = stoull(fields[4]); + u.io[BACKGROUND].rchar = stoull(fields[5]); + u.io[BACKGROUND].wchar = stoull(fields[6]); + u.io[BACKGROUND].read_bytes = stoull(fields[7]); + u.io[BACKGROUND].write_bytes = stoull(fields[8]); - if (!ss.good()) { - ss.clear(std::ios_base::badbit); - break; + if (fields.size() == 11) { + u.io[FOREGROUND].fsync = stoull(fields[9]); + u.io[BACKGROUND].fsync = stoull(fields[10]); } if (last_uid_io_stats.find(u.uid) == last_uid_io_stats.end()) { @@ -88,11 +102,6 @@ std::unordered_map uid_monitor::get_uid_io_stats_lock uid_io_stats[u.uid] = u; } - if (!ss.eof() || ss.bad()) { - uid_io_stats.clear(); - LOG_TO(SYSTEM, ERROR) << "read UID IO stats failed"; - } - if (refresh_uid) { packagelist_parse(packagelist_parse_cb, &uid_io_stats); } 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 uids) { // Title printf("Per-UID I/O stats\n"); - printf(" Application FG Read FG Write FG Read FG Write BG Read BG Write BG Read BG Write\n" - " NAME/UID Characters Characters Bytes Bytes Characters Characters Bytes Bytes\n" - " ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------\n"); + printf(" Application FG Read FG Write FG Read FG Write BG Read BG Write BG Read BG Write FG fsync BG fsync\n" + " NAME/UID Characters Characters Bytes Bytes Characters Characters Bytes Bytes \n" + " ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------\n"); for (const auto& uid : uids) { - printf("%50s%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju\n", uid.name.c_str(), + printf("%50s%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju\n", uid.name.c_str(), uid.io[0].rchar, uid.io[0].wchar, uid.io[0].read_bytes, uid.io[0].write_bytes, - uid.io[1].rchar, uid.io[1].wchar, uid.io[1].read_bytes, uid.io[1].write_bytes); + uid.io[1].rchar, uid.io[1].wchar, uid.io[1].read_bytes, uid.io[1].write_bytes, + uid.io[0].fsync, uid.io[1].fsync); } fflush(stdout); }