Created functions to run dumpsys.
Such functions not only are less error prone (for example, uses just one
variable for both timeouts) but also will make it easier to pass
additional commands to dumpsys.
BUG: 28980245
Change-Id: Ib0a14eaafd83e71a50f5548f86144ac6403fa84b
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 5de7b68..8a4ebf3 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -267,6 +267,45 @@
return false;
}
+static void _run_dumpsys(const std::string& title, RootMode root_mode, int timeout_seconds,
+ const std::vector<std::string>& args) {
+ DurationReporter duration_reporter(title.c_str());
+
+ std::string timeout_string = std::to_string(timeout_seconds);
+
+ const char *dumpsys_args[ARG_MAX] = { "/system/bin/dumpsys", "-t", timeout_string.c_str()};
+
+ int index = 3; // 'dumpsys' '-t' 'TIMEOUT'
+ for (const std::string& arg : args) {
+ if (index > ARG_MAX - 2) {
+ MYLOGE("Too many arguments for '%s': %d\n", title.c_str(), (int) args.size());
+ return;
+ }
+ dumpsys_args[index++] = arg.c_str();
+ }
+ // Always terminate with nullptr.
+ dumpsys_args[index] = nullptr;
+
+ std::string args_string;
+ format_args(index, dumpsys_args, &args_string);
+ printf("------ %s (%s) ------\n", title.c_str(), args_string.c_str());
+ fflush(stdout);
+
+ ON_DRY_RUN({ update_progress(timeout_seconds); return; });
+
+ run_command_always(title.c_str(), root_mode, NORMAL_STDOUT, timeout_seconds, dumpsys_args);
+}
+
+static void run_dumpsys(const std::string& title, int timeout_seconds,
+ const std::vector<std::string>& args) {
+ _run_dumpsys(title, DONT_DROP_ROOT, timeout_seconds, args);
+}
+
+static void run_dumpsys_as_shell(const std::string& title, int timeout_seconds,
+ const std::vector<std::string>& args) {
+ _run_dumpsys(title, DROP_ROOT, timeout_seconds, args);
+}
+
static const char mmcblk0[] = "/sys/block/mmcblk0/";
unsigned long worst_write_perf = 20000; /* in KB/s */
@@ -889,7 +928,7 @@
#endif
dump_file("INTERRUPTS (1)", "/proc/interrupts");
- run_command("NETWORK DIAGNOSTICS", 10, "dumpsys", "-t", "10", "connectivity", "--diag", NULL);
+ run_dumpsys("NETWORK DIAGNOSTICS", 10, {"connectivity", "--diag"});
#ifdef FWDUMP_bcmdhd
run_command("DUMP WIFI STATUS", 20,
@@ -959,36 +998,36 @@
printf("== Android Framework Services\n");
printf("========================================================\n");
- run_command("DUMPSYS", 60, "dumpsys", "-t", "60", "--skip", "meminfo", "cpuinfo", NULL);
+ run_dumpsys("DUMPSYS", 60, {"--skip", "meminfo", "cpuinfo"});
printf("========================================================\n");
printf("== Checkins\n");
printf("========================================================\n");
- run_command("CHECKIN BATTERYSTATS", 30, "dumpsys", "-t", "30", "batterystats", "-c", NULL);
- run_command("CHECKIN MEMINFO", 30, "dumpsys", "-t", "30", "meminfo", "--checkin", NULL);
- run_command("CHECKIN NETSTATS", 30, "dumpsys", "-t", "30", "netstats", "--checkin", NULL);
- run_command("CHECKIN PROCSTATS", 30, "dumpsys", "-t", "30", "procstats", "-c", NULL);
- run_command("CHECKIN USAGESTATS", 30, "dumpsys", "-t", "30", "usagestats", "-c", NULL);
- run_command("CHECKIN PACKAGE", 30, "dumpsys", "-t", "30", "package", "--checkin", NULL);
+ run_dumpsys("CHECKIN BATTERYSTATS", 30, {"batterystats", "-c"});
+ run_dumpsys("CHECKIN MEMINFO", 30, {"meminfo", "--checkin"});
+ run_dumpsys("CHECKIN NETSTATS", 30, {"netstats", "--checkin"});
+ run_dumpsys("CHECKIN PROCSTATS", 30, {"procstats", "-c"});
+ run_dumpsys("CHECKIN USAGESTATS", 30, {"usagestats", "-c"});
+ run_dumpsys("CHECKIN PACKAGE", 30, {"package", "--checkin"});
printf("========================================================\n");
printf("== Running Application Activities\n");
printf("========================================================\n");
- run_command("APP ACTIVITIES", 30, "dumpsys", "-t", "30", "activity", "all", NULL);
+ run_dumpsys("APP ACTIVITIES", 30, {"activity", "all"});
printf("========================================================\n");
printf("== Running Application Services\n");
printf("========================================================\n");
- run_command("APP SERVICES", 30, "dumpsys", "-t", "30", "activity", "service", "all", NULL);
+ run_dumpsys("APP SERVICES", 30, {"activity", "service", "all"});
printf("========================================================\n");
printf("== Running Application Providers\n");
printf("========================================================\n");
- run_command("APP PROVIDERS", 30, "dumpsys", "-t", "30", "activity", "provider", "all", NULL);
+ run_dumpsys("APP PROVIDERS", 30, {"activity", "provider", "all"});
printf("========================================================\n");
@@ -1365,8 +1404,8 @@
// Invoking the following dumpsys calls before dump_traces() to try and
// keep the system stats as close to its initial state as possible.
- run_command_as_shell("DUMPSYS MEMINFO", 90, "dumpsys", "-t", "90", "meminfo", "-a", NULL);
- run_command_as_shell("DUMPSYS CPUINFO", 10, "dumpsys", "-t", "10", "cpuinfo", "-a", NULL);
+ run_dumpsys_as_shell("DUMPSYS MEMINFO", 90, {"meminfo", "-a"});
+ run_dumpsys_as_shell("DUMPSYS CPUINFO", 10, {"cpuinfo", "-a"});
/* collect stack traces from Dalvik and native processes (needs root) */
dump_traces_path = dump_traces();