am 0078f358: Merge "make_ext4fs: fix sepolicy lookup for lost+found"

* commit '0078f358ee79245e87fa8f5fc32ce30887f08357':
  make_ext4fs: fix sepolicy lookup for lost+found
diff --git a/atrace/atrace.c b/atrace/atrace.c
index 2d9b4f8..64f13e4 100644
--- a/atrace/atrace.c
+++ b/atrace/atrace.c
@@ -16,6 +16,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <getopt.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <stdbool.h>
@@ -432,7 +433,12 @@
                     "  -u              trace bus utilization\n"
                     "  -w              trace the kernel workqueue\n"
                     "  -y              trace sync timelines and waits\n"
-                    "  -z              compress the trace dump\n");
+                    "  -z              compress the trace dump\n"
+                    "  --async_start   start circular trace and return immediatly\n"
+                    "  --async_dump    dump the current contents of circular trace buffer\n"
+                    "  --async_stop    stop tracing and dump the current contents of circular\n"
+                    "                    trace buffer\n"
+            );
 }
 
 static void handleSignal(int signo) {
@@ -455,6 +461,10 @@
 int main(int argc, char **argv)
 {
     bool isRoot = (getuid() == 0);
+    bool async = false;
+    bool traceStart = true;
+    bool traceStop = true;
+    bool traceDump = true;
 
     if (argc == 2 && 0 == strcmp(argv[1], "--help")) {
         showHelp(argv[0]);
@@ -463,8 +473,16 @@
 
     for (;;) {
         int ret;
+        int option_index = 0;
+        static struct option long_options[] = {
+            {"async_start",     no_argument, 0,  0 },
+            {"async_stop",      no_argument, 0,  0 },
+            {"async_dump",      no_argument, 0,  0 },
+            {0,         0,                 0,  0 }
+        };
 
-        ret = getopt(argc, argv, "b:cidflst:uwyznS:");
+        ret = getopt_long(argc, argv, "b:cidflst:uwyznS:",
+                          long_options, &option_index);
 
         if (ret < 0) {
             break;
@@ -543,6 +561,22 @@
                 g_compress = true;
             break;
 
+            case 0:
+                if (!strcmp(long_options[option_index].name, "async_start")) {
+                    async = true;
+                    traceStop = false;
+                    traceDump = false;
+                    g_traceOverwrite = true;
+                } else if (!strcmp(long_options[option_index].name, "async_stop")) {
+                    async = true;
+                    traceStop = false;
+                } else if (!strcmp(long_options[option_index].name, "async_dump")) {
+                    async = true;
+                    traceStart = false;
+                    traceStop = false;
+                }
+                break;
+
             default:
                 fprintf(stderr, "\n");
                 showHelp(argv[0]);
@@ -559,7 +593,7 @@
 
     bool ok = startTrace(isRoot);
 
-    if (ok) {
+    if (ok && traceStart) {
         printf("capturing trace...");
         fflush(stdout);
 
@@ -570,7 +604,7 @@
         // another.
         ok = clearTrace();
 
-        if (ok) {
+        if (ok && !async) {
             // Sleep to allow the trace to be captured.
             struct timespec timeLeft;
             timeLeft.tv_sec = g_traceDurationSeconds;
@@ -584,9 +618,10 @@
     }
 
     // Stop the trace and restore the default settings.
-    stopTrace(isRoot);
+    if (traceStop)
+        stopTrace(isRoot);
 
-    if (ok) {
+    if (ok && traceDump) {
         if (!g_traceAborted) {
             printf(" done\nTRACE:\n");
             fflush(stdout);
@@ -596,12 +631,13 @@
             fflush(stdout);
         }
         clearTrace();
-    } else {
+    } else if (!ok) {
         fprintf(stderr, "unable to start tracing\n");
     }
 
     // Reset the trace buffer size to 1.
-    setTraceBufferSizeKB(1);
+    if (traceStop)
+        setTraceBufferSizeKB(1);
 
     return g_traceAborted ? 1 : 0;
 }