summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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:
#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<uint32_t, struct uid_info> get_uids(void) {
return mUidm.get_uid_io_stats();
}
- std::map<uint64_t, std::vector<struct uid_record>> get_uid_records(int hours) {
- return mUidm.dump(hours);
+ std::map<uint64_t, std::vector<struct uid_record>> 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<uint32_t, struct uid_info> get_uid_io_stats();
// called by dumpsys
- std::map<uint64_t, std::vector<struct uid_record>> dump(int hours);
+ std::map<uint64_t, std::vector<struct uid_record>> 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<String16>& 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<String16>& 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<uint64_t, std::vector<struct uid_record>>& 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<String16>& 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<uint64_t, std::vector<struct uid_record>> uid_monitor::dump(int hours)
+std::map<uint64_t, std::vector<struct uid_record>> uid_monitor::dump(
+ int hours, uint64_t threshold)
{
std::unique_ptr<lock_t> lock(new lock_t(&um_lock));
@@ -160,7 +161,25 @@ std::map<uint64_t, std::vector<struct uid_record>> 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<struct uid_record>& recs = it->second;
+ std::vector<struct uid_record> 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<uint64_t, std::vector<struct uid_record>>(it->first, filtered));
+ }
return dump_records;
}