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"
35 #include "trace_callset.hpp"
39 COLOR_OPTION_NEVER = 0,
40 COLOR_OPTION_ALWAYS = 1,
41 COLOR_OPTION_AUTO = -1
44 static ColorOption color = COLOR_OPTION_AUTO;
46 static bool verbose = false;
48 static trace::CallSet calls(trace::FREQUENCY_ALL);
50 static const char *synopsis = "Dump given trace(s) to standard output.";
56 << "usage: apitrace dump [OPTIONS] <trace-file>...\n"
59 " -v, --verbose verbose output\n"
60 " --calls <CALLSET> Only dump specified calls\n"
62 " --colour=<WHEN> Colored syntax highlighting\n"
63 " WHEN is 'auto', 'always', or 'never'\n"
64 " --no-arg-names Don't dump argument names\n"
65 " --thread-ids Dump thread ids\n"
70 command(int argc, char *argv[])
72 trace::DumpFlags dumpFlags = 0;
73 bool dumpThreadIds = false;
77 for (i = 0; i < argc;) {
78 const char *arg = argv[i];
86 if (!strcmp(arg, "--")) {
88 } else if (!strcmp(arg, "--help")) {
91 } else if (strcmp(arg, "-v") == 0 ||
92 strcmp(arg, "--verbose") == 0) {
94 } else if (!strcmp(arg, "--calls")) {
95 calls = trace::CallSet(argv[i++]);
96 } else if (!strcmp(arg, "--color=auto") ||
97 !strcmp(arg, "--colour=auto")) {
98 color = COLOR_OPTION_AUTO;
99 } else if (!strcmp(arg, "--color") ||
100 !strcmp(arg, "--colour") ||
101 !strcmp(arg, "--color=always") ||
102 !strcmp(arg, "--colour=always")) {
103 color = COLOR_OPTION_ALWAYS;
104 } else if (!strcmp(arg, "--color=never") ||
105 !strcmp(arg, "--colour=never") ||
106 !strcmp(arg, "--no-color") ||
107 !strcmp(arg, "--no-colour")) {
108 color = COLOR_OPTION_NEVER;
109 } else if (!strcmp(arg, "--no-arg-names")) {
110 dumpFlags |= trace::DUMP_FLAG_NO_ARG_NAMES;
111 } else if (!strcmp(arg, "--thread-ids")) {
112 dumpThreadIds = true;
114 std::cerr << "error: unknown option " << arg << "\n";
120 if (color == COLOR_OPTION_AUTO) {
122 color = COLOR_OPTION_ALWAYS;
124 color = isatty(1) ? COLOR_OPTION_ALWAYS : COLOR_OPTION_NEVER;
129 if (color == COLOR_OPTION_NEVER) {
130 dumpFlags |= trace::DUMP_FLAG_NO_COLOR;
133 for (; i < argc; ++i) {
136 if (!p.open(argv[i])) {
137 std::cerr << "error: failed to open " << argv[i] << "\n";
142 while ((call = p.parse_call())) {
143 if (calls.contains(*call)) {
145 !(call->flags & trace::CALL_FLAG_VERBOSE)) {
147 std::cout << std::hex << call->thread_id << std::dec << " ";
149 trace::dump(*call, std::cout, dumpFlags);
159 const Command dump_command = {