1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
4 * Copyright 2011 Intel corporation
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 "os_string.hpp"
33 #include "trace_callset.hpp"
34 #include "trace_parser.hpp"
35 #include "trace_writer.hpp"
37 static const char *synopsis = "Create a new trace by trimming an existing trace.";
43 << "usage: apitrace trim [OPTIONS] <trace-file>...\n"
46 " --calls <CALLSET> Only trim specified calls\n"
47 " -o --output <TRACEFILE> Output trace file\n"
53 command(int argc, char *argv[])
56 trace::CallSet calls(trace::FREQUENCY_ALL);
59 for (i = 0; i < argc;) {
60 const char *arg = argv[i];
68 if (!strcmp(arg, "--")) {
70 } else if (!strcmp(arg, "--help")) {
73 } else if (!strcmp(arg, "--calls")) {
74 calls = trace::CallSet(argv[i++]);
75 } else if (!strcmp(arg, "-o") ||
76 !strcmp(arg, "--output")) {
79 std::cerr << "error: unknown option " << arg << "\n";
86 std::cerr << "Error: apitrace trim requires a trace file as an argument.\n";
91 for ( ; i < argc; ++i) {
93 if (!p.open(argv[i])) {
94 std::cerr << "error: failed to open " << argv[i] << "\n";
99 os::String base(argv[i]);
100 base.trimExtension();
102 output = std::string(base.str()) + std::string("-trim.trace");
105 trace::Writer writer;
106 if (!writer.open(output.c_str())) {
107 std::cerr << "error: failed to create " << argv[i] << "\n";
112 while ((call = p.parse_call())) {
113 if (calls.contains(*call)) {
114 writer.writeCall(call);
119 std::cout << "Trimmed trace is available as " << output << "\n";
125 const Command trim_command = {