1 /**************************************************************************
3 * Copyright 2011 Jose Fonseca
4 * Copyright 2010 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies 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 included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
31 #include "cli_pager.hpp"
33 #include "trace_parser.hpp"
34 #include "trace_dump.hpp"
38 COLOR_OPTION_NEVER = 0,
39 COLOR_OPTION_ALWAYS = 1,
40 COLOR_OPTION_AUTO = -1
43 static ColorOption color = COLOR_OPTION_AUTO;
45 static bool verbose = false;
47 static const char *synopsis = "Dump given trace(s) to standard output.";
53 << "usage: apitrace dump [OPTIONS] <trace-file>...\n"
56 " -v, --verbose verbose output\n"
58 " --colour=<WHEN> Colored syntax highlighting\n"
59 " WHEN is 'auto', 'always', or 'never'\n"
60 " --no-arg-names Don't dump argument names\n"
61 " --thread-ids Dump thread ids\n"
66 command(int argc, char *argv[])
68 trace::DumpFlags dumpFlags = 0;
69 bool dumpThreadIds = false;
73 for (i = 0; i < argc; ++i) {
74 const char *arg = argv[i];
80 if (!strcmp(arg, "--")) {
82 } else if (!strcmp(arg, "--help")) {
85 } else if (strcmp(arg, "-v") == 0 ||
86 strcmp(arg, "--verbose") == 0) {
88 } else if (!strcmp(arg, "--color=auto") ||
89 !strcmp(arg, "--colour=auto")) {
90 color = COLOR_OPTION_AUTO;
91 } else if (!strcmp(arg, "--color") ||
92 !strcmp(arg, "--colour") ||
93 !strcmp(arg, "--color=always") ||
94 !strcmp(arg, "--colour=always")) {
95 color = COLOR_OPTION_ALWAYS;
96 } else if (!strcmp(arg, "--color=never") ||
97 !strcmp(arg, "--colour=never") ||
98 !strcmp(arg, "--no-color") ||
99 !strcmp(arg, "--no-colour")) {
100 color = COLOR_OPTION_NEVER;
101 } else if (!strcmp(arg, "--no-arg-names")) {
102 dumpFlags |= trace::DUMP_FLAG_NO_ARG_NAMES;
103 } else if (!strcmp(arg, "--thread-ids")) {
104 dumpThreadIds = true;
106 std::cerr << "error: unknown option " << arg << "\n";
112 if (color == COLOR_OPTION_AUTO) {
114 color = COLOR_OPTION_ALWAYS;
116 color = isatty(1) ? COLOR_OPTION_ALWAYS : COLOR_OPTION_NEVER;
121 if (color == COLOR_OPTION_NEVER) {
122 dumpFlags |= trace::DUMP_FLAG_NO_COLOR;
125 for (; i < argc; ++i) {
128 if (!p.open(argv[i])) {
129 std::cerr << "error: failed to open " << argv[i] << "\n";
134 while ((call = p.parse_call())) {
136 !(call->flags & trace::CALL_FLAG_VERBOSE)) {
138 std::cout << std::hex << call->thread_id << std::dec << " ";
140 trace::dump(*call, std::cout, dumpFlags);
149 const Command dump_command = {