diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-01-17 11:36:36 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-02-01 21:00:59 -0500 |
commit | 19293fe7beb005caad1dc139eab1094288df30e0 (patch) | |
tree | 2bcb26941383d5fede499c6aa202d4f0df2fd02c | |
parent | 9f88745242c0cdd78af1226fb710e8031cb81a0a (diff) |
trace-cmd: Allow update_ftrace_pid() to allow multiple calls
Change the way update_ftrace_pid() to allow multiple calls
to add more than one pid.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-cmd.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/trace-cmd.c b/trace-cmd.c index 5055db6..e1341bf 100644 --- a/trace-cmd.c +++ b/trace-cmd.c | |||
@@ -317,19 +317,37 @@ static void reset_max_latency(void) | |||
317 | fclose(fp); | 317 | fclose(fp); |
318 | } | 318 | } |
319 | 319 | ||
320 | static void update_ftrace_pid(const char *pid) | 320 | static void update_ftrace_pid(const char *pid, int reset) |
321 | { | 321 | { |
322 | char *path; | 322 | static char *path; |
323 | int ret; | 323 | int ret; |
324 | int fd; | 324 | static int fd = -1; |
325 | 325 | ||
326 | path = tracecmd_get_tracing_file("set_ftrace_pid"); | 326 | if (!pid) { |
327 | if (!path) | 327 | if (fd >= 0) |
328 | close(fd); | ||
329 | if (path) | ||
330 | tracecmd_put_tracing_file(path); | ||
331 | fd = -1; | ||
332 | path = NULL; | ||
328 | return; | 333 | return; |
334 | } | ||
329 | 335 | ||
330 | fd = open(path, O_WRONLY | O_TRUNC); | 336 | /* Force reopen on reset */ |
331 | if (fd < 0) | 337 | if (reset && fd >= 0) { |
332 | return; | 338 | close(fd); |
339 | fd = -1; | ||
340 | } | ||
341 | |||
342 | if (fd < 0) { | ||
343 | if (!path) | ||
344 | path = tracecmd_get_tracing_file("set_ftrace_pid"); | ||
345 | if (!path) | ||
346 | return; | ||
347 | fd = open(path, O_WRONLY | (reset ? O_TRUNC : 0)); | ||
348 | if (fd < 0) | ||
349 | return; | ||
350 | } | ||
333 | 351 | ||
334 | ret = write(fd, pid, strlen(pid)); | 352 | ret = write(fd, pid, strlen(pid)); |
335 | 353 | ||
@@ -342,7 +360,8 @@ static void update_ftrace_pid(const char *pid) | |||
342 | if (ret < 0) | 360 | if (ret < 0) |
343 | die("error writing to %s", path); | 361 | die("error writing to %s", path); |
344 | 362 | ||
345 | close(fd); | 363 | /* add whitespace in case another pid is written */ |
364 | write(fd, " ", 1); | ||
346 | } | 365 | } |
347 | 366 | ||
348 | static void update_pid_event_filters(const char *pid); | 367 | static void update_pid_event_filters(const char *pid); |
@@ -354,7 +373,7 @@ static void update_task_filter(void) | |||
354 | char spid[100]; | 373 | char spid[100]; |
355 | 374 | ||
356 | if (!filter_task && filter_pid < 0) { | 375 | if (!filter_task && filter_pid < 0) { |
357 | update_ftrace_pid(""); | 376 | update_ftrace_pid("", 1); |
358 | enable_tracing(); | 377 | enable_tracing(); |
359 | return; | 378 | return; |
360 | } | 379 | } |
@@ -364,7 +383,7 @@ static void update_task_filter(void) | |||
364 | 383 | ||
365 | snprintf(spid, 100, "%d", pid); | 384 | snprintf(spid, 100, "%d", pid); |
366 | 385 | ||
367 | update_ftrace_pid(spid); | 386 | update_ftrace_pid(spid, 1); |
368 | 387 | ||
369 | update_pid_event_filters(spid); | 388 | update_pid_event_filters(spid); |
370 | 389 | ||
@@ -837,7 +856,10 @@ static void disable_all(void) | |||
837 | 856 | ||
838 | set_plugin("nop"); | 857 | set_plugin("nop"); |
839 | update_event("all", "0", 0, '0'); | 858 | update_event("all", "0", 0, '0'); |
840 | update_ftrace_pid(""); | 859 | |
860 | /* Force close and reset of ftrace pid file */ | ||
861 | update_ftrace_pid("", 1); | ||
862 | update_ftrace_pid(NULL, 0); | ||
841 | 863 | ||
842 | clear_trace(); | 864 | clear_trace(); |
843 | } | 865 | } |