Add -n and -S options for 'nohup', offline traces

Change-Id: Ieef12b36b8519ff689ab5a81447b1b9bf4806171
diff --git a/atrace/atrace.c b/atrace/atrace.c
index 5edc47b..890165a 100644
--- a/atrace/atrace.c
+++ b/atrace/atrace.c
@@ -39,6 +39,8 @@
 static bool g_traceOverwrite = false;
 static int g_traceBufferSizeKB = 2048;
 static bool g_compress = false;
+static bool g_nohup = false;
+static int g_initialSleepSecs = 0;
 
 /* Global state */
 static bool g_traceAborted = false;
@@ -417,7 +419,9 @@
 }
 
 static void handleSignal(int signo) {
-    g_traceAborted = true;
+    if (!g_nohup) {
+        g_traceAborted = true;
+    }
 }
 
 static void registerSigHandler() {
@@ -443,7 +447,7 @@
     for (;;) {
         int ret;
 
-        ret = getopt(argc, argv, "b:cidflst:uwz");
+        ret = getopt(argc, argv, "b:cidflst:uwznS:");
 
         if (ret < 0) {
             break;
@@ -478,10 +482,18 @@
                 g_traceFrequency = true;
             break;
 
+            case 'n':
+                g_nohup = true;
+                break;
+
             case 's':
                 g_traceSchedSwitch = true;
             break;
 
+            case 'S':
+                g_initialSleepSecs = atoi(optarg);
+            break;
+
             case 't':
                 g_traceDurationSeconds = atoi(optarg);
             break;
@@ -516,6 +528,10 @@
 
     registerSigHandler();
 
+    if (g_initialSleepSecs > 0) {
+        sleep(g_initialSleepSecs);
+    }
+
     bool ok = startTrace(isRoot);
 
     if (ok) {