]> git.cworth.org Git - apitrace/blobdiff - cli/cli_dump.cpp
Allow to use call sets instead of call numbers / frequencies.
[apitrace] / cli / cli_dump.cpp
index 2164518d5e264712f7729596bfc90048f5b5b3c4..3f6bea2e0fd03d0463e74edf1d599b435cbb53ce 100644 (file)
@@ -1,5 +1,6 @@
 /**************************************************************************
  *
+ * Copyright 2011 Jose Fonseca
  * Copyright 2010 VMware, Inc.
  * All Rights Reserved.
  *
  *
  **************************************************************************/
 
+
 #include <string.h>
 
 #include "cli.hpp"
+#include "cli_pager.hpp"
 
 #include "trace_parser.hpp"
+#include "trace_dump.hpp"
+#include "trace_callset.hpp"
+
 
 enum ColorOption {
     COLOR_OPTION_NEVER = 0,
@@ -37,6 +43,10 @@ enum ColorOption {
 
 static ColorOption color = COLOR_OPTION_AUTO;
 
+static bool verbose = false;
+
+static trace::CallSet calls(trace::FREQUENCY_ALL);
+
 static const char *synopsis = "Dump given trace(s) to standard output.";
 
 static void
@@ -46,28 +56,43 @@ usage(void)
         << "usage: apitrace dump [OPTIONS] <trace-file>...\n"
         << synopsis << "\n"
         "\n"
+        "    -v, --verbose       verbose output\n"
+        "    --calls <CALLSET>   Only dump specified calls\n"
         "    --color=<WHEN>\n"
         "    --colour=<WHEN>     Colored syntax highlighting\n"
-        "                        WHEN is 'auto', 'always', or 'never'\n";
+        "                        WHEN is 'auto', 'always', or 'never'\n"
+        "    --no-arg-names      Don't dump argument names\n"
+        "    --thread-ids        Dump thread ids\n"
+    ;
 }
 
 static int
 command(int argc, char *argv[])
 {
+    trace::DumpFlags dumpFlags = 0;
+    bool dumpThreadIds = false;
+
     int i;
 
-    for (i = 0; i < argc; ++i) {
+    for (i = 0; i < argc;) {
         const char *arg = argv[i];
 
         if (arg[0] != '-') {
             break;
         }
 
+        ++i;
+
         if (!strcmp(arg, "--")) {
             break;
         } else if (!strcmp(arg, "--help")) {
             usage();
             return 0;
+        } else if (strcmp(arg, "-v") == 0 ||
+                   strcmp(arg, "--verbose") == 0) {
+            verbose = true;
+        } else if (!strcmp(arg, "--calls")) {
+            calls = trace::CallSet(argv[i++]);
         } else if (!strcmp(arg, "--color=auto") ||
                    !strcmp(arg, "--colour=auto")) {
             color = COLOR_OPTION_AUTO;
@@ -81,6 +106,10 @@ command(int argc, char *argv[])
                    !strcmp(arg, "--no-color") ||
                    !strcmp(arg, "--no-colour")) {
             color = COLOR_OPTION_NEVER;
+        } else if (!strcmp(arg, "--no-arg-names")) {
+            dumpFlags |= trace::DUMP_FLAG_NO_ARG_NAMES;
+        } else if (!strcmp(arg, "--thread-ids")) {
+            dumpThreadIds = true;
         } else {
             std::cerr << "error: unknown option " << arg << "\n";
             usage();
@@ -93,9 +122,14 @@ command(int argc, char *argv[])
         color = COLOR_OPTION_ALWAYS;
 #else
         color = isatty(1) ? COLOR_OPTION_ALWAYS : COLOR_OPTION_NEVER;
+        pipepager();
 #endif
     }
 
+    if (color == COLOR_OPTION_NEVER) {
+        dumpFlags |= trace::DUMP_FLAG_NO_COLOR;
+    }
+
     for (; i < argc; ++i) {
         trace::Parser p;
 
@@ -106,7 +140,15 @@ command(int argc, char *argv[])
 
         trace::Call *call;
         while ((call = p.parse_call())) {
-            call->dump(std::cout, color);
+            if (calls.contains(*call)) {
+                if (verbose ||
+                    !(call->flags & trace::CALL_FLAG_VERBOSE)) {
+                    if (dumpThreadIds) {
+                        std::cout << std::hex << call->thread_id << std::dec << " ";
+                    }
+                    trace::dump(*call, std::cout, dumpFlags);
+                }
+            }
             delete call;
         }
     }
@@ -114,7 +156,7 @@ command(int argc, char *argv[])
     return 0;
 }
 
-const Command dump = {
+const Command dump_command = {
     "dump",
     synopsis,
     usage,