aboutsummaryrefslogtreecommitdiffstats
path: root/trace-cmd.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-02-01 23:30:26 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-02-01 23:30:26 -0500
commit0bf9ef787cd9cd482280f935b1a13e068e5a5d82 (patch)
treeabd629e91d9f443f1675276f91a24df8b9ccc058 /trace-cmd.c
parent1d8fcad30f182df6c6006613685e200a4bda73a9 (diff)
trace-cmd: Add sched_switch to and wake up of pid to filter
If the -F option is set, include events that wake up that pid or switch to it. That is, even if the event is done by another task, if that task calls the wakeup event to the filtered pid, it should also be shown, as well as the context switches to the filtered task. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'trace-cmd.c')
-rw-r--r--trace-cmd.c64
1 files changed, 62 insertions, 2 deletions
diff --git a/trace-cmd.c b/trace-cmd.c
index 6c3d91c..4466f93 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -283,7 +283,7 @@ static void update_ftrace_pid(const char *pid)
283 close(fd); 283 close(fd);
284} 284}
285 285
286static void update_pid_event_filters(char *pid); 286static void update_pid_event_filters(const char *pid);
287static void enable_tracing(void); 287static void enable_tracing(void);
288 288
289static void update_task_filter(void) 289static void update_task_filter(void)
@@ -720,7 +720,60 @@ static void disable_all(void)
720 clear_trace(); 720 clear_trace();
721} 721}
722 722
723static void update_pid_event_filters(char *pid) 723static void update_filter(const char *event_name, const char *field,
724 const char *pid)
725{
726 char buf[BUFSIZ];
727 char *filter_name;
728 char *path;
729 char *filter;
730 int fd;
731 int ret;
732
733 filter_name = malloc_or_die(strlen(event_name) +
734 strlen("events//filter") + 1);
735 sprintf(filter_name, "events/%s/filter", event_name);
736
737 path = get_tracing_file(filter_name);
738 free(filter_name);
739
740 /* Ignore if file does not exist */
741 fd = open(path, O_RDONLY);
742 if (fd < 0)
743 goto out;
744
745 ret = read(fd, buf, BUFSIZ);
746 if (ret < 0)
747 die("Can't read %s", path);
748 close(fd);
749
750 /* append unless there is currently no filter */
751 if (strcmp(buf, "none") == 0) {
752 filter = malloc_or_die(strlen(pid) + strlen(field) +
753 strlen("(==)") + 1);
754 sprintf(filter, "(%s==%s)", field, pid);
755 } else {
756 filter = malloc_or_die(strlen(pid) + strlen(field) +
757 strlen(buf) + strlen("()||(==)") + 1);
758 sprintf(filter, "(%s)||(%s==%s)", buf, field, pid);
759 }
760
761 fd = open(path, O_WRONLY);
762 if (fd < 0)
763 die("can't open %s", path);
764
765 ret = write(fd, filter, strlen(filter));
766 if (ret < 0)
767 die("Can't write to %s", path);
768 close(fd);
769
770 free(filter);
771
772 out:
773 put_tracing_file(path);
774}
775
776static void update_pid_event_filters(const char *pid)
724{ 777{
725 struct event_list *event; 778 struct event_list *event;
726 char *filter; 779 char *filter;
@@ -745,6 +798,13 @@ static void update_pid_event_filters(char *pid)
745 } 798 }
746 799
747 free(filter); 800 free(filter);
801
802 /*
803 * Also make sure that the sched_switch to this pid
804 * and wakeups of this pid are also traced.
805 */
806 update_filter("sched/sched_switch", "next_pid", pid);
807 update_filter("sched/sched_wakeup", "pid", pid);
748} 808}
749 809
750static void enable_events(void) 810static void enable_events(void)