diff options
-rw-r--r-- | trace-cmd.c | 64 |
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 | ||
286 | static void update_pid_event_filters(char *pid); | 286 | static void update_pid_event_filters(const char *pid); |
287 | static void enable_tracing(void); | 287 | static void enable_tracing(void); |
288 | 288 | ||
289 | static void update_task_filter(void) | 289 | static void update_task_filter(void) |
@@ -720,7 +720,60 @@ static void disable_all(void) | |||
720 | clear_trace(); | 720 | clear_trace(); |
721 | } | 721 | } |
722 | 722 | ||
723 | static void update_pid_event_filters(char *pid) | 723 | static 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 | |||
776 | static 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 | ||
750 | static void enable_events(void) | 810 | static void enable_events(void) |