1 /*********************************************************************
3 * Copyright 2011 Jose Fonseca
4 * Copyright 2012 Intel Corporation
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy,
11 * modify, merge, publish, distribute, sublicense, and/or sell copies
12 * of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 *********************************************************************/
30 #include <limits.h> // for CHAR_MAX
34 #include "os_string.hpp"
35 #include "os_process.hpp"
37 #include "trace_parser.hpp"
38 #include "cli_resources.hpp"
41 #include "cli_retrace.hpp"
45 guessApi(const char *filename)
48 if (!p.open(filename)) {
49 return trace::API_UNKNOWN;
52 while ((call = p.parse_call())) {
55 if (p.api != trace::API_UNKNOWN) {
60 return trace::API_UNKNOWN;
64 executeRetrace(const std::vector<const char *> & opts,
65 const char *traceName,
67 const char *retraceName;
70 retraceName = "glretrace";
73 retraceName = "eglretrace";
80 // Use prefix so that it can be used with WINE
81 retraceName = "d3dretrace.exe";
84 std::cerr << "warning: could not guess trace's API\n";
85 retraceName = "glretrace";
89 std::vector<const char *> command;
90 os::String retracePath = findProgram(retraceName);
91 if (retracePath.length()) {
92 command.push_back(retracePath);
94 command.push_back(retraceName);
97 command.insert(command.end(), opts.begin(), opts.end());
100 command.push_back(traceName);
102 command.push_back(NULL);
104 return os::execute((char * const *)&command[0]);
108 executeRetrace(const std::vector<const char *> & opts,
109 const char *traceName) {
110 trace::API api = guessApi(traceName);
111 return executeRetrace(opts, traceName, api);
115 static const char *synopsis = "Replay a trace.";
120 std::vector<const char *>opts;
121 opts.push_back("--help");
122 trace::API api = trace::API_GL;
123 executeRetrace(opts, NULL, api);
127 command(int argc, char *argv[])
129 std::vector<const char *> opts;
130 for (int i = 1; i < argc; ++i) {
131 opts.push_back(argv[i]);
134 trace::API api = trace::API_GL;
136 const char *lastArg = argv[argc -1];
137 if (lastArg[0] != '-') {
138 api = guessApi(lastArg);
142 return executeRetrace(opts, NULL, api);
145 const Command retrace_command = {