]> git.cworth.org Git - apitrace/commitdiff
cli: Auto-detect retrace for dump-images too.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 21 Nov 2012 08:58:42 +0000 (08:58 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 21 Nov 2012 08:58:42 +0000 (08:58 +0000)
README.markdown
cli/cli_dump_images.cpp
cli/cli_retrace.cpp
cli/cli_retrace.hpp [new file with mode: 0644]

index eb0945b5db2e865d99f7302adb788336737066c2..4e596cc172269299749ef731132ae03964295570 100644 (file)
@@ -373,7 +373,7 @@ These are the steps to create a regression test-suite around **apitrace**:
 * obtain reference snapshots, by doing on a reference system:
 
         mkdir /path/to/reference/snapshots/
-        glretrace -s /path/to/reference/snapshots/ application.trace
+        apitrace dump-images -o /path/to/reference/snapshots/ application.trace
 
 * prune the snapshots which are not interesting
 
@@ -383,7 +383,7 @@ These are the steps to create a regression test-suite around **apitrace**:
 
   Alternatively, for a HTML summary, use `apitrace diff-images`:
 
-        glretrace -s /path/to/test/snapshots/ application.trace
+        apitrace dump-images -o /path/to/test/snapshots/ application.trace
         apitrace diff-images --output summary.html /path/to/reference/snapshots/ /path/to/test/snapshots/
 
 
index 594f001e4c7b68ddc656d3ff0897a3792bf6b355..0e2dd8c8b6cfaf6919253a0ffdc8b841fad1dd5e 100644 (file)
 #include <getopt.h>
 #include <iostream>
 
-#include "cli.hpp"
-
 #include "os_string.hpp"
-#include "os_process.hpp"
 
-#include "trace_resource.hpp"
+#include "cli.hpp"
+#include "cli_retrace.hpp"
 
 static const char *synopsis = "Dump frame images obtained from a trace.";
 
@@ -74,7 +72,9 @@ static int
 command(int argc, char *argv[])
 {
     os::String prefix;
-    const char *calls, *filename, *output = NULL;
+    const char *calls = NULL;
+    const char *traceName = NULL;
+    const char *output = NULL;
 
     int opt;
     while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
@@ -107,30 +107,27 @@ command(int argc, char *argv[])
         return 1;
     }
 
-    filename = argv[optind];
+    traceName = argv[optind];
 
     if (output == NULL) {
-        prefix = filename;
+        prefix = traceName;
         prefix.trimDirectory();
         prefix.trimExtension();
+        prefix.append('.');
         output = prefix.str();
     }
 
-    std::vector<const char *> command;
+    std::vector<const char *> opts;
 
-    os::String glretracePath = trace::findProgram("glretrace");
-    command.push_back(glretracePath);
-    command.push_back("-s");
-    command.push_back(output);
-    command.push_back("-S");
+    opts.push_back("-s");
+    opts.push_back(output);
+    opts.push_back("-S");
     if (calls)
-        command.push_back(calls);
+        opts.push_back(calls);
     else
-        command.push_back("*/frame");
-    command.push_back(filename);
-    command.push_back(NULL);
+        opts.push_back("*/frame");
 
-    return os::execute((char * const *)&command[0]);
+    return executeRetrace(opts, traceName);
 }
 
 const Command dump_images_command = {
index de5eb6b9fc4daa11fb959849cd02699b0fe4e509..cf9ffdf5786f0d46f313e016c8e19ac58316c387 100644 (file)
 #include <getopt.h>
 #include <iostream>
 
-#include "cli.hpp"
-
 #include "os_string.hpp"
 #include "os_process.hpp"
 
 #include "trace_parser.hpp"
 #include "trace_resource.hpp"
 
+#include "cli.hpp"
+#include "cli_retrace.hpp"
+
 static const char *synopsis = "Replay a trace.";
 
 static void
 usage(void)
 {
-    std::cout << "usage apitrace retrace [OPTIONS] TRACE_FILE\n"
+    std::cout << "usage: apitrace retrace [OPTIONS] TRACE_FILE\n"
               << synopsis << "\n"
            "\n"
            "    -h, --help             Show this help message and exit\n"
@@ -81,45 +82,10 @@ guessApi(const char *filename)
     return trace::API_UNKNOWN;
 }
 
-static int
-command(int argc, char *argv[])
-{
-    bool wait = false;
-    const char *traceName;
-
-    int opt;
-    while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
-        switch (opt) {
-        case 'h':
-            usage();
-            return 0;
-        case 'w':
-            wait = true;
-            break;
-        default:
-            std::cerr << "error: unexpected option `" << opt << "`\n";
-            usage();
-            return 1;
-        }
-    }
-
-    if (optind >= argc) {
-        std::cerr << "error: apitrace retrace requires a trace file as an argument.\n";
-        usage();
-        return 1;
-    }
-
-    if (optind < argc - 1) { 
-        std::cerr << "error: apitrace retrace can accept only a single trace file argument.\n";
-        usage();
-        return 1;
-    }
-
-    traceName = argv[optind];
-
-    trace::API api = guessApi(traceName);
-
-    std::vector<const char *> command;
+int
+executeRetrace(const std::vector<const char *> & opts,
+               const char *traceName,
+               trace::API api) {
     const char *retraceName;
     switch (api) {
     case trace::API_GL:
@@ -144,16 +110,15 @@ command(int argc, char *argv[])
         break;
     }
 
+    std::vector<const char *> command;
     os::String retracePath = trace::findProgram(retraceName);
-    if (retracePath) {
+    if (retracePath.length()) {
         command.push_back(retracePath);
     } else {
         command.push_back(retraceName);
     }
 
-    if (wait) {
-        command.push_back("--wait");
-    }
+    command.insert(command.end(), opts.begin(), opts.end());
 
     command.push_back(traceName);
     command.push_back(NULL);
@@ -161,6 +126,53 @@ command(int argc, char *argv[])
     return os::execute((char * const *)&command[0]);
 }
 
+int
+executeRetrace(const std::vector<const char *> & opts,
+               const char *traceName) {
+    trace::API api = guessApi(traceName);
+    return executeRetrace(opts, traceName, api);
+}
+
+static int
+command(int argc, char *argv[])
+{
+    std::vector<const char *> opts;
+
+    const char *traceName;
+
+    int opt;
+    while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
+        switch (opt) {
+        case 'h':
+            usage();
+            return 0;
+        case 'w':
+            opts.push_back("--wait");
+            break;
+        default:
+            std::cerr << "error: unexpected option `" << opt << "`\n";
+            usage();
+            return 1;
+        }
+    }
+
+    if (optind >= argc) {
+        std::cerr << "error: apitrace retrace requires a trace file as an argument.\n";
+        usage();
+        return 1;
+    }
+
+    if (optind < argc - 1) { 
+        std::cerr << "error: apitrace retrace can accept only a single trace file argument.\n";
+        usage();
+        return 1;
+    }
+
+    traceName = argv[optind];
+
+    return executeRetrace(opts, traceName);
+}
+
 const Command retrace_command = {
     "retrace",
     synopsis,
diff --git a/cli/cli_retrace.hpp b/cli/cli_retrace.hpp
new file mode 100644 (file)
index 0000000..0dfa823
--- /dev/null
@@ -0,0 +1,46 @@
+/*********************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ *********************************************************************/
+
+#ifndef _CLI_RETRACE_HPP_
+#define _CLI_RETRACE_HPP_
+
+
+#include <vector>
+#include "trace_api.hpp"
+
+
+int
+executeRetrace(const std::vector<const char *> & opts,
+               const char *traceName,
+               trace::API api);
+
+int
+executeRetrace(const std::vector<const char *> & opts,
+               const char *traceName);
+
+
+#endif /* _CLI_RETRACE_HPP_ */