X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=cli%2Fcli_trim.cpp;h=eea55535e95395f8707afd7f6d1090e6edc873ec;hb=0dc18e795c47098d94447c2b8deabbf265737559;hp=73c18d1f58dc923e26bd298657b8200ed717e7b3;hpb=b682b67d31082f5c86458512ce36cbcf597312d3;p=apitrace diff --git a/cli/cli_trim.cpp b/cli/cli_trim.cpp index 73c18d1..eea5553 100644 --- a/cli/cli_trim.cpp +++ b/cli/cli_trim.cpp @@ -46,26 +46,28 @@ usage(void) << "usage: apitrace trim [OPTIONS] TRACE_FILE...\n" << synopsis << "\n" "\n" - " -h, --help show this help message and exit\n" - " --calls=CALLSET only trim specified calls\n" - " -o --output=TRACE_FILE output trace file\n" + " -h, --help show this help message and exit\n" + " --calls=CALLSET only retain specified calls\n" + " --thread=THREAD_ID only retain calls from specified thread\n" + " -o, --output=TRACE_FILE output trace file\n" "\n" ; } enum { - CALLS_OPT = CHAR_MAX + 1, + CALLS_OPT = CHAR_MAX + 1, + THREAD_OPT, }; const static char * -shortOptions = "ho"; +shortOptions = "ho:"; const static struct option longOptions[] = { {"help", no_argument, 0, 'h'}, {"calls", required_argument, 0, CALLS_OPT}, - {"calls", required_argument, 0, CALLS_OPT}, - {"output", optional_argument, 0, 'o'}, + {"thread", required_argument, 0, THREAD_OPT}, + {"output", required_argument, 0, 'o'}, {0, 0, 0, 0} }; @@ -74,6 +76,7 @@ command(int argc, char *argv[]) { std::string output; trace::CallSet calls(trace::FREQUENCY_ALL); + int thread = -1; int i; int opt; @@ -85,6 +88,9 @@ command(int argc, char *argv[]) case CALLS_OPT: calls = trace::CallSet(optarg); break; + case THREAD_OPT: + thread = atoi(optarg); + break; case 'o': output = optarg; break; @@ -104,7 +110,6 @@ command(int argc, char *argv[]) for (i = optind; i < argc; ++i) { trace::Parser p; if (!p.open(argv[i])) { - std::cerr << "error: failed to open " << argv[i] << "\n"; return 1; } @@ -123,7 +128,8 @@ command(int argc, char *argv[]) trace::Call *call; while ((call = p.parse_call())) { - if (calls.contains(*call)) { + if (calls.contains(*call) && + (thread == -1 || call->thread_id == thread)) { writer.writeCall(call); } delete call;