]> git.cworth.org Git - apitrace/commitdiff
cli: Add a new "apitrace diff" command.
authorCarl Worth <cworth@cworth.org>
Fri, 4 Nov 2011 22:45:09 +0000 (15:45 -0700)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 6 Nov 2011 08:36:52 +0000 (08:36 +0000)
This command simply provides a more consistent way of getting access
to the existing tracediff.sh command, (which is now installed to
<prefix>/lib/apitrace/scripts for the "apitrace diff" command to
invoke, but not necessarily for users to invoke directly).

CMakeLists.txt
TODO.markdown
cli/CMakeLists.txt
cli/cli.hpp
cli/cli_diff.cpp [new file with mode: 0644]
cli/cli_main.cpp
scripts/tracediff.sh

index 9721cdc3e6c653a7f2ae0ea7de203c43522b6fde..39797a85e2a9ed8654375a1b48d0476ee86e902c 100755 (executable)
@@ -486,6 +486,11 @@ install (TARGETS glretrace RUNTIME DESTINATION bin)
 
 add_subdirectory(cli)
 
+##############################################################################
+# Scripts (to support the CLI)
+
+install (PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/tracediff.sh DESTINATION ${LIB_INSTALL_DIR}/scripts)
+
 ##############################################################################
 # GUI
 
index e523b01b94b491211c4e80a13f5b7edc801191d8..c3afde725ebe73c9c8d0442b5357e2b4600fe974 100644 (file)
@@ -63,7 +63,6 @@ CLI
 * Add trim        Trim a trace by including only the specified calls/frames
 * Add dump-state  Output the OpenGL state in JSON format
 * Add dump-images Create image files for each frame/drawing operation of a trace
-* Add diff        Identify differences between a trace dump and another trace
 * Add diff-state  Identify differences between a state dump and another trace
 * Add diff-images Identify differences between images and another trace
 
index fc52527dfc91996a5a48a607edba38907a336a1a..89bd0540d84c06e6614c1e45653c282e04b036f5 100644 (file)
@@ -1,5 +1,6 @@
 add_executable (apitrace
     cli_main.cpp
+    cli_diff.cpp
     cli_dump.cpp
     cli_trace.cpp
 )
index 9ab160026e04d99b6f6d3df5807b7200d36dc942..0f3746bc6c8e843404ec1c7146a02c23ed1c8bf6 100644 (file)
@@ -40,6 +40,7 @@ struct Command {
     Function function;
 };
 
+extern const Command diff_command;
 extern const Command dump_command;
 extern const Command trace_command;
 
diff --git a/cli/cli_diff.cpp b/cli/cli_diff.cpp
new file mode 100644 (file)
index 0000000..a06e842
--- /dev/null
@@ -0,0 +1,112 @@
+/*********************************************************************
+ *
+ * Copyright 2011 Intel Corporation
+ * 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.
+ *
+ *********************************************************************/
+
+#include <string.h>
+#include <iostream>
+
+#include "cli.hpp"
+#include "os_path.hpp"
+#include "trace_tools.hpp"
+
+static const char *synopsis = "Identify differences between two traces.";
+
+static void
+usage(void)
+{
+    std::cout
+        << "usage: apitrace diff <trace-1> <trace-2>\n"
+        << synopsis << "\n"
+        "\n"
+        "    Both input files should be the result of running 'apitrace trace'.\n";
+}
+
+static int
+command(int argc, char *argv[])
+{
+    int i;
+
+    for (i = 0; i < argc; ++i) {
+        const char *arg = argv[i];
+
+        if (arg[0] != '-') {
+            break;
+        }
+
+        if (!strcmp(arg, "--")) {
+            i++;
+            break;
+        } else if (!strcmp(arg, "--help")) {
+            usage();
+            return 0;
+        } else {
+            std::cerr << "error: unknown option " << arg << "\n";
+            usage();
+            return 1;
+        }
+    }
+
+    if (argc - i != 2) {
+        std::cerr << "Error: diff requires exactly two trace files as arguments.\n";
+        usage();
+        return 1;
+    }
+
+    char *file1, *file2;
+
+    file1 = argv[i];
+    file2 = argv[i+1];
+
+#define CLI_DIFF_TRACEDIFF_COMMAND "tracediff.sh"
+
+    os::Path command = trace::findFile("scripts/" CLI_DIFF_TRACEDIFF_COMMAND,
+                 APITRACE_SCRIPTS_INSTALL_DIR "/" CLI_DIFF_TRACEDIFF_COMMAND,
+                                       true);
+
+    char* args[4];
+
+    args[0] = (char *) command.str();
+    args[1] = file1;
+    args[2] = file2;
+    args[3] = NULL;
+
+#ifdef _WIN32
+    std::cerr << "The 'apitrace diff' command is not yet supported on this O/S.\n";
+#else
+    execv(command.str(), args);
+#endif
+
+    std::cerr << "Error: Failed to execute " << argv[0] << "\n";
+
+    return 1;
+}
+
+const Command diff_command = {
+    "diff",
+    synopsis,
+    usage,
+    command
+};
index a3abf54a0d6daab8aee1a5e09c71d6af6bdfeb48..421748ca171fab39f67e19b18eca89cdfababfca 100644 (file)
@@ -66,6 +66,7 @@ const Command help_command = {
 };
 
 static const Command * commands[] = {
+    &diff_command,
     &dump_command,
     &trace_command,
     &help_command
index b3b9220f86c80c1aa3283da2212fa7fb85264eb0..57d59f890840b7db2b6e51ccff3ef4dbc22cd65c 100755 (executable)
@@ -26,7 +26,7 @@
 
 set -e
 
-APITRACE=${APITRACE:-`dirname "$0"`/../apitrace}
+APITRACE=${APITRACE:-apitrace}
 
 $APITRACE dump