]> git.cworth.org Git - apitrace/commitdiff
Add new "apitrace diff-state" command
authorCarl Worth <cworth@cworth.org>
Sat, 5 Nov 2011 00:04:15 +0000 (17:04 -0700)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 6 Nov 2011 09:02:42 +0000 (09:02 +0000)
Which is simply a convenient way to invoke the existing jsondiff.py script,
(which is now installed by "make install" to support this command).

CMakeLists.txt
TODO.markdown
cli/CMakeLists.txt
cli/cli.hpp
cli/cli_diff_state.cpp [new file with mode: 0644]
cli/cli_main.cpp

index 39797a85e2a9ed8654375a1b48d0476ee86e902c..72b35c21f8bb148985f76b6b827cfd1c8026e25a 100755 (executable)
@@ -490,6 +490,7 @@ add_subdirectory(cli)
 # Scripts (to support the CLI)
 
 install (PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/tracediff.sh DESTINATION ${LIB_INSTALL_DIR}/scripts)
+install (PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/jsondiff.py DESTINATION ${LIB_INSTALL_DIR}/scripts)
 
 ##############################################################################
 # GUI
index c3afde725ebe73c9c8d0442b5357e2b4600fe974..5830680b9adb5e86827a807bdcf0740134e4c8ef 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-state  Identify differences between a state dump and another trace
 * Add diff-images Identify differences between images and another trace
 
 * Add some common command-line options:
index 89bd0540d84c06e6614c1e45653c282e04b036f5..36a9d2620969296f9d99374311c9a059f61ea1f0 100644 (file)
@@ -1,6 +1,7 @@
 add_executable (apitrace
     cli_main.cpp
     cli_diff.cpp
+    cli_diff_state.cpp
     cli_dump.cpp
     cli_trace.cpp
 )
index 0f3746bc6c8e843404ec1c7146a02c23ed1c8bf6..edada5141b4e617c10a96bf65d54d4c5577097bd 100644 (file)
@@ -41,6 +41,7 @@ struct Command {
 };
 
 extern const Command diff_command;
+extern const Command diff_state_command;
 extern const Command dump_command;
 extern const Command trace_command;
 
diff --git a/cli/cli_diff_state.cpp b/cli/cli_diff_state.cpp
new file mode 100644 (file)
index 0000000..e58bd1d
--- /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 state dumps.";
+
+static void
+usage(void)
+{
+    std::cout
+        << "usage: apitrace diff-state <state-1> <state-2>\n"
+        << synopsis << "\n"
+        "\n"
+        "    Both input files should be the result of running 'glretrace -D XYZ <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-state requires exactly two state-dump files as arguments.\n";
+        usage();
+        return 1;
+    }
+
+    char *file1, *file2;
+
+    file1 = argv[i];
+    file2 = argv[i+1];
+
+#define CLI_DIFF_STATE_COMMAND "jsondiff.py"
+
+    os::Path command = trace::findFile("scripts/" CLI_DIFF_STATE_COMMAND,
+                 APITRACE_SCRIPTS_INSTALL_DIR "/" CLI_DIFF_STATE_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-state' 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_state_command = {
+    "diff-state",
+    synopsis,
+    usage,
+    command
+};
index 421748ca171fab39f67e19b18eca89cdfababfca..d996abd67c374cb9da95abe28babd39e1eb9b409 100644 (file)
@@ -67,6 +67,7 @@ const Command help_command = {
 
 static const Command * commands[] = {
     &diff_command,
+    &diff_state_command,
     &dump_command,
     &trace_command,
     &help_command