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 (gl or egl);\n"
56 " -o, --output=TRACE specify output trace file;\n"
57 " default is `PROGRAM.trace`\n";
61 shortOptions = "+hva:o:";
63 const static struct option
65 {"help", no_argument, 0, 'h'},
66 {"verbose", no_argument, 0, 'v'},
67 {"api", required_argument, 0, 'a'},
68 {"output", required_argument, 0, 'o'},
73 command(int argc, char *argv[])
76 trace::API api = trace::API_GL;
77 const char *output = NULL;
80 while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
89 if (strcmp(optarg, "gl") == 0) {
91 } else if (strcmp(optarg, "egl") == 0) {
94 std::cerr << "error: unknown API `" << optarg << "`\n";
103 std::cerr << "error: unexpected option `" << opt << "`\n";
109 if (optind == argc) {
110 std::cerr << "error: no command specified\n";
115 assert(argv[argc] == 0);
116 return trace::traceProgram(api, argv + optind, output, verbose);
119 const Command trace_command = {