summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Fonseca <jose.r.fonseca@gmail.com>2012-11-21 08:58:42 +0000
committerJosé Fonseca <jose.r.fonseca@gmail.com>2012-11-21 08:58:42 +0000
commitd7a4487ca3354de7603dee23eb0892b8467a6464 (patch)
tree2e7aad092a4a033eee1ac9c08f6a58b1fd40441c
parentdf8c819e1e00ee89b2c62f81e5c97ffe919f17b8 (diff)
cli: Auto-detect retrace for dump-images too.
-rw-r--r--README.markdown4
-rw-r--r--cli/cli_dump_images.cpp33
-rw-r--r--cli/cli_retrace.cpp104
-rw-r--r--cli/cli_retrace.hpp46
4 files changed, 121 insertions, 66 deletions
diff --git a/README.markdown b/README.markdown
index eb0945b5..4e596cc1 100644
--- a/README.markdown
+++ b/README.markdown
@@ -373,7 +373,7 @@ These are the steps to create a regression test-suite around **apitrace**:
* obtain reference snapshots, by doing on a reference system:
mkdir /path/to/reference/snapshots/
- glretrace -s /path/to/reference/snapshots/ application.trace
+ apitrace dump-images -o /path/to/reference/snapshots/ application.trace
* prune the snapshots which are not interesting
@@ -383,7 +383,7 @@ These are the steps to create a regression test-suite around **apitrace**:
Alternatively, for a HTML summary, use `apitrace diff-images`:
- glretrace -s /path/to/test/snapshots/ application.trace
+ apitrace dump-images -o /path/to/test/snapshots/ application.trace
apitrace diff-images --output summary.html /path/to/reference/snapshots/ /path/to/test/snapshots/
diff --git a/cli/cli_dump_images.cpp b/cli/cli_dump_images.cpp
index 594f001e..0e2dd8c8 100644
--- a/cli/cli_dump_images.cpp
+++ b/cli/cli_dump_images.cpp
@@ -31,12 +31,10 @@
#include <getopt.h>
#include <iostream>
-#include "cli.hpp"
-
#include "os_string.hpp"
-#include "os_process.hpp"
-#include "trace_resource.hpp"
+#include "cli.hpp"
+#include "cli_retrace.hpp"
static const char *synopsis = "Dump frame images obtained from a trace.";
@@ -74,7 +72,9 @@ static int
command(int argc, char *argv[])
{
os::String prefix;
- const char *calls, *filename, *output = NULL;
+ const char *calls = NULL;
+ const char *traceName = NULL;
+ const char *output = NULL;
int opt;
while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
@@ -107,30 +107,27 @@ command(int argc, char *argv[])
return 1;
}
- filename = argv[optind];
+ traceName = argv[optind];
if (output == NULL) {
- prefix = filename;
+ prefix = traceName;
prefix.trimDirectory();
prefix.trimExtension();
+ prefix.append('.');
output = prefix.str();
}
- std::vector<const char *> command;
+ std::vector<const char *> opts;
- os::String glretracePath = trace::findProgram("glretrace");
- command.push_back(glretracePath);
- command.push_back("-s");
- command.push_back(output);
- command.push_back("-S");
+ opts.push_back("-s");
+ opts.push_back(output);
+ opts.push_back("-S");
if (calls)
- command.push_back(calls);
+ opts.push_back(calls);
else
- command.push_back("*/frame");
- command.push_back(filename);
- command.push_back(NULL);
+ opts.push_back("*/frame");
- return os::execute((char * const *)&command[0]);
+ return executeRetrace(opts, traceName);
}
const Command dump_images_command = {
diff --git a/cli/cli_retrace.cpp b/cli/cli_retrace.cpp
index de5eb6b9..cf9ffdf5 100644
--- a/cli/cli_retrace.cpp
+++ b/cli/cli_retrace.cpp
@@ -31,20 +31,21 @@
#include <getopt.h>
#include <iostream>
-#include "cli.hpp"
-
#include "os_string.hpp"
#include "os_process.hpp"
#include "trace_parser.hpp"
#include "trace_resource.hpp"
+#include "cli.hpp"
+#include "cli_retrace.hpp"
+
static const char *synopsis = "Replay a trace.";
static void
usage(void)
{
- std::cout << "usage apitrace retrace [OPTIONS] TRACE_FILE\n"
+ std::cout << "usage: apitrace retrace [OPTIONS] TRACE_FILE\n"
<< synopsis << "\n"
"\n"
" -h, --help Show this help message and exit\n"
@@ -81,45 +82,10 @@ guessApi(const char *filename)
return trace::API_UNKNOWN;
}
-static int
-command(int argc, char *argv[])
-{
- bool wait = false;
- const char *traceName;
-
- int opt;
- while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
- switch (opt) {
- case 'h':
- usage();
- return 0;
- case 'w':
- wait = true;
- break;
- default:
- std::cerr << "error: unexpected option `" << opt << "`\n";
- usage();
- return 1;
- }
- }
-
- if (optind >= argc) {
- std::cerr << "error: apitrace retrace requires a trace file as an argument.\n";
- usage();
- return 1;
- }
-
- if (optind < argc - 1) {
- std::cerr << "error: apitrace retrace can accept only a single trace file argument.\n";
- usage();
- return 1;
- }
-
- traceName = argv[optind];
-
- trace::API api = guessApi(traceName);
-
- std::vector<const char *> command;
+int
+executeRetrace(const std::vector<const char *> & opts,
+ const char *traceName,
+ trace::API api) {
const char *retraceName;
switch (api) {
case trace::API_GL:
@@ -144,16 +110,15 @@ command(int argc, char *argv[])
break;
}
+ std::vector<const char *> command;
os::String retracePath = trace::findProgram(retraceName);
- if (retracePath) {
+ if (retracePath.length()) {
command.push_back(retracePath);
} else {
command.push_back(retraceName);
}
- if (wait) {
- command.push_back("--wait");
- }
+ command.insert(command.end(), opts.begin(), opts.end());
command.push_back(traceName);
command.push_back(NULL);
@@ -161,6 +126,53 @@ command(int argc, char *argv[])
return os::execute((char * const *)&command[0]);
}
+int
+executeRetrace(const std::vector<const char *> & opts,
+ const char *traceName) {
+ trace::API api = guessApi(traceName);
+ return executeRetrace(opts, traceName, api);
+}
+
+static int
+command(int argc, char *argv[])
+{
+ std::vector<const char *> opts;
+
+ const char *traceName;
+
+ int opt;
+ while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
+ switch (opt) {
+ case 'h':
+ usage();
+ return 0;
+ case 'w':
+ opts.push_back("--wait");
+ break;
+ default:
+ std::cerr << "error: unexpected option `" << opt << "`\n";
+ usage();
+ return 1;
+ }
+ }
+
+ if (optind >= argc) {
+ std::cerr << "error: apitrace retrace requires a trace file as an argument.\n";
+ usage();
+ return 1;
+ }
+
+ if (optind < argc - 1) {
+ std::cerr << "error: apitrace retrace can accept only a single trace file argument.\n";
+ usage();
+ return 1;
+ }
+
+ traceName = argv[optind];
+
+ return executeRetrace(opts, traceName);
+}
+
const Command retrace_command = {
"retrace",
synopsis,
diff --git a/cli/cli_retrace.hpp b/cli/cli_retrace.hpp
new file mode 100644
index 00000000..0dfa823e
--- /dev/null
+++ b/cli/cli_retrace.hpp
@@ -0,0 +1,46 @@
+/*********************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * 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.
+ *
+ *********************************************************************/
+
+#ifndef _CLI_RETRACE_HPP_
+#define _CLI_RETRACE_HPP_
+
+
+#include <vector>
+#include "trace_api.hpp"
+
+
+int
+executeRetrace(const std::vector<const char *> & opts,
+ const char *traceName,
+ trace::API api);
+
+int
+executeRetrace(const std::vector<const char *> & opts,
+ const char *traceName);
+
+
+#endif /* _CLI_RETRACE_HPP_ */