Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc42bdae authored by Felipe Leme's avatar Felipe Leme
Browse files

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
parent bb3ff929
Loading
Loading
Loading
Loading
+52 −13
Original line number Original line Diff line number Diff line
@@ -267,6 +267,45 @@ static bool skip_none(const char *path) {
    return false;
    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/";
static const char mmcblk0[] = "/sys/block/mmcblk0/";
unsigned long worst_write_perf = 20000; /* in KB/s */
unsigned long worst_write_perf = 20000; /* in KB/s */


@@ -889,7 +928,7 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver
#endif
#endif
    dump_file("INTERRUPTS (1)", "/proc/interrupts");
    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
#ifdef FWDUMP_bcmdhd
    run_command("DUMP WIFI STATUS", 20,
    run_command("DUMP WIFI STATUS", 20,
@@ -959,36 +998,36 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver
    printf("== Android Framework Services\n");
    printf("== Android Framework Services\n");
    printf("========================================================\n");
    printf("========================================================\n");


    run_command("DUMPSYS", 60, "dumpsys", "-t", "60", "--skip", "meminfo", "cpuinfo", NULL);
    run_dumpsys("DUMPSYS", 60, {"--skip", "meminfo", "cpuinfo"});


    printf("========================================================\n");
    printf("========================================================\n");
    printf("== Checkins\n");
    printf("== Checkins\n");
    printf("========================================================\n");
    printf("========================================================\n");


    run_command("CHECKIN BATTERYSTATS", 30, "dumpsys", "-t", "30", "batterystats", "-c", NULL);
    run_dumpsys("CHECKIN BATTERYSTATS", 30, {"batterystats", "-c"});
    run_command("CHECKIN MEMINFO", 30, "dumpsys", "-t", "30", "meminfo", "--checkin", NULL);
    run_dumpsys("CHECKIN MEMINFO", 30, {"meminfo", "--checkin"});
    run_command("CHECKIN NETSTATS", 30, "dumpsys", "-t", "30", "netstats", "--checkin", NULL);
    run_dumpsys("CHECKIN NETSTATS", 30, {"netstats", "--checkin"});
    run_command("CHECKIN PROCSTATS", 30, "dumpsys", "-t", "30", "procstats", "-c", NULL);
    run_dumpsys("CHECKIN PROCSTATS", 30, {"procstats", "-c"});
    run_command("CHECKIN USAGESTATS", 30, "dumpsys", "-t", "30", "usagestats", "-c", NULL);
    run_dumpsys("CHECKIN USAGESTATS", 30, {"usagestats", "-c"});
    run_command("CHECKIN PACKAGE", 30, "dumpsys", "-t", "30", "package", "--checkin", NULL);
    run_dumpsys("CHECKIN PACKAGE", 30, {"package", "--checkin"});


    printf("========================================================\n");
    printf("========================================================\n");
    printf("== Running Application Activities\n");
    printf("== Running Application Activities\n");
    printf("========================================================\n");
    printf("========================================================\n");


    run_command("APP ACTIVITIES", 30, "dumpsys", "-t", "30", "activity", "all", NULL);
    run_dumpsys("APP ACTIVITIES", 30, {"activity", "all"});


    printf("========================================================\n");
    printf("========================================================\n");
    printf("== Running Application Services\n");
    printf("== Running Application Services\n");
    printf("========================================================\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("========================================================\n");
    printf("== Running Application Providers\n");
    printf("== Running Application Providers\n");
    printf("========================================================\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");
    printf("========================================================\n");
@@ -1365,8 +1404,8 @@ int main(int argc, char *argv[]) {


    // Invoking the following dumpsys calls before dump_traces() to try and
    // Invoking the following dumpsys calls before dump_traces() to try and
    // keep the system stats as close to its initial state as possible.
    // 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_dumpsys_as_shell("DUMPSYS MEMINFO", 90, {"meminfo", "-a"});
    run_command_as_shell("DUMPSYS CPUINFO", 10, "dumpsys", "-t", "10", "cpuinfo", "-a", NULL);
    run_dumpsys_as_shell("DUMPSYS CPUINFO", 10, {"cpuinfo", "-a"});


    /* collect stack traces from Dalvik and native processes (needs root) */
    /* collect stack traces from Dalvik and native processes (needs root) */
    dump_traces_path = dump_traces();
    dump_traces_path = dump_traces();
+10 −6
Original line number Original line Diff line number Diff line
@@ -644,7 +644,7 @@ int run_command(const char *title, int timeout_seconds, const char *command, ...
    DurationReporter duration_reporter(title);
    DurationReporter duration_reporter(title);
    fflush(stdout);
    fflush(stdout);


    const char *args[1024] = {command};
    const char *args[ARG_MAX] = {command};
    size_t arg;
    size_t arg;
    va_list ap;
    va_list ap;
    va_start(ap, command);
    va_start(ap, command);
@@ -682,7 +682,7 @@ int run_command_as_shell(const char *title, int timeout_seconds, const char *com
    DurationReporter duration_reporter(title);
    DurationReporter duration_reporter(title);
    fflush(stdout);
    fflush(stdout);


    const char *args[1024] = {command};
    const char *args[ARG_MAX] = {command};
    size_t arg;
    size_t arg;
    va_list ap;
    va_list ap;
    va_start(ap, command);
    va_start(ap, command);
@@ -871,14 +871,18 @@ void send_broadcast(const std::string& action, const std::vector<std::string>& a
        MYLOGE("send_broadcast: too many arguments (%d)\n", (int) args.size());
        MYLOGE("send_broadcast: too many arguments (%d)\n", (int) args.size());
        return;
        return;
    }
    }
    const char *am_args[1024] = { "/system/bin/am", "broadcast", "--user", "0", "-a",
    const char *am_args[ARG_MAX] = { "/system/bin/am", "broadcast", "--user", "0", "-a",
                                     action.c_str() };
                                     action.c_str() };
    size_t am_index = 5; // Starts at the index of last initial value above.
    size_t am_index = 5; // Starts at the index of last initial value above.
    for (const std::string& arg : args) {
    for (const std::string& arg : args) {
        if (am_index > ARG_MAX - 2) {
            MYLOGE("send_broadcast: too many arguments (%d)\n", (int) args.size());
            return;
        }
        am_args[++am_index] = arg.c_str();
        am_args[++am_index] = arg.c_str();
    }
    }
    // Always terminate with NULL.
    // Always terminate with nullptr.
    am_args[am_index + 1] = NULL;
    am_args[am_index + 1] = nullptr;
    std::string args_string;
    std::string args_string;
    format_args(am_index + 1, am_args, &args_string);
    format_args(am_index + 1, am_args, &args_string);
    MYLOGD("send_broadcast command: %s\n", args_string.c_str());
    MYLOGD("send_broadcast command: %s\n", args_string.c_str());