+static void
+help()
+{
+ std::cout
+ << "usage: apitrace trim [OPTIONS] TRACE_FILE...\n"
+ << synopsis << "\n"
+ "\n"
+ " -h, --help Show this help message and exit\n"
+ "\n"
+ " --calls=CALLSET Include specified calls in the trimmed output.\n"
+ " --frames=FRAMESET Include specified frames in the trimmed output.\n"
+ "\n"
+ " --deps Perform dependency analysis and include dependent\n"
+ " calls as needed, (even if those calls were not\n"
+ " explicitly requested with --calls or --frames).\n"
+ "\n"
+ " --prune Omit calls with no side effects, even if the call\n"
+ " is within the range specified by --calls/--frames.\n"
+ "\n"
+ " -a, --auto Use dependency analysis and pruning\n"
+ " of uninteresting calls the resulting trace may\n"
+ " include more and less calls than specified.\n"
+ " This option is equivalent\n"
+ " to passing both --deps and --prune.\n"
+ "\n"
+ " --print-callset Print to stdout the final set of calls included\n"
+ " in the trim output. This can be useful for\n"
+ " tweaking trimmed callset from --auto on the\n"
+ " command-line.\n"
+ " Use --calls=@FILE to read callset from a file.\n"
+ "\n"
+ " --thread=THREAD_ID Only retain calls from specified thread\n"
+ "\n"
+ " -o, --output=TRACE_FILE Output trace file\n"
+ "\n"
+ ;
+}
+
+enum {
+ CALLS_OPT = CHAR_MAX + 1,
+ FRAMES_OPT,
+ DEPS_OPT,
+ PRUNE_OPT,
+ THREAD_OPT,
+ PRINT_CALLSET_OPT,
+};
+
+const static char *
+shortOptions = "aho:x";
+
+const static struct option
+longOptions[] = {
+ {"help", no_argument, 0, 'h'},
+ {"calls", required_argument, 0, CALLS_OPT},
+ {"frames", required_argument, 0, FRAMES_OPT},
+ {"deps", no_argument, 0, DEPS_OPT},
+ {"prune", no_argument, 0, PRUNE_OPT},
+ {"auto", no_argument, 0, 'a'},
+ {"thread", required_argument, 0, THREAD_OPT},
+ {"output", required_argument, 0, 'o'},
+ {"print-callset", no_argument, 0, PRINT_CALLSET_OPT},
+ {0, 0, 0, 0}
+};
+
+struct stringCompare {
+ bool operator() (const char *a, const char *b) const {
+ return strcmp(a, b) < 0;
+ }
+};
+
+struct trim_options {
+ /* Calls to be included in trace. */
+ trace::CallSet calls;
+
+ /* Frames to be included in trace. */
+ trace::CallSet frames;
+
+ /* Whether dependency analysis should be performed. */
+ bool dependency_analysis;
+
+ /* Whether uninteresting calls should be pruned.. */
+ bool prune_uninteresting;
+
+ /* Output filename */
+ std::string output;
+
+ /* Emit only calls from this thread (-1 == all threads) */
+ int thread;
+
+ /* Print resulting callset */
+ int print_callset;
+};
+