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
diff --git a/storaged/include/storaged.h b/storaged/include/storaged.h
index a16be27..0bdff74 100644
--- a/storaged/include/storaged.h
+++ b/storaged/include/storaged.h
@@ -302,8 +302,8 @@
         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) {
diff --git a/storaged/include/storaged_uid_monitor.h b/storaged/include/storaged_uid_monitor.h
index ae85016..f6250ae 100644
--- a/storaged/include/storaged_uid_monitor.h
+++ b/storaged/include/storaged_uid_monitor.h
@@ -91,10 +91,11 @@
     // 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();
 };
 
diff --git a/storaged/storaged_service.cpp b/storaged/storaged_service.cpp
index 007b75c..8624b3b 100644
--- a/storaged/storaged_service.cpp
+++ b/storaged/storaged_service.cpp
@@ -91,6 +91,7 @@
     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 @@
             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) {
diff --git a/storaged/storaged_uid_monitor.cpp b/storaged/storaged_uid_monitor.cpp
index a186b73..2c20dba 100644
--- a/storaged/storaged_uid_monitor.cpp
+++ b/storaged/storaged_uid_monitor.cpp
@@ -150,8 +150,12 @@
 }
 
 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;