[PATCH v2 03/18] filter based on thread_id
Imre Deak
imre.deak at intel.com
Tue May 15 07:10:58 PDT 2012
Signed-off-by: Imre Deak <imre.deak at intel.com>
---
cli/cli_trim.cpp | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/cli/cli_trim.cpp b/cli/cli_trim.cpp
index 206e24e..3a91923 100644
--- a/cli/cli_trim.cpp
+++ b/cli/cli_trim.cpp
@@ -48,6 +48,7 @@ usage(void)
"\n"
" -h, --help show this help message and exit\n"
" --calls=CALLSET only trim specified calls\n"
+ " --thread=THREAD_ID only trim calls from specified thread\n"
" -o, --output=TRACE_FILE output trace file\n"
"\n"
;
@@ -55,6 +56,7 @@ usage(void)
enum {
CALLS_OPT = CHAR_MAX + 1,
+ THREAD_OPT,
};
const static char *
@@ -63,7 +65,8 @@ shortOptions = "ho:";
const static struct option
longOptions[] = {
{"help", no_argument, 0, 'h'},
- {"calls", required_argument, 0, CALLS_OPT},
+ {"calls", optional_argument, 0, CALLS_OPT},
+ {"thread", optional_argument, 0, THREAD_OPT},
{"output", optional_argument, 0, 'o'},
{0, 0, 0, 0}
};
@@ -72,7 +75,9 @@ static int
command(int argc, char *argv[])
{
std::string output;
+ bool calls_set = false;
trace::CallSet calls(trace::FREQUENCY_ALL);
+ int thread = -1;
int i;
int opt;
@@ -83,6 +88,10 @@ command(int argc, char *argv[])
return 0;
case CALLS_OPT:
calls = trace::CallSet(optarg);
+ calls_set = true;
+ break;
+ case THREAD_OPT:
+ thread = atoi(optarg);
break;
case 'o':
output = optarg;
@@ -94,6 +103,12 @@ command(int argc, char *argv[])
}
}
+ if (thread == -1 && !calls_set) {
+ std::cerr << "error: you must specify at least one of 'calls' or 'thread'\n";
+ usage();
+ return 1;
+ }
+
if (optind >= argc) {
std::cerr << "error: apitrace trim requires a trace file as an argument.\n";
usage();
@@ -122,7 +137,8 @@ command(int argc, char *argv[])
trace::Call *call;
while ((call = p.parse_call())) {
- if (calls.contains(*call)) {
+ if ((thread != -1 && call->thread_id == thread) ||
+ (calls_set && calls.contains(*call))) {
writer.writeCall(call);
}
delete call;
--
1.7.5.4
More information about the apitrace
mailing list