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

Commit 05352fd5 authored by Zhengyin Qian's avatar Zhengyin Qian Committed by android-build-merger
Browse files

make sure anrd trace is being collected.

am: afc38fe2

Change-Id: I2032769fc587c38dd62c58bbeae8a2e4e9ab073b
parents a0514298 afc38fe2
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -219,7 +219,8 @@ static bool dump_anrd_trace() {
    struct dirent *trace;
    struct stat st;
    DIR *trace_dir;
    long max_ctime = 0;
    int retry = 5;
    long max_ctime = 0, old_mtime;
    long long cur_size = 0;
    const char *trace_path = "/data/misc/anrd/";

@@ -232,6 +233,13 @@ static bool dump_anrd_trace() {
    pid = pid_of_process("/system/xbin/anrd");

    if (pid > 0) {
        if (stat(trace_path, &st) == 0) {
            old_mtime = st.st_mtime;
        } else {
            MYLOGE("Failed to find: %s\n", trace_path);
            return false;
        }

        // send SIGUSR1 to the anrd to generate a trace.
        sprintf(buf, "%u", pid);
        if (run_command("ANRD_DUMP", 1, "kill", "-SIGUSR1", buf, NULL)) {
@@ -239,6 +247,16 @@ static bool dump_anrd_trace() {
            return false;
        }

        while (retry-- > 0 && old_mtime == st.st_mtime) {
            sleep(1);
            stat(trace_path, &st);
        }

        if (retry < 0 && old_mtime == st.st_mtime) {
            MYLOGE("Failed to stat %s or trace creation timeout\n", trace_path);
            return false;
        }

        // identify the trace file by its creation time.
        if (!(trace_dir = opendir(trace_path))) {
            MYLOGE("Can't open trace file under %s\n", trace_path);