blob: f88d7dfc59591f9ff23d64453f7030e812d787b5 [file] [log] [blame]
Carl Worthda96cbf2012-08-20 09:45:27 -07001/*********************************************************************
2 *
3 * Copyright 2011 Jose Fonseca
4 * Copyright 2012 Intel Corporation
5 * All Rights Reserved.
6 *
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:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
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
25 * SOFTWARE.
26 *
27 *********************************************************************/
28
29#include <string.h>
30#include <limits.h> // for CHAR_MAX
31#include <getopt.h>
32#include <iostream>
33
34#include "cli.hpp"
35
36#include "os_string.hpp"
37#include "os_process.hpp"
38
39#include "trace_resource.hpp"
40
41static const char *synopsis = "Replay a trace.";
42
43static void
44usage(void)
45{
José Fonseca3320d022012-11-18 15:45:27 +000046 std::cout << "usage apitrace retrace [OPTIONS] TRACE_FILE\n"
Carl Worthda96cbf2012-08-20 09:45:27 -070047 << synopsis << "\n"
48 "\n"
49 " -h, --help Show this help message and exit\n"
50 " -w, --wait Wait for user termination after the last frame\n"
51 "\n";
52}
53
54const static char *
55shortOptions = "hw";
56
57const static struct option
58longOptions[] = {
59 {"help", no_argument, 0, 'h'},
60 {"wait", required_argument, 0, 'w'},
61 {0, 0, 0, 0}
62};
63
64static int
65command(int argc, char *argv[])
66{
67 bool wait = false;
68 const char *filename;
69
70 int opt;
71 while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
72 switch (opt) {
73 case 'h':
74 usage();
75 return 0;
76 case 'w':
77 wait = true;
78 break;
79 default:
80 std::cerr << "error: unexpected option `" << opt << "`\n";
81 usage();
82 return 1;
83 }
84 }
85
86 if (optind >= argc) {
José Fonseca3320d022012-11-18 15:45:27 +000087 std::cerr << "error: apitrace retrace requires a trace file as an argument.\n";
Carl Worthda96cbf2012-08-20 09:45:27 -070088 usage();
89 return 1;
90 }
91
92 if (optind < argc - 1) {
José Fonseca3320d022012-11-18 15:45:27 +000093 std::cerr << "error: apitrace retrace can accept only a single trace file argument.\n";
Carl Worthda96cbf2012-08-20 09:45:27 -070094 usage();
95 return 1;
96 }
97
98 filename = argv[optind];
99
Carl Worthda96cbf2012-08-20 09:45:27 -0700100 std::vector<const char *> command;
101
102 os::String glretracePath = trace::findProgram("glretrace");
103 command.push_back(glretracePath);
104
105 if (wait) {
106 command.push_back("--wait");
107 }
108
109 command.push_back(filename);
110 command.push_back(NULL);
111
112 return os::execute((char * const *)&command[0]);
113}
114
José Fonseca3320d022012-11-18 15:45:27 +0000115const Command retrace_command = {
116 "retrace",
Carl Worthda96cbf2012-08-20 09:45:27 -0700117 synopsis,
118 usage,
119 command
120};