From ca0c40fa6d5764b3f2ba7cafc7ba1c291e466005 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 4 Nov 2011 17:04:15 -0700 Subject: [PATCH] Add new "apitrace diff-state" command 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 | 1 + TODO.markdown | 1 - cli/CMakeLists.txt | 1 + cli/cli.hpp | 1 + cli/cli_diff_state.cpp | 112 +++++++++++++++++++++++++++++++++++++++++ cli/cli_main.cpp | 1 + 6 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 cli/cli_diff_state.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 39797a8..72b35c2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/TODO.markdown b/TODO.markdown index c3afde7..5830680 100644 --- a/TODO.markdown +++ b/TODO.markdown @@ -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: diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 89bd054..36a9d26 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -1,6 +1,7 @@ add_executable (apitrace cli_main.cpp cli_diff.cpp + cli_diff_state.cpp cli_dump.cpp cli_trace.cpp ) diff --git a/cli/cli.hpp b/cli/cli.hpp index 0f3746b..edada51 100644 --- a/cli/cli.hpp +++ b/cli/cli.hpp @@ -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 index 0000000..e58bd1d --- /dev/null +++ b/cli/cli_diff_state.cpp @@ -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 +#include + +#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 \n" + << synopsis << "\n" + "\n" + " Both input files should be the result of running 'glretrace -D XYZ '.\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 +}; diff --git a/cli/cli_main.cpp b/cli/cli_main.cpp index 421748c..d996abd 100644 --- a/cli/cli_main.cpp +++ b/cli/cli_main.cpp @@ -67,6 +67,7 @@ const Command help_command = { static const Command * commands[] = { &diff_command, + &diff_state_command, &dump_command, &trace_command, &help_command -- 2.43.0