diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2010-02-18 10:27:15 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-18 10:27:15 -0500 |
| commit | 3c080e0fe5f28e63d5f1a6597e348901fedc0b86 (patch) | |
| tree | dc779a58cf4c0e87544180c21ca18b9903839564 | |
| parent | c748e01c073f47d7696f6eba59cb18454648ae8a (diff) | |
trace-cmd: Add -P option to record a single pid
Add the -P option to trace-cmd record (and start) to only trace
a given pid. This is just like -F command where the pid given to
-P would be the pid of the command.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | trace-cmd.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/trace-cmd.c b/trace-cmd.c index 2b246df..e89362d 100644 --- a/trace-cmd.c +++ b/trace-cmd.c | |||
| @@ -58,6 +58,7 @@ static int cpu_count; | |||
| 58 | static int *pids; | 58 | static int *pids; |
| 59 | 59 | ||
| 60 | static int filter_task; | 60 | static int filter_task; |
| 61 | static int filter_pid = -1; | ||
| 61 | 62 | ||
| 62 | struct func_list { | 63 | struct func_list { |
| 63 | struct func_list *next; | 64 | struct func_list *next; |
| @@ -309,12 +310,15 @@ static void update_task_filter(void) | |||
| 309 | int pid = getpid(); | 310 | int pid = getpid(); |
| 310 | char spid[100]; | 311 | char spid[100]; |
| 311 | 312 | ||
| 312 | if (!filter_task) { | 313 | if (!filter_task && filter_pid < 0) { |
| 313 | update_ftrace_pid(""); | 314 | update_ftrace_pid(""); |
| 314 | enable_tracing(); | 315 | enable_tracing(); |
| 315 | return; | 316 | return; |
| 316 | } | 317 | } |
| 317 | 318 | ||
| 319 | if (filter_pid >= 0) | ||
| 320 | pid = filter_pid; | ||
| 321 | |||
| 318 | snprintf(spid, 100, "%d", pid); | 322 | snprintf(spid, 100, "%d", pid); |
| 319 | 323 | ||
| 320 | update_ftrace_pid(spid); | 324 | update_ftrace_pid(spid); |
| @@ -1061,11 +1065,13 @@ void usage(char **argv) | |||
| 1061 | "%s version %s\n\n" | 1065 | "%s version %s\n\n" |
| 1062 | "usage:\n" | 1066 | "usage:\n" |
| 1063 | " %s record [-v][-e event [-f filter]][-p plugin][-F][-d][-o file] \\\n" | 1067 | " %s record [-v][-e event [-f filter]][-p plugin][-F][-d][-o file] \\\n" |
| 1064 | " [-s usecs][-O option ][-l func][-g func][-n func][command ...]\n" | 1068 | " [-s usecs][-O option ][-l func][-g func][-n func]\n" |
| 1069 | " [-P pid][command ...]\n" | ||
| 1065 | " -e run command with event enabled\n" | 1070 | " -e run command with event enabled\n" |
| 1066 | " -f filter for previous -e event\n" | 1071 | " -f filter for previous -e event\n" |
| 1067 | " -p run command with plugin enabled\n" | 1072 | " -p run command with plugin enabled\n" |
| 1068 | " -F filter only on the given process\n" | 1073 | " -F filter only on the given process\n" |
| 1074 | " -P trace the given pid like -F for the command\n" | ||
| 1069 | " -l filter function name\n" | 1075 | " -l filter function name\n" |
| 1070 | " -g set graph function\n" | 1076 | " -g set graph function\n" |
| 1071 | " -n do not trace function\n" | 1077 | " -n do not trace function\n" |
| @@ -1075,7 +1081,7 @@ void usage(char **argv) | |||
| 1075 | " -O option to enable (or disable)\n" | 1081 | " -O option to enable (or disable)\n" |
| 1076 | " -s sleep interval between recording (in usecs) [default: 1000]\n" | 1082 | " -s sleep interval between recording (in usecs) [default: 1000]\n" |
| 1077 | "\n" | 1083 | "\n" |
| 1078 | " %s start [-e event][-p plugin] [-d] [-O option ]\n" | 1084 | " %s start [-e event][-p plugin][-d][-O option ][-P pid]\n" |
| 1079 | " Uses same options as record, but does not run a command.\n" | 1085 | " Uses same options as record, but does not run a command.\n" |
| 1080 | " It only enables the tracing and exits\n" | 1086 | " It only enables the tracing and exits\n" |
| 1081 | "\n" | 1087 | "\n" |
| @@ -1160,7 +1166,7 @@ int main (int argc, char **argv) | |||
| 1160 | (strcmp(argv[1], "start") == 0) || | 1166 | (strcmp(argv[1], "start") == 0) || |
| 1161 | ((extract = strcmp(argv[1], "extract") == 0))) { | 1167 | ((extract = strcmp(argv[1], "extract") == 0))) { |
| 1162 | 1168 | ||
| 1163 | while ((c = getopt(argc-1, argv+1, "+he:f:Fp:do:O:s:vg:l:n:")) >= 0) { | 1169 | while ((c = getopt(argc-1, argv+1, "+he:f:Fp:do:O:s:vg:l:n:P:")) >= 0) { |
| 1164 | switch (c) { | 1170 | switch (c) { |
| 1165 | case 'h': | 1171 | case 'h': |
| 1166 | usage(argv); | 1172 | usage(argv); |
| @@ -1198,8 +1204,17 @@ int main (int argc, char **argv) | |||
| 1198 | break; | 1204 | break; |
| 1199 | 1205 | ||
| 1200 | case 'F': | 1206 | case 'F': |
| 1207 | if (filter_pid >= 0) | ||
| 1208 | die("-P and -F can not both be specified"); | ||
| 1201 | filter_task = 1; | 1209 | filter_task = 1; |
| 1202 | break; | 1210 | break; |
| 1211 | case 'P': | ||
| 1212 | if (filter_task) | ||
| 1213 | die("-P and -F can not both be specified"); | ||
| 1214 | if (filter_pid >= 0) | ||
| 1215 | die("only one -P pid can be filtered at a time"); | ||
| 1216 | filter_pid = atoi(optarg); | ||
| 1217 | break; | ||
| 1203 | case 'v': | 1218 | case 'v': |
| 1204 | if (extract) | 1219 | if (extract) |
| 1205 | usage(argv); | 1220 | usage(argv); |
