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

Commit 3078a9e4 authored by Sachin Sharma's avatar Sachin Sharma Committed by Linux Build Service Account
Browse files

frameworks/base: move the traces file to avoid data loss.

If an ANR comes just after the framework reboot, the traces for
the framework reboot will get over-written with the ANR traces.
So, We are missing the traces for the framework reboot which
makes debugging the framework reboot difficult.

This patch will rename and will append a unique timestamp
this trace file name for the framework reboot once the
ActivityManager collects the traces. In case of multiple
Watchdog Kills the trace file generated will have diffrent
timestamp so that it does not get overwritten on multiple
Watchdog kills.

Change-Id: I90cb400d06aa909c1560328de4751aa02dbb6858
parent 879e6505
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.text.SimpleDateFormat;

/** This class calls its monitor every minute. Killing this process if they don't return **/
public class Watchdog extends Thread {
@@ -81,6 +83,7 @@ public class Watchdog extends Thread {
    int mPhonePid;
    IActivityController mController;
    boolean mAllowRestart = true;
    SimpleDateFormat mTraceDateFormat = new SimpleDateFormat("dd_MMM_HH_mm_ss.SSS");

    /**
     * Used for checking status of handle threads and scheduling monitor callbacks.
@@ -425,6 +428,23 @@ public class Watchdog extends Thread {
                Slog.e(TAG, e.getMessage());
            }

            String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
            String traceFileNameAmendment = "_SystemServer_WDT" + mTraceDateFormat.format(new Date());

            if (tracesPath != null && tracesPath.length() != 0) {
                File traceRenameFile = new File(tracesPath);
                String newTracesPath;
                int lpos = tracesPath.lastIndexOf (".");
                if (-1 != lpos)
                    newTracesPath = tracesPath.substring (0, lpos) + traceFileNameAmendment + tracesPath.substring (lpos);
                else
                    newTracesPath = tracesPath + traceFileNameAmendment;
                traceRenameFile.renameTo(new File(newTracesPath));
                tracesPath = newTracesPath;
            }

            final File newFd = new File(tracesPath);

            // Try to add the error to the dropbox, but assuming that the ActivityManager
            // itself may be deadlocked.  (which has happened, causing this statement to
            // deadlock and the watchdog as a whole to be ineffective)
@@ -432,7 +452,7 @@ public class Watchdog extends Thread {
                    public void run() {
                        mActivity.addErrorToDropBox(
                                "watchdog", null, "system_server", null, null,
                                subject, null, stack, null);
                                subject, null, newFd, null);
                    }
                };
            dropboxThread.start();