perf script: Add comm filtering option
PATCH 1/1 perf script: Add comm filtering option
Allows collecting events system wide and then pulling out events for a specific task name(s). e.g,
perf script -c gnome-shell,gnome-terminal
Applies on top of:
https://lkml.org/lkml/2011/11/13/74
--- tools/perf/Documentation/perf-script.txt | 4 ++++ tools/perf/builtin-script.c | 11 +++++++++++ tools/perf/util/strlist.c | 15 +++++++++++++++ tools/perf/util/strlist.h | 2 ++ tools/perf/util/symbol.c | 14 -------------- 5 files changed, 32 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-script.txt +4 -0
@@ -188,6 +188,10 @@ OPTIONS CPUs are specified with -: 0-2. Default is to report samples on all CPUs. +-c:: +--comms=:: + Comma separated list of comms. Only events for these comms are shown. + -I:: --show-info:: Display extended information about the perf.data file. This adds
tools/perf/builtin-script.c +11 -0
@@ -13,6 +13,7 @@#include "util/util.h" #include "util/evlist.h" #include "util/evsel.h" +#include "util/strlist.h" #include <linux/bitmap.h> static char const *script_name;
@@ -24,6 +25,8 @@ extern const struct option record_options[];static bool no_callchain;static bool show_full_info;static const char *cpu_list; +static const char *comm_list_str; +struct strlist *comm_list; static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);enum perf_output_field {
@@ -461,6 +464,9 @@ static int process_sample_event(union perf_event *event,if (cpu_list && !test_bit (sample->cpu, cpu_bitmap))return 0 ; +if (comm_list && !strlist__has_entry (comm_list, thread->comm)) +return 0 ; + scripting_ops->process_event (event, sample, evsel, session, thread); session->hists.stats.total_period += sample->period;
@@ -1084,6 +1090,8 @@ static const struct option options[] = { "comma separated output fields prepend with 'type:'. Valid types: hw,sw,trace,raw. Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,addr", parse_output_fields),OPT_STRING ('C' ,"cpu" , &cpu_list,"cpu" ,"list of cpus to profile" ), +OPT_STRING ('c' ,"comms" , &comm_list_str,"comm[,comm...]" , +"only display events for these comms" ),OPT_BOOLEAN ('I' ,"show-info" , &show_full_info,"display extended information from perf.data file" ),OPT_END ()
@@ -1256,6 +1264,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)exit (-1 ); } +if (setup_list (&comm_list, comm_list_str,"comm" ) <0 ) +return -1 ; +if (symbol__init () <0 )return -1 ;if (!script_name)
tools/perf/util/strlist.c +15 -0
@@ -198,3 +198,18 @@ struct str_node *strlist__entry(const struct strlist *self, unsigned int idx)return NULL ; } + +int setup_list (struct strlist **list,const char *list_str, +const char *list_name) +{ +if (list_str ==NULL ) +return 0 ; + + *list =strlist__new (true, list_str); +if (!*list) { +pr_err ("problems parsing %s list\n" , list_name); +return -1 ; + } + +return 0 ; +}
tools/perf/util/strlist.h +2 -0
@@ -24,6 +24,8 @@ int strlist__add(struct strlist *self, const char *str);struct str_node *strlist__entry (const struct strlist *self,unsigned int idx);struct str_node *strlist__find (struct strlist *self,const char *entry); +int setup_list (struct strlist **list,const char *list_str, +const char *list_name);static inline bool strlist__has_entry (struct strlist *self,const char *entry) {
tools/perf/util/symbol.c +0 -14
@@ -2525,20 +2525,6 @@ size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp)return printed; } -static int setup_list (struct strlist **list,const char *list_str, -const char *list_name) -{ -if (list_str ==NULL ) -return 0 ; - - *list =strlist__new (true, list_str); -if (!*list) { -pr_err ("problems parsing %s list\n" , list_name); -return -1 ; - } -return 0 ; -} -static bool symbol__read_kptr_restrict (void ) {bool value = false;
Signature · 1 line
1.7.7.1
Em Fri, Nov 18, 2011 at 11:39:45AM -0700, David Ahern escreveu:
Quoted 7 lines
Allows collecting events system wide and then pulling out events for a specific task name(s). e.g,
perf script -c gnome-shell,gnome-terminal
Applies on top of:
https://lkml.org/lkml/2011/11/13/74
Can't we just reuse symbol_conf.comm_list[_str]?
- Arnaldo
Quoted 4 lines · Arnaldo Carvalho de Melo
Em Fri, Nov 18, 2011 at 11:39:45AM -0700, David Ahern escreveu:
Quoted 3 lines
Allows collecting events system wide and then pulling out events for a specific task name(s). e.g,
Quoted 8 lines
Quoted 4 lines
perf script -c gnome-shell,gnome-terminal
Applies on top of:
https://lkml.org/lkml/2011/11/13/74Can't we just reuse symbol_conf.comm_list[_str]?
- Arnaldo
For now, yes. I'll redo.
David
Em Mon, Nov 21, 2011 at 08:46:03AM -0700, David Ahern escreveu:
Quoted 7 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Em Fri, Nov 18, 2011 at 11:39:45AM -0700, David Ahern escreveu:
Quoted 5 lines
Allows collecting events system wide and then pulling out events for a specific task name(s). e.g,
perf script -c gnome-shell,gnome-terminal
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Applies on top of:
https://lkml.org/lkml/2011/11/13/74Can't we just reuse symbol_conf.comm_list[_str]?
- Arnaldo
For now, yes. I'll redo.
Great, if we have any need to have those in separate variables in the future, no problem we can do that at that point.
- Arnaldo