From 32420d2167c14c4c00d351e8807031b64bce06ef Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 4 Nov 2011 15:45:09 -0700 Subject: [PATCH] cli: Add a new "apitrace diff" command. This command simply provides a more consistent way of getting access to the existing tracediff.sh command, (which is now installed to /lib/apitrace/scripts for the "apitrace diff" command to invoke, but not necessarily for users to invoke directly). --- CMakeLists.txt | 5 ++ TODO.markdown | 1 - cli/CMakeLists.txt | 1 + cli/cli.hpp | 1 + cli/cli_diff.cpp | 112 +++++++++++++++++++++++++++++++++++++++++++ cli/cli_main.cpp | 1 + scripts/tracediff.sh | 2 +- 7 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 cli/cli_diff.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9721cdc..39797a8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/TODO.markdown b/TODO.markdown index e523b01..c3afde7 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 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 diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index fc52527..89bd054 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable (apitrace cli_main.cpp + cli_diff.cpp cli_dump.cpp cli_trace.cpp ) diff --git a/cli/cli.hpp b/cli/cli.hpp index 9ab1600..0f3746b 100644 --- a/cli/cli.hpp +++ b/cli/cli.hpp @@ -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 index 0000000..a06e842 --- /dev/null +++ b/cli/cli_diff.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 traces."; + +static void +usage(void) +{ + std::cout + << "usage: apitrace diff \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 +}; diff --git a/cli/cli_main.cpp b/cli/cli_main.cpp index a3abf54..421748c 100644 --- a/cli/cli_main.cpp +++ b/cli/cli_main.cpp @@ -66,6 +66,7 @@ const Command help_command = { }; static const Command * commands[] = { + &diff_command, &dump_command, &trace_command, &help_command diff --git a/scripts/tracediff.sh b/scripts/tracediff.sh index b3b9220..57d59f8 100755 --- a/scripts/tracediff.sh +++ b/scripts/tracediff.sh @@ -26,7 +26,7 @@ set -e -APITRACE=${APITRACE:-`dirname "$0"`/../apitrace} +APITRACE=${APITRACE:-apitrace} $APITRACE dump -- 2.43.0