storaged: add --force option to dumpsys

This option forces storaged to generate io usage report since last
report. This is for testing purpose so that we can run some app and
get the app's IO usage right away instead of waiting an hour for next
report.

Bug: 34198239
Bug: 34845096
Change-Id: I9cd217df37a9b6c8f383eb25d41602e8e8c8f9ba
This commit is contained in:
Jin Qian 2017-02-06 14:02:50 -08:00
parent e5ea17c840
commit 1275b1b6aa
4 changed files with 16 additions and 6 deletions

View File

@ -302,8 +302,8 @@ public:
return mUidm.get_uid_io_stats();
}
std::map<uint64_t, std::vector<struct uid_record>> get_uid_records(
int hours, uint64_t threshold) {
return mUidm.dump(hours, threshold);
int hours, uint64_t threshold, bool force_report) {
return mUidm.dump(hours, threshold, force_report);
}
void update_uid_io_interval(int interval) {
if (interval >= DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO_LIMIT) {

View File

@ -91,10 +91,11 @@ 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, uint64_t threshold);
std::map<uint64_t, std::vector<struct uid_record>> dump(
int hours, uint64_t threshold, bool force_report);
// called by battery properties listener
void set_charger_state(charger_stat_t stat);
// called by storaged periodic_chore
// called by storaged periodic_chore or dump with force_report
void report();
};

View File

@ -91,6 +91,7 @@ status_t Storaged::dump(int fd, const Vector<String16>& args) {
int hours = 0;
int time_window = 0;
uint64_t threshold = 0;
bool force_report = false;
for (size_t i = 0; i < args.size(); i++) {
const auto& arg = args[i];
if (arg == String16("--hours")) {
@ -111,10 +112,14 @@ status_t Storaged::dump(int fd, const Vector<String16>& args) {
threshold = stoll(String16::std_string(args[i]));
continue;
}
if (arg == String16("--force")) {
force_report = true;
continue;
}
}
const std::map<uint64_t, std::vector<struct uid_record>>& records =
storaged.get_uid_records(hours, threshold);
storaged.get_uid_records(hours, threshold, force_report);
for (const auto& it : records) {
dprintf(fd, "%llu\n", (unsigned long long)it.first);
for (const auto& record : it.second) {

View File

@ -150,8 +150,12 @@ void uid_monitor::add_records_locked(uint64_t curr_ts)
}
std::map<uint64_t, std::vector<struct uid_record>> uid_monitor::dump(
int hours, uint64_t threshold)
int hours, uint64_t threshold, bool force_report)
{
if (force_report) {
report();
}
std::unique_ptr<lock_t> lock(new lock_t(&um_lock));
std::map<uint64_t, std::vector<struct uid_record>> dump_records;