More updates for event lists in perf list
This adds support for the event topics that Ingo requested, and replaces the earlier event group patch. JSON files now have a Topic header that is used by perf list to group events.
This applies on top of Sukadev's patchkit. In addition the Intel events also need to be pulled from
git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc.git perf/intel-json-files-3
-Andi
PATCH 1/3 perf, tools: Add override support for event list CPUID
From: Andi Kleen <[email protected]>
Add a PERF_CPUID variable to override the CPUID of the current CPU. This is useful for testing, so that all event lists can be tested on a single system.
v2: Fix double free in earlier version.
--- tools/perf/util/pmu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/util/pmu.c +5 -1
@@ -474,7 +474,11 @@ static int pmu_add_cpu_aliases(void *data)struct pmu_event *pe;char *cpuid; - cpuid =get_cpuid_str (); + cpuid =getenv ("PERF_CPUID" ); +if (cpuid) + cpuid =strdup (cpuid); +if (!cpuid) + cpuid =get_cpuid_str ();if (!cpuid)return 0 ;
Signature · 1 line
2.4.1
Re: [PATCH 1/3] perf, tools: Add override support for event list CPUID
Quoted 4 lines · Andi Kleen
From: Andi Kleen <[email protected]>
Add a
PERF_CPUIDvariable to override the CPUID of the current CPU. This is useful for testing, so that all event lists
.. within a current architecture (x86, powerpc) ..
Quoted 15 lines
can be tested on a single
system.v2: Fix double free in earlier version.
Signed-off-by Andi Kleen <[email protected]>--- tools/perf/util/pmu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)tools/perf/util/pmu.c +0
-0@@ -474,7 +474,11 @@ static int pmu_add_cpu_aliases(void *data)struct pmu_event *pe;
tools/perf/util/pmu.c static int pmu_add_cpu_aliases(void *data) · line 483
Quoted 10 lines
tools/perf/util/pmu.c +5
-1char *cpuid; - cpuid =get_cpuid_str (); + cpuid =getenv ("PERF_CPUID" ); +if (cpuid) + cpuid =strdup (cpuid); +if (!cpuid) + cpuid =get_cpuid_str ();if (!cpuid)return 0 ;
I tried and it's hard to actually say you're looking on another CPU events. Could we advertise the CPUID in perf list? Or at least some pr_debug print.
thanks,
jirka
PATCH 2/3 perf, tools: Support long descriptions with perf list -v
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Previously we were dropping the useful longer descriptions that some events have in the event list completely. This patch makes them appear with perf list.
Old perf list:
baclears:
baclears.all
[Counts the number of baclears]
vs new:
perf list -v:
...
baclears:
baclears.all
[The BACLEARS event counts the number of times the front end is resteered, mainly when
the Branch Prediction Unit cannot provide a correct prediction and this is corrected by the Branch Address Calculator at the front end. The BACLEARS.ANY event counts the number of baclears for any type of branch]
--- tools/perf/builtin-list.c | 9 ++++++--- tools/perf/pmu-events/jevents.c | 29 ++++++++++++++++++++--------- tools/perf/pmu-events/jevents.h | 2 +- tools/perf/pmu-events/pmu-events.h | 1 + tools/perf/util/parse-events.c | 4 ++-- tools/perf/util/parse-events.h | 2 +- tools/perf/util/pmu.c | 17 ++++++++++++----- tools/perf/util/pmu.h | 4 +++- 8 files changed, 46 insertions(+), 22 deletions(-)
tools/perf/builtin-list.c +6 -3
@@ -22,10 +22,13 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) {int i;bool raw_dump = false; +bool long_desc_flag = false;struct option list_options[] = {OPT_BOOLEAN (0 ,"raw-dump" , &raw_dump,"Dump raw events" ),OPT_BOOLEAN ('d' ,"desc" , &desc_flag,"Print extra event descriptions. --no-desc to not print." ), +OPT_BOOLEAN ('v' ,"long-desc" , &long_desc_flag, +"Print longer event descriptions." ),OPT_END () };const char *const list_usage[] = {
@@ -44,7 +47,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)printf ("\nList of pre-defined events (to be used in -e):\n\n" );if (argc ==0 ) { -print_events (NULL , raw_dump, !desc_flag); +print_events (NULL , raw_dump, !desc_flag, long_desc_flag);return 0 ; }
@@ -63,13 +66,13 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) strcmp(argv[i], "hwcache") == 0)print_hwcache_events (NULL , raw_dump); else if (strcmp(argv[i], "pmu") == 0) - print_pmu_events(NULL, raw_dump, !desc_flag); + print_pmu_events(NULL, raw_dump, !desc_flag, long_desc_flag); else {char *sep =strchr (argv[i],':' ), *s;int sep_idx;if (sep ==NULL ) { -print_events (argv[i], raw_dump, !desc_flag); +print_events (argv[i], raw_dump, !desc_flag, long_desc_flag);continue ; } sep_idx = sep - argv[i];
tools/perf/pmu-events/jevents.c +20 -9
@@ -202,7 +202,7 @@ static void print_events_table_prefix(FILE *fp, const char *tblname) }static int print_events_table_entry (void *data,char *name,char *event, -char *desc) +char *desc,char *long_desc) {FILE *outfp = data;/*
@@ -214,7 +214,8 @@ static int print_events_table_entry(void *data, char *name, char *event,fprintf (outfp,"\t.name = \"%s\",\n" , name);fprintf (outfp,"\t.event = \"%s\",\n" , event);fprintf (outfp,"\t.desc = \"%s\",\n" , desc); - +if (long_desc && long_desc[0 ]) +fprintf (outfp,"\t.long_desc = \"%s\"" , long_desc);fprintf (outfp,"},\n" );return 0 ;
@@ -234,7 +235,7 @@ static void print_events_table_suffix(FILE *outfp)/* Call func with each event in the json file */ int json_events (const char *fn, -int (*func)(void *data,char *name,char *event,char *desc), +int (*func)(void *data,char *name,char *event,char *desc,char *long_desc),void *data) {int err = -EIO ;
@@ -252,7 +253,8 @@ int json_events(const char *fn,EXPECT (tokens->type ==JSMN_ARRAY , tokens,"expected top level array" ); tok = tokens +1 ;for (i =0 ; i < tokens->size; i++) { -char *event =NULL , *desc =NULL , *name =NULL ; +char *event =NULL , *desc =NULL , *name =NULL , *long_desc =NULL ; +char *extra_desc =NULL ;struct msrmap *msr =NULL ;jsmntok_t *msrval =NULL ;jsmntok_t *precise =NULL ;
@@ -278,6 +280,9 @@ int json_events(const char *fn, }else if (json_streq (map, field,"BriefDescription" )) {addfield (map, &desc,"" ,"" , val);fixdesc (desc); + }else if (json_streq (map, field,"PublicDescription" )) { +addfield (map, &long_desc,"" ,"" , val); +fixdesc (long_desc); }else if (json_streq (map, field,"PEBS" ) && nz) { precise = val; }else if (json_streq (map, field,"MSRIndex" ) && nz) {
@@ -286,10 +291,10 @@ int json_events(const char *fn, msrval = val; }else if (json_streq (map, field,"Errata" ) && !json_streq (map, val,"null" )) { -addfield (map, &desc,". " , +addfield (map, &extra_desc,". " ," Spec update: " , val); }else if (json_streq (map, field,"Data_LA" ) && nz) { -addfield (map, &desc,". " , +addfield (map, &extra_desc,". " ," Supports address when precise" ,NULL ); }
@@ -297,19 +302,25 @@ int json_events(const char *fn, }if (precise && !strstr (desc,"(Precise Event)" )) {if (json_streq (map, precise,"2" )) -addfield (map, &desc," " ,"(Must be precise)" , +addfield (map, &extra_desc," " ,"(Must be precise)" ,NULL );else -addfield (map, &desc," " , +addfield (map, &extra_desc," " ,"(Precise event)" ,NULL ); } +if (desc && extra_desc) +addfield (map, &desc," " , extra_desc,NULL ); +if (long_desc && extra_desc) +addfield (map, &long_desc," " , extra_desc,NULL );if (msr !=NULL )addfield (map, &event,"," , msr->pname, msrval);fixname (name); - err =func (data, name, event, desc); + err =func (data, name, event, desc, long_desc);free (event);free (desc);free (name); +free (extra_desc); +free (long_desc);if (err)break ; tok += j;
tools/perf/pmu-events/jevents.h +1 -1
@@ -2,7 +2,7 @@#define JEVENTS_H 1int json_events (const char *fn, -int (*func)(void *data,char *name,char *event,char *desc), +int (*func)(void *data,char *name,char *event,char *desc,char *long_desc),void *data);char *get_cpu_str (void );
tools/perf/pmu-events/pmu-events.h +1 -0
@@ -8,6 +8,7 @@ struct pmu_event {const char *name;const char *event;const char *desc; +const char *long_desc; };/*
tools/perf/util/parse-events.c +2 -2
@@ -1419,7 +1419,7 @@ out_enomem:/* * Print the help text for the event symbols: */ -void print_events (const char *event_glob,bool name_only,bool quiet_flag) +void print_events (const char *event_glob,bool name_only,bool quiet_flag,bool long_desc) {print_symbol_events (event_glob,PERF_TYPE_HARDWARE , event_symbols_hw,PERF_COUNT_HW_MAX , name_only);
@@ -1429,7 +1429,7 @@ void print_events(const char *event_glob, bool name_only, bool quiet_flag)print_hwcache_events (event_glob, name_only); -print_pmu_events (event_glob, name_only, quiet_flag); +print_pmu_events (event_glob, name_only, quiet_flag, long_desc);if (event_glob !=NULL )return ;
tools/perf/util/parse-events.h +1 -1
@@ -115,7 +115,7 @@ void parse_events_update_lists(struct list_head *list_event, struct list_head *list_all);void parse_events_error (void *data,void *scanner,char const *msg); -void print_events (const char *event_glob,bool name_only,bool quiet); +void print_events (const char *event_glob,bool name_only,bool quiet,bool long_desc);struct event_symbol {const char *symbol;
tools/perf/util/pmu.c +12 -5
@@ -201,7 +201,8 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,return 0 ; } -static int __perf_pmu__new_alias (struct list_head *list,char *name,char *dir,char *desc__maybe_unused ,char *val) +static int __perf_pmu__new_alias (struct list_head *list,char *name,char *dir,char *desc__maybe_unused ,char *val, +char *long_desc) {struct perf_pmu_alias *alias;int ret;
@@ -234,6 +235,9 @@ static int __perf_pmu__new_alias(struct list_head *list, char *name, char *dir, } alias->desc = desc ?strdup (desc) :NULL ; + alias->long_desc = long_desc ? +strdup (long_desc) : + desc ?strdup (desc) :NULL ;list_add_tail (&alias->list, list);
@@ -250,7 +254,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FIreturn -EINVAL ; buf[ret] =0 ; -return __perf_pmu__new_alias (list, name, dir,NULL , buf); +return __perf_pmu__new_alias (list, name, dir,NULL , buf,NULL ); }static inline bool pmu_alias_info_file (char *name)
@@ -503,7 +507,8 @@ static int pmu_add_cpu_aliases(void *data)/* need type casts to override 'const' */ __perf_pmu__new_alias (head, (char *)pe->name,NULL , - (char *)pe->desc, (char *)pe->event); + (char *)pe->desc, (char *)pe->event, + (char *)pe->long_desc); }free (cpuid);
@@ -976,7 +981,8 @@ static void wordwrap(char *s, int start, int max, int corr) } } -void print_pmu_events (const char *event_glob,bool name_only,bool quiet_flag) +void print_pmu_events (const char *event_glob,bool name_only,bool quiet_flag, +bool long_desc) {struct perf_pmu *pmu;struct perf_pmu_alias *alias;
@@ -1021,7 +1027,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag) pmu, alias); aliases[j].name =strdup (aliases[j].name);/* failure harmless */ - aliases[j].desc = alias->desc; + aliases[j].desc = long_desc ? alias->long_desc : + alias->desc; j++; }if (pmu->selectable) {
tools/perf/util/pmu.h +3 -1
@@ -38,6 +38,7 @@ struct perf_pmu_info {struct perf_pmu_alias {char *name;char *desc; +char *long_desc;struct list_head terms;/* HEAD struct parse_events_term -> list */ struct list_head list;/* ELEM */ char unit[UNIT_MAX_LEN +1 ];
@@ -67,7 +68,8 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);struct perf_pmu *perf_pmu__scan (struct perf_pmu *pmu); -void print_pmu_events (const char *event_glob,bool name_only,bool quiet); +void print_pmu_events (const char *event_glob,bool name_only,bool quiet, +bool long_desc);bool pmu_have_event (const char *pname,const char *name); int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
Signature · 1 line
2.4.1
PATCH 3/3 perf, tools: Add support for event list topics
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Add support to group the output of perf list by the Topic field in the JSON file.
Example output:
% perf list
...
Cache:
l1d.replacement
[L1D data line replacements]
l1d_pend_miss.pending
[L1D miss oustandings duration in cycles]
l1d_pend_miss.pending_cycles
[Cycles with L1D load Misses outstanding]
l2_l1d_wb_rqsts.all
[Not rejected writebacks from L1D to L2 cache lines in any state]
l2_l1d_wb_rqsts.hit_e
[Not rejected writebacks from L1D to L2 cache lines in E state]
l2_l1d_wb_rqsts.hit_m
[Not rejected writebacks from L1D to L2 cache lines in M state]
...
Pipeline:
arith.fpu_div
[Divide operations executed]
arith.fpu_div_active
[Cycles when divider is busy executing divide operations]
baclears.any
[Counts the total number when the front end is resteered, mainly when the BPU cannot provide a correct prediction and this is corrected by
other branch handling mechanisms at the front end]
br_inst_exec.all_branches
[Speculative and retired branches]
br_inst_exec.all_conditional
[Speculative and retired macro-conditional branches]
br_inst_exec.all_direct_jmp
[Speculative and retired macro-unconditional branches excluding calls and indirects]
br_inst_exec.all_direct_near_call
[Speculative and retired direct near calls]
br_inst_exec.all_indirect_jump_non_call_ret
--- tools/perf/pmu-events/jevents.c | 16 +++++++++++----- tools/perf/pmu-events/jevents.h | 3 ++- tools/perf/pmu-events/pmu-events.h | 1 + tools/perf/util/pmu.c | 34 ++++++++++++++++++++++++---------- tools/perf/util/pmu.h | 1 + 5 files changed, 39 insertions(+), 16 deletions(-)
tools/perf/pmu-events/jevents.c +11 -5
@@ -202,7 +202,7 @@ static void print_events_table_prefix(FILE *fp, const char *tblname) }static int print_events_table_entry (void *data,char *name,char *event, -char *desc,char *long_desc) +char *desc,char *long_desc,char *topic) {FILE *outfp = data;/*
@@ -215,7 +215,9 @@ static int print_events_table_entry(void *data, char *name, char *event,fprintf (outfp,"\t.event = \"%s\",\n" , event);fprintf (outfp,"\t.desc = \"%s\",\n" , desc);if (long_desc && long_desc[0 ]) -fprintf (outfp,"\t.long_desc = \"%s\"" , long_desc); +fprintf (outfp,"\t.long_desc = \"%s\",\n" , long_desc); +if (topic) +fprintf (outfp,"\t.topic = \"%s\",\n" , topic);fprintf (outfp,"},\n" );return 0 ;
@@ -235,7 +237,8 @@ static void print_events_table_suffix(FILE *outfp)/* Call func with each event in the json file */ int json_events (const char *fn, -int (*func)(void *data,char *name,char *event,char *desc,char *long_desc), +int (*func)(void *data,char *name,char *event,char *desc, +char *long_desc,char *topic),void *data) {int err = -EIO ;
@@ -254,7 +257,7 @@ int json_events(const char *fn, tok = tokens +1 ;for (i =0 ; i < tokens->size; i++) {char *event =NULL , *desc =NULL , *name =NULL , *long_desc =NULL ; -char *extra_desc =NULL ; +char *extra_desc =NULL , *topic =NULL ;struct msrmap *msr =NULL ;jsmntok_t *msrval =NULL ;jsmntok_t *precise =NULL ;
@@ -293,6 +296,8 @@ int json_events(const char *fn, !json_streq(map, val, "null")) {addfield (map, &extra_desc,". " ," Spec update: " , val); + } else if (json_streq(map, field, "Topic")) { +addfield (map, &topic,"" ,"" , val); } else if (json_streq(map, field, "Data_LA") && nz) { addfield(map, &extra_desc, ". ", " Supports address when precise",
@@ -315,12 +320,13 @@ int json_events(const char *fn,if (msr !=NULL )addfield (map, &event,"," , msr->pname, msrval);fixname (name); - err =func (data, name, event, desc, long_desc); + err =func (data, name, event, desc, long_desc, topic);free (event);free (desc);free (name);free (extra_desc);free (long_desc); +free (topic);if (err)break ; tok += j;
tools/perf/pmu-events/jevents.h +2 -1
@@ -2,7 +2,8 @@#define JEVENTS_H 1int json_events (const char *fn, -int (*func)(void *data,char *name,char *event,char *desc,char *long_desc), +int (*func)(void *data,char *name,char *event,char *desc, +char *long_desc,char *topic),void *data);char *get_cpu_str (void );
tools/perf/pmu-events/pmu-events.h +1 -0
@@ -9,6 +9,7 @@ struct pmu_event {const char *event;const char *desc;const char *long_desc; +const char *topic; };/*
tools/perf/util/pmu.c +24 -10
@@ -202,7 +202,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias, }static int __perf_pmu__new_alias (struct list_head *list,char *name,char *dir,char *desc__maybe_unused ,char *val, -char *long_desc) +char *long_desc,char *topic) {struct perf_pmu_alias *alias;int ret;
@@ -238,6 +238,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *name, char *dir, alias->long_desc = long_desc ?strdup (long_desc) : desc ?strdup (desc) :NULL ; + alias->topic = topic ?strdup (topic) :NULL ;list_add_tail (&alias->list, list);
@@ -254,7 +255,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FIreturn -EINVAL ; buf[ret] =0 ; -return __perf_pmu__new_alias (list, name, dir,NULL , buf,NULL ); +return __perf_pmu__new_alias (list, name, dir,NULL , buf,NULL ,NULL ); }static inline bool pmu_alias_info_file (char *name)
@@ -508,7 +509,8 @@ static int pmu_add_cpu_aliases(void *data)/* need type casts to override 'const' */ __perf_pmu__new_alias (head, (char *)pe->name,NULL , (char *)pe->desc, (char *)pe->event, - (char *)pe->long_desc); + (char *)pe->long_desc, + (char *)pe->topic); }free (cpuid);
@@ -943,19 +945,25 @@ static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,return buf; } -struct pair { +struct sevent {char *name;char *desc; +char *topic; }; -static int cmp_pair (const void *a,const void *b) +static int cmp_sevent (const void *a,const void *b) { -const struct pair *as = a; -const struct pair *bs = b; +const struct sevent *as = a; +const struct sevent *bs = b;/* Put extra events last */ if (!!as->desc != !!bs->desc)return !!as->desc - !!bs->desc; +if (as->topic && bs->topic) { +int n =strcmp (as->topic, bs->topic); +if (n) +return n; + }return strcmp (as->name, bs->name); }
@@ -989,9 +997,10 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,char buf[1024 ];int printed =0 ;int len, j; -struct pair *aliases; +struct sevent *aliases;int numdesc =0 ;int columns =pager_get_columns (); +char *topic =NULL ; pmu =NULL ; len =0 ;
@@ -1001,7 +1010,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,if (pmu->selectable) len++; } - aliases =zalloc (sizeof (struct pair ) * len); + aliases =zalloc (sizeof (struct sevent ) * len);if (!aliases) goto out_enomem; pmu =NULL ;
@@ -1029,6 +1038,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,/* failure harmless */ aliases[j].desc = long_desc ? alias->long_desc : alias->desc; + aliases[j].topic = alias->topic; j++; }if (pmu->selectable) {
@@ -1040,7 +1050,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, } } len = j; -qsort (aliases, len,sizeof (struct pair ), cmp_pair); +qsort (aliases, len,sizeof (struct sevent ), cmp_sevent);for (j =0 ; j < len; j++) {if (name_only) {printf ("%s " , aliases[j].name);
@@ -1049,6 +1059,10 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,if (aliases[j].desc && !quiet_flag) {if (numdesc++ ==0 )printf ("\n" ); +if (aliases[j].topic && (!topic ||strcmp (topic, aliases[j].topic))) { +printf ("%s%s:\n" , topic ?"\n" :"" , aliases[j].topic); + topic = aliases[j].topic; + }printf (" %-50s\n" , aliases[j].name);printf ("%*s" ,8 ,"[" );wordwrap (aliases[j].desc,8 , columns,0 );
tools/perf/util/pmu.h +1 -0
@@ -39,6 +39,7 @@ struct perf_pmu_alias {char *name;char *desc;char *long_desc; +char *topic;struct list_head terms;/* HEAD struct parse_events_term -> list */ struct list_head list;/* ELEM */ char unit[UNIT_MAX_LEN +1 ];
Signature · 1 line
2.4.1
Andi Kleen [[email protected]] wrote:
| This adds support for the event topics that Ingo requested, and | replaces the earlier event group patch. JSON files now have a Topic | header that is used by perf list to group events. | | This applies on top of Sukadev's patchkit. In addition | the Intel events also need to be pulled from | | git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc.git perf/intel-json-files-3
I addressed comments, rebased to Arnaldo's tree and pushed all patches to:
https://github.com/sukadev/linux.git
Branches:
json-v12 (code only) json-files-3 (x86 and powerpc data files only)
Please let me know if they work for you. I will email the patches for the code in a day or so.
Sukadev
Quoted 10 lines · Sukadev Bhattiprolu
Andi Kleen [[email protected]] wrote:
| This adds support for the event topics that Ingo requested, and | replaces the earlier event group patch. JSON files now have a Topic | header that is used by perf list to group events. | | This applies on top of Sukadev's patchkit. In addition | the Intel events also need to be pulled from | | git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc.git perf/intel-json-files-3
Quoted 8 lines
I addressed comments, rebased to Arnaldo's tree and pushed all patches to:
https://github.com/sukadev/linux.git
Branches:
json-v12 (code only) json-files-3 (x86 and powerpc data files only)
please make also one merged branch and advertise
it in the patchset.. so people can do just single
checkout and try the code with data files
thanks,
jirka