blob: d7568449269d39f6820f17374628595b7ca18d71 [file] [log] [blame]
Carl Worth4c5f6fa2011-11-14 14:50:07 -08001/**************************************************************************
2 *
3 * Copyright 2010 VMware, Inc.
4 * Copyright 2011 Intel corporation
5 * All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
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
23 * THE SOFTWARE.
24 *
25 **************************************************************************/
26
Carl Worth33b92632012-08-14 14:11:19 -070027#include <sstream>
Carl Worth4c5f6fa2011-11-14 14:50:07 -080028#include <string.h>
José Fonsecab682b672012-02-15 07:13:31 +000029#include <limits.h> // for CHAR_MAX
30#include <getopt.h>
Carl Worth4c5f6fa2011-11-14 14:50:07 -080031
Carl Worth163b22c2012-08-10 10:15:30 -070032#include <set>
33
Carl Worth4c5f6fa2011-11-14 14:50:07 -080034#include "cli.hpp"
35
36#include "os_string.hpp"
37
Carl Worth8efbe012012-08-17 14:15:54 -070038#include "trace_analyzer.hpp"
José Fonsecad3c00132012-01-27 22:43:53 +000039#include "trace_callset.hpp"
Carl Worth4c5f6fa2011-11-14 14:50:07 -080040#include "trace_parser.hpp"
José Fonseca630471a2012-01-27 22:06:51 +000041#include "trace_writer.hpp"
Carl Worth4c5f6fa2011-11-14 14:50:07 -080042
43static const char *synopsis = "Create a new trace by trimming an existing trace.";
44
45static void
46usage(void)
47{
48 std::cout
José Fonsecab682b672012-02-15 07:13:31 +000049 << "usage: apitrace trim [OPTIONS] TRACE_FILE...\n"
José Fonsecad3c00132012-01-27 22:43:53 +000050 << synopsis << "\n"
51 "\n"
Carl Worth86464432012-08-11 11:46:54 -070052 " -h, --help Show detailed help for trim options and exit\n"
53 " --calls=CALLSET Include specified calls in the trimmed output.\n"
Carl Worth46abfd12012-08-14 22:32:29 -070054 " --frames=FRAMESET Include specified frames in the trimmed output.\n"
Carl Worth86464432012-08-11 11:46:54 -070055 " --deps Include additional calls to satisfy dependencies\n"
Carl Wortha0931fd2013-03-21 15:49:58 -070056 " --no-deps Do not include any more calls than requestd\n"
57 " --prune Omit calls without side effects from the output\n"
58 " --no-prune Do not omit any requested calls\n"
José Fonseca6e4768b2012-11-22 08:31:47 +000059 " -a, --auto Trim automatically to calls specified in --calls/--frames\n"
60 " Equivalent to both --deps and --prune\n"
Carl Wortha0931fd2013-03-21 15:49:58 -070061 " --exact Trim to exactly the calls specified in --calls/--frames\n"
62 " Equivalent to both --no-deps and --no-prune\n"
Carl Worthab82b3b2012-08-15 16:35:38 -070063 " --print-callset Print the final set of calls included in output\n"
Carl Worth25fe5242012-11-14 20:55:31 -080064 " --trim-spec=SPEC Only performing trimming as described in SPEC\n"
Carl Worth86464432012-08-11 11:46:54 -070065 " --thread=THREAD_ID Only retain calls from specified thread\n"
66 " -o, --output=TRACE_FILE Output trace file\n"
67 ;
68}
69
70static void
71help()
72{
73 std::cout
74 << "usage: apitrace trim [OPTIONS] TRACE_FILE...\n"
75 << synopsis << "\n"
76 "\n"
Carl Worth163b22c2012-08-10 10:15:30 -070077 " -h, --help Show this help message and exit\n"
Carl Worth16b18db2012-08-11 11:33:12 -070078 "\n"
79 " --calls=CALLSET Include specified calls in the trimmed output.\n"
Carl Worth46abfd12012-08-14 22:32:29 -070080 " --frames=FRAMESET Include specified frames in the trimmed output.\n"
Carl Worth16b18db2012-08-11 11:33:12 -070081 "\n"
Carl Worth163b22c2012-08-10 10:15:30 -070082 " --deps Perform dependency analysis and include dependent\n"
Carl Worth16b18db2012-08-11 11:33:12 -070083 " calls as needed, (even if those calls were not\n"
Carl Worth46abfd12012-08-14 22:32:29 -070084 " explicitly requested with --calls or --frames).\n"
Carl Wortha0931fd2013-03-21 15:49:58 -070085 " --no-deps Do not perform dependency analysis. Output will\n"
86 " not include any additional calls beyond those\n"
87 " explicitly requested with --calls or --frames).\n"
Carl Worth16b18db2012-08-11 11:33:12 -070088 "\n"
Carl Worth46abfd12012-08-14 22:32:29 -070089 " --prune Omit calls with no side effects, even if the call\n"
90 " is within the range specified by --calls/--frames.\n"
Carl Worth16b18db2012-08-11 11:33:12 -070091 "\n"
Carl Wortha0931fd2013-03-21 15:49:58 -070092 " --no-prune Never omit any calls from the range specified\n"
93 " --calls/--frames.\n"
94 "\n"
José Fonseca6e4768b2012-11-22 08:31:47 +000095 " -a, --auto Use dependency analysis and pruning\n"
96 " of uninteresting calls the resulting trace may\n"
97 " include more and less calls than specified.\n"
98 " This option is equivalent\n"
99 " to passing both --deps and --prune.\n"
Carl Worth16b18db2012-08-11 11:33:12 -0700100 "\n"
Carl Wortha0931fd2013-03-21 15:49:58 -0700101 " --exact Trim output to exact the calls or frames\n"
102 " specified with --calls or --frames.\n"
103 " This option is equivalent\n"
104 " to passing both --no-deps and --no-prune.\n"
105 "\n"
Carl Worthab82b3b2012-08-15 16:35:38 -0700106 " --print-callset Print to stdout the final set of calls included\n"
107 " in the trim output. This can be useful for\n"
Carl Worth25fe5242012-11-14 20:55:31 -0800108 " tweaking the trimmed callset from --auto on the\n"
José Fonseca6e4768b2012-11-22 08:31:47 +0000109 " command-line.\n"
110 " Use --calls=@FILE to read callset from a file.\n"
Carl Worth25fe5242012-11-14 20:55:31 -0800111 " --trim-spec=SPEC Specifies which classes of calls will be trimmed.\n"
112 " This option only has an effect if dependency\n"
113 " analysis is enabled. The argument is a comma-\n"
114 " separated list of names from the following:\n"
115 "\n"
116 " no-side-effects Calls with no side effects\n"
117 " textures Calls to setup unused textures\n"
118 " shaders Calls to setup unused shaders\n"
119 " drawing Calls that draw\n"
120 "\n"
121 " The default trim specification includes all of\n"
122 " the above, (as much as possible will be trimmed).\n"
Carl Worthab82b3b2012-08-15 16:35:38 -0700123 "\n"
Carl Worth163b22c2012-08-10 10:15:30 -0700124 " --thread=THREAD_ID Only retain calls from specified thread\n"
Carl Worth16b18db2012-08-11 11:33:12 -0700125 "\n"
Carl Worth163b22c2012-08-10 10:15:30 -0700126 " -o, --output=TRACE_FILE Output trace file\n"
José Fonsecad3c00132012-01-27 22:43:53 +0000127 "\n"
128 ;
Carl Worth4c5f6fa2011-11-14 14:50:07 -0800129}
130
José Fonsecab682b672012-02-15 07:13:31 +0000131enum {
Imre Deak6f07a842012-05-08 15:20:43 +0300132 CALLS_OPT = CHAR_MAX + 1,
Carl Worth46abfd12012-08-14 22:32:29 -0700133 FRAMES_OPT,
Carl Worth163b22c2012-08-10 10:15:30 -0700134 DEPS_OPT,
Carl Wortha0931fd2013-03-21 15:49:58 -0700135 NO_DEPS_OPT,
Carl Worth16b18db2012-08-11 11:33:12 -0700136 PRUNE_OPT,
Carl Wortha0931fd2013-03-21 15:49:58 -0700137 NO_PRUNE_OPT,
Imre Deak6f07a842012-05-08 15:20:43 +0300138 THREAD_OPT,
Carl Worthab82b3b2012-08-15 16:35:38 -0700139 PRINT_CALLSET_OPT,
Carl Wortha0931fd2013-03-21 15:49:58 -0700140 TRIM_SPEC_OPT,
141 EXACT_OPT
José Fonsecab682b672012-02-15 07:13:31 +0000142};
143
144const static char *
Carl Worth54300eb2013-01-28 23:37:17 +1100145shortOptions = "aho:x";
José Fonsecab682b672012-02-15 07:13:31 +0000146
147const static struct option
148longOptions[] = {
149 {"help", no_argument, 0, 'h'},
150 {"calls", required_argument, 0, CALLS_OPT},
Carl Worth46abfd12012-08-14 22:32:29 -0700151 {"frames", required_argument, 0, FRAMES_OPT},
Carl Worth163b22c2012-08-10 10:15:30 -0700152 {"deps", no_argument, 0, DEPS_OPT},
Carl Wortha0931fd2013-03-21 15:49:58 -0700153 {"no-deps", no_argument, 0, NO_DEPS_OPT},
Carl Worth16b18db2012-08-11 11:33:12 -0700154 {"prune", no_argument, 0, PRUNE_OPT},
Carl Wortha0931fd2013-03-21 15:49:58 -0700155 {"no-prune", no_argument, 0, NO_PRUNE_OPT},
José Fonseca6e4768b2012-11-22 08:31:47 +0000156 {"auto", no_argument, 0, 'a'},
Carl Wortha0931fd2013-03-21 15:49:58 -0700157 {"exact", no_argument, 0, EXACT_OPT},
Imre Deak6f07a842012-05-08 15:20:43 +0300158 {"thread", required_argument, 0, THREAD_OPT},
159 {"output", required_argument, 0, 'o'},
Carl Worthab82b3b2012-08-15 16:35:38 -0700160 {"print-callset", no_argument, 0, PRINT_CALLSET_OPT},
Carl Worth25fe5242012-11-14 20:55:31 -0800161 {"trim-spec", required_argument, 0, TRIM_SPEC_OPT},
José Fonsecab682b672012-02-15 07:13:31 +0000162 {0, 0, 0, 0}
163};
164
Carl Worth163b22c2012-08-10 10:15:30 -0700165struct stringCompare {
166 bool operator() (const char *a, const char *b) const {
167 return strcmp(a, b) < 0;
168 }
169};
170
Carl Worth163b22c2012-08-10 10:15:30 -0700171struct trim_options {
172 /* Calls to be included in trace. */
173 trace::CallSet calls;
174
Carl Worth46abfd12012-08-14 22:32:29 -0700175 /* Frames to be included in trace. */
176 trace::CallSet frames;
177
Carl Worth163b22c2012-08-10 10:15:30 -0700178 /* Whether dependency analysis should be performed. */
179 bool dependency_analysis;
180
Carl Worth16b18db2012-08-11 11:33:12 -0700181 /* Whether uninteresting calls should be pruned.. */
182 bool prune_uninteresting;
183
Carl Worth163b22c2012-08-10 10:15:30 -0700184 /* Output filename */
185 std::string output;
186
187 /* Emit only calls from this thread (-1 == all threads) */
188 int thread;
Carl Worthab82b3b2012-08-15 16:35:38 -0700189
190 /* Print resulting callset */
191 int print_callset;
Carl Worth25fe5242012-11-14 20:55:31 -0800192
193 /* What kind of trimming to perform. */
194 TrimFlags trim_flags;
Carl Worth163b22c2012-08-10 10:15:30 -0700195};
196
197static int
198trim_trace(const char *filename, struct trim_options *options)
199{
200 trace::ParseBookmark beginning;
201 trace::Parser p;
Carl Worth25fe5242012-11-14 20:55:31 -0800202 TraceAnalyzer analyzer(options->trim_flags);
Carl Worth163b22c2012-08-10 10:15:30 -0700203 std::set<unsigned> *required;
Carl Worth46abfd12012-08-14 22:32:29 -0700204 unsigned frame;
Carl Worthab82b3b2012-08-15 16:35:38 -0700205 int call_range_first, call_range_last;
Carl Worth163b22c2012-08-10 10:15:30 -0700206
207 if (!p.open(filename)) {
208 std::cerr << "error: failed to open " << filename << "\n";
209 return 1;
210 }
211
212 /* Mark the beginning so we can return here for pass 2. */
213 p.getBookmark(beginning);
214
215 /* In pass 1, analyze which calls are needed. */
Carl Worth46abfd12012-08-14 22:32:29 -0700216 frame = 0;
Carl Worth163b22c2012-08-10 10:15:30 -0700217 trace::Call *call;
218 while ((call = p.parse_call())) {
Carl Worth5b827e12012-08-12 20:41:50 -0700219
Carl Worth18198bc2013-03-11 15:49:17 -0700220 /* There's no use doing any work past the last call and frame
Carl Worth46abfd12012-08-14 22:32:29 -0700221 * requested by the user. */
Carl Worth18198bc2013-03-11 15:49:17 -0700222 if ((options->calls.empty() || call->no > options->calls.getLast()) &&
223 (options->frames.empty() || frame > options->frames.getLast())) {
224
Carl Worth42249012012-08-14 10:26:11 -0700225 delete call;
Carl Worth5b827e12012-08-12 20:41:50 -0700226 break;
Carl Worth42249012012-08-14 10:26:11 -0700227 }
Carl Worth5b827e12012-08-12 20:41:50 -0700228
Carl Worth163b22c2012-08-10 10:15:30 -0700229 /* If requested, ignore all calls not belonging to the specified thread. */
Carl Worth42249012012-08-14 10:26:11 -0700230 if (options->thread != -1 && call->thread_id != options->thread) {
Carl Worth46abfd12012-08-14 22:32:29 -0700231 goto NEXT;
Carl Worth42249012012-08-14 10:26:11 -0700232 }
Carl Worth163b22c2012-08-10 10:15:30 -0700233
Carl Worth6e57af82013-02-15 16:31:11 -0800234 /* Also, prune if no side effects (unless the user asked for no pruning. */
235 if (options->prune_uninteresting && call->flags & trace::CALL_FLAG_NO_SIDE_EFFECTS) {
Carl Worth46abfd12012-08-14 22:32:29 -0700236 goto NEXT;
Carl Worth16b18db2012-08-11 11:33:12 -0700237 }
238
Carl Worthcc6e51c2012-08-13 14:35:43 -0700239 /* If this call is included in the user-specified call set,
240 * then require it (and all dependencies) in the trimmed
241 * output. */
Carl Worth46abfd12012-08-14 22:32:29 -0700242 if (options->calls.contains(*call) ||
243 options->frames.contains(frame, call->flags)) {
244
Carl Worth163b22c2012-08-10 10:15:30 -0700245 analyzer.require(call);
Carl Worthcc6e51c2012-08-13 14:35:43 -0700246 }
247
248 /* Regardless of whether we include this call or not, we do
249 * some dependency tracking (unless disabled by the user). We
250 * do this even for calls we have included in the output so
251 * that any state updates get performed. */
252 if (options->dependency_analysis) {
253 analyzer.analyze(call);
Carl Worth163b22c2012-08-10 10:15:30 -0700254 }
Carl Worth42249012012-08-14 10:26:11 -0700255
Carl Worth46abfd12012-08-14 22:32:29 -0700256 NEXT:
257 if (call->flags & trace::CALL_FLAG_END_FRAME)
258 frame++;
259
Carl Worth42249012012-08-14 10:26:11 -0700260 delete call;
Carl Worth163b22c2012-08-10 10:15:30 -0700261 }
262
263 /* Prepare output file and writer for output. */
264 if (options->output.empty()) {
265 os::String base(filename);
266 base.trimExtension();
267
268 options->output = std::string(base.str()) + std::string("-trim.trace");
269 }
270
271 trace::Writer writer;
272 if (!writer.open(options->output.c_str())) {
273 std::cerr << "error: failed to create " << filename << "\n";
274 return 1;
275 }
276
277 /* Reset bookmark for pass 2. */
278 p.setBookmark(beginning);
279
280 /* In pass 2, emit the calls that are required. */
281 required = analyzer.get_required();
282
Carl Worth46abfd12012-08-14 22:32:29 -0700283 frame = 0;
Carl Worthab82b3b2012-08-15 16:35:38 -0700284 call_range_first = -1;
285 call_range_last = -1;
Carl Worth163b22c2012-08-10 10:15:30 -0700286 while ((call = p.parse_call())) {
Carl Worth5b827e12012-08-12 20:41:50 -0700287
Carl Worth18198bc2013-03-11 15:49:17 -0700288 /* There's no use doing any work past the last call and frame
Carl Worth46abfd12012-08-14 22:32:29 -0700289 * requested by the user. */
Carl Worth18198bc2013-03-11 15:49:17 -0700290 if ((options->calls.empty() || call->no > options->calls.getLast()) &&
291 (options->frames.empty() || frame > options->frames.getLast())) {
Carl Worth46abfd12012-08-14 22:32:29 -0700292
Carl Worth5b827e12012-08-12 20:41:50 -0700293 break;
Carl Worth46abfd12012-08-14 22:32:29 -0700294 }
Carl Worth5b827e12012-08-12 20:41:50 -0700295
Carl Worth163b22c2012-08-10 10:15:30 -0700296 if (required->find(call->no) != required->end()) {
297 writer.writeCall(call);
Carl Worthab82b3b2012-08-15 16:35:38 -0700298
299 if (options->print_callset) {
300 if (call_range_first < 0) {
301 call_range_first = call->no;
302 printf ("%d", call_range_first);
303 } else if (call->no != call_range_last + 1) {
304 if (call_range_last != call_range_first)
305 printf ("-%d", call_range_last);
306 call_range_first = call->no;
307 printf (",%d", call_range_first);
308 }
309 call_range_last = call->no;
310 }
Carl Worth163b22c2012-08-10 10:15:30 -0700311 }
Carl Worth46abfd12012-08-14 22:32:29 -0700312
313 if (call->flags & trace::CALL_FLAG_END_FRAME) {
314 frame++;
315 }
316
Carl Worth163b22c2012-08-10 10:15:30 -0700317 delete call;
318 }
319
Carl Worthab82b3b2012-08-15 16:35:38 -0700320 if (options->print_callset) {
321 if (call_range_last != call_range_first)
322 printf ("-%d\n", call_range_last);
323 }
324
Carl Worth1a800a12012-08-17 14:23:13 -0700325 std::cerr << "Trimmed trace is available as " << options->output << "\n";
Carl Worth163b22c2012-08-10 10:15:30 -0700326
327 return 0;
328}
329
Carl Worth4c5f6fa2011-11-14 14:50:07 -0800330static int
Carl Worth25fe5242012-11-14 20:55:31 -0800331parse_trim_spec(const char *trim_spec, TrimFlags *flags)
332{
333 std::string spec(trim_spec), word;
334 size_t start = 0, comma = 0;
335 *flags = 0;
336
337 while (start < spec.size()) {
338 comma = spec.find(',', start);
339
340 if (comma == std::string::npos)
341 word = std::string(spec, start);
342 else
343 word = std::string(spec, start, comma - start);
344
345 if (strcmp(word.c_str(), "no-side-effects") == 0)
346 *flags |= TRIM_FLAG_NO_SIDE_EFFECTS;
347 else if (strcmp(word.c_str(), "textures") == 0)
348 *flags |= TRIM_FLAG_TEXTURES;
349 else if (strcmp(word.c_str(), "shaders") == 0)
350 *flags |= TRIM_FLAG_SHADERS;
351 else if (strcmp(word.c_str(), "drawing") == 0)
352 *flags |= TRIM_FLAG_DRAWING;
353 else {
354 return 1;
355 }
356
357 if (comma == std::string::npos)
358 break;
359
360 start = comma + 1;
361 }
362
363 return 0;
364}
365
366static int
Carl Worth4c5f6fa2011-11-14 14:50:07 -0800367command(int argc, char *argv[])
368{
Carl Worth163b22c2012-08-10 10:15:30 -0700369 struct trim_options options;
370
Carl Worth46abfd12012-08-14 22:32:29 -0700371 options.calls = trace::CallSet(trace::FREQUENCY_NONE);
372 options.frames = trace::CallSet(trace::FREQUENCY_NONE);
José Fonseca6e4768b2012-11-22 08:31:47 +0000373 options.dependency_analysis = false;
374 options.prune_uninteresting = false;
Carl Worth163b22c2012-08-10 10:15:30 -0700375 options.output = "";
376 options.thread = -1;
Carl Worthab82b3b2012-08-15 16:35:38 -0700377 options.print_callset = 0;
Carl Worth25fe5242012-11-14 20:55:31 -0800378 options.trim_flags = -1;
Carl Worth4c5f6fa2011-11-14 14:50:07 -0800379
José Fonsecab682b672012-02-15 07:13:31 +0000380 int opt;
381 while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
382 switch (opt) {
383 case 'h':
Carl Worth86464432012-08-11 11:46:54 -0700384 help();
Carl Worth4c5f6fa2011-11-14 14:50:07 -0800385 return 0;
José Fonsecab682b672012-02-15 07:13:31 +0000386 case CALLS_OPT:
Carl Worth163b22c2012-08-10 10:15:30 -0700387 options.calls = trace::CallSet(optarg);
388 break;
Carl Worth46abfd12012-08-14 22:32:29 -0700389 case FRAMES_OPT:
390 options.frames = trace::CallSet(optarg);
391 break;
Carl Worth163b22c2012-08-10 10:15:30 -0700392 case DEPS_OPT:
393 options.dependency_analysis = true;
394 break;
Carl Wortha0931fd2013-03-21 15:49:58 -0700395 case NO_DEPS_OPT:
396 options.dependency_analysis = false;
397 break;
Carl Worth16b18db2012-08-11 11:33:12 -0700398 case PRUNE_OPT:
399 options.prune_uninteresting = true;
400 break;
Carl Wortha0931fd2013-03-21 15:49:58 -0700401 case NO_PRUNE_OPT:
402 options.prune_uninteresting = false;
403 break;
José Fonseca6e4768b2012-11-22 08:31:47 +0000404 case 'a':
405 options.dependency_analysis = true;
406 options.prune_uninteresting = true;
Carl Worth16b18db2012-08-11 11:33:12 -0700407 break;
Carl Wortha0931fd2013-03-21 15:49:58 -0700408 case EXACT_OPT:
409 options.dependency_analysis = false;
410 options.prune_uninteresting = false;
411 break;
Imre Deak6f07a842012-05-08 15:20:43 +0300412 case THREAD_OPT:
Carl Worth163b22c2012-08-10 10:15:30 -0700413 options.thread = atoi(optarg);
Imre Deak6f07a842012-05-08 15:20:43 +0300414 break;
José Fonsecab682b672012-02-15 07:13:31 +0000415 case 'o':
Carl Worth163b22c2012-08-10 10:15:30 -0700416 options.output = optarg;
José Fonsecab682b672012-02-15 07:13:31 +0000417 break;
Carl Worthab82b3b2012-08-15 16:35:38 -0700418 case PRINT_CALLSET_OPT:
419 options.print_callset = 1;
420 break;
Carl Worth25fe5242012-11-14 20:55:31 -0800421 case TRIM_SPEC_OPT:
422 if (parse_trim_spec(optarg, &options.trim_flags)) {
423 std::cerr << "error: illegal value for trim-spec: " << optarg << "\n";
424 std::cerr << "See \"apitrace help trim\" for help.\n";
425 return 1;
426 }
427 break;
José Fonsecab682b672012-02-15 07:13:31 +0000428 default:
429 std::cerr << "error: unexpected option `" << opt << "`\n";
Carl Worth4c5f6fa2011-11-14 14:50:07 -0800430 usage();
431 return 1;
432 }
433 }
434
Carl Worth46abfd12012-08-14 22:32:29 -0700435 /* If neither of --calls nor --frames was set, default to the
436 * entire set of calls. */
437 if (options.calls.empty() && options.frames.empty()) {
438 options.calls = trace::CallSet(trace::FREQUENCY_ALL);
439 }
440
José Fonsecab682b672012-02-15 07:13:31 +0000441 if (optind >= argc) {
442 std::cerr << "error: apitrace trim requires a trace file as an argument.\n";
Carl Worth4c5f6fa2011-11-14 14:50:07 -0800443 usage();
444 return 1;
445 }
446
Carl Worthf630d9d2012-09-04 16:48:00 -0700447 if (argc > optind + 1) {
448 std::cerr << "error: extraneous arguments:";
449 for (int i = optind + 1; i < argc; i++) {
450 std::cerr << " " << argv[i];
451 }
452 std::cerr << "\n";
453 usage();
454 return 1;
455 }
456
Carl Worth83ec3f62012-08-17 14:22:30 -0700457 if (options.dependency_analysis) {
458 std::cerr <<
459 "Note: The dependency analysis in \"apitrace trim\" is still experimental.\n"
460 " We hope that it will be useful, but it may lead to incorrect results.\n"
461 " If you find a trace that misbehaves while trimming, please share that\n"
462 " by sending email to apitrace@lists.freedesktop.org, cworth@cworth.org\n";
463 }
464
Carl Worth163b22c2012-08-10 10:15:30 -0700465 return trim_trace(argv[optind], &options);
Carl Worth4c5f6fa2011-11-14 14:50:07 -0800466}
467
468const Command trim_command = {
469 "trim",
470 synopsis,
Carl Worth86464432012-08-11 11:46:54 -0700471 help,
Carl Worth4c5f6fa2011-11-14 14:50:07 -0800472 command
473};