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 "trace_resource.hpp"
41 #include "cli_retrace.hpp"
43 static const char *synopsis = "Replay a trace.";
48 std::cout << "usage: apitrace retrace [OPTIONS] TRACE_FILE\n"
51 " -h, --help Show this help message and exit\n"
52 " -w, --wait Wait for user termination after the last frame\n"
59 const static struct option
61 {"help", no_argument, 0, 'h'},
62 {"wait", required_argument, 0, 'w'},
67 guessApi(const char *filename)
70 if (!p.open(filename)) {
71 return trace::API_UNKNOWN;
74 while ((call = p.parse_call())) {
77 if (p.api != trace::API_UNKNOWN) {
82 return trace::API_UNKNOWN;
86 executeRetrace(const std::vector<const char *> & opts,
87 const char *traceName,
89 const char *retraceName;
92 retraceName = "glretrace";
95 retraceName = "eglretrace";
100 case trace::API_D3D9:
101 case trace::API_D3D10:
102 case trace::API_D3D10_1:
103 case trace::API_D3D11:
104 // Can be used with WINE
105 retraceName = "d3dretrace.exe";
108 std::cerr << "warning: could not guess trace's API\n";
109 retraceName = "glretrace";
113 std::vector<const char *> command;
114 os::String retracePath = trace::findProgram(retraceName);
115 if (retracePath.length()) {
116 command.push_back(retracePath);
118 command.push_back(retraceName);
121 command.insert(command.end(), opts.begin(), opts.end());
123 command.push_back(traceName);
124 command.push_back(NULL);
126 return os::execute((char * const *)&command[0]);
130 executeRetrace(const std::vector<const char *> & opts,
131 const char *traceName) {
132 trace::API api = guessApi(traceName);
133 return executeRetrace(opts, traceName, api);
137 command(int argc, char *argv[])
139 std::vector<const char *> opts;
141 const char *traceName;
144 while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
150 opts.push_back("--wait");
153 std::cerr << "error: unexpected option `" << opt << "`\n";
159 if (optind >= argc) {
160 std::cerr << "error: apitrace retrace requires a trace file as an argument.\n";
165 if (optind < argc - 1) {
166 std::cerr << "error: apitrace retrace can accept only a single trace file argument.\n";
171 traceName = argv[optind];
173 return executeRetrace(opts, traceName);
176 const Command retrace_command = {