1 /*********************************************************************
3 * Copyright 2011 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 *********************************************************************/
37 #include "trace_tools.hpp"
40 static const char *synopsis = "Generate a new trace by executing the given program.";
45 std::cout << "usage: apitrace trace [OPTIONS] PROGRAM [ARGS ...]\n"
48 " The given program will be executed with the given arguments.\n"
49 " During execution, all OpenGL calls will be captured to a trace\n"
50 " file. That trace file can then be used\n"
51 " with other apitrace utilities for replay or analysis.\n"
53 " -v, --verbose verbose output\n"
54 " -a, --api=API specify API to trace ("
56 "gl, d3d7, d3d8, d3d9, or d3d10"
62 " -o, --output=TRACE specify output trace file;\n"
63 " default is `PROGRAM.trace`\n";
67 shortOptions = "+hva:o:";
69 const static struct option
71 {"help", no_argument, 0, 'h'},
72 {"verbose", no_argument, 0, 'v'},
73 {"api", required_argument, 0, 'a'},
74 {"output", required_argument, 0, 'o'},
79 command(int argc, char *argv[])
82 trace::API api = trace::API_GL;
83 const char *output = NULL;
86 while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
95 if (strcmp(optarg, "gl") == 0) {
97 } else if (strcmp(optarg, "egl") == 0) {
99 } else if (strcmp(optarg, "d3d7") == 0) {
100 api = trace::API_D3D7;
101 } else if (strcmp(optarg, "d3d8") == 0) {
102 api = trace::API_D3D8;
103 } else if (strcmp(optarg, "d3d9") == 0) {
104 api = trace::API_D3D9;
105 } else if (strcmp(optarg, "d3d10") == 0) {
106 api = trace::API_D3D10;
107 } else if (strcmp(optarg, "d3d10_1") == 0) {
108 api = trace::API_D3D10_1;
109 } else if (strcmp(optarg, "d3d11") == 0) {
110 api = trace::API_D3D11;
112 std::cerr << "error: unknown API `" << optarg << "`\n";
121 std::cerr << "error: unexpected option `" << opt << "`\n";
127 if (optind == argc) {
128 std::cerr << "error: no command specified\n";
133 assert(argv[argc] == 0);
134 return trace::traceProgram(api, argv + optind, output, verbose);
137 const Command trace_command = {