diff options
author | Carl Worth <cworth@cworth.org> | 2011-11-04 17:04:15 -0700 |
---|---|---|
committer | José Fonseca <jose.r.fonseca@gmail.com> | 2011-11-06 09:02:42 +0000 |
commit | ca0c40fa6d5764b3f2ba7cafc7ba1c291e466005 (patch) | |
tree | 27843aa74f099a0cf59347cf28d134f05d50f77f /cli/cli_diff_state.cpp | |
parent | 73694fa14967ad586b5116c49665fb7884de68b8 (diff) |
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).
Diffstat (limited to 'cli/cli_diff_state.cpp')
-rw-r--r-- | cli/cli_diff_state.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/cli/cli_diff_state.cpp b/cli/cli_diff_state.cpp new file mode 100644 index 00000000..e58bd1d2 --- /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 <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 +}; |