Minor improvements for brstackisn
One bug fix and one minor enhancement.
Note one of the patches will likely conflict with Kan's LBR events patchkit, but the conflict should be easy to resolve (or I will rebase if that one goes in first)
-Andi
PATCH 1/2 perf script: Add summary to brstackinsn / brstackdisasm
Print the total average IPC and total instructions for the last LBR entry. This can be useful to quickly estimate if a sample shows problematic code or not.
Signed-off-by Andi Kleen <[email protected]>
--- tools/perf/builtin-script.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
tools/perf/builtin-script.c +11 -3
@@ -1195,7 +1195,8 @@ static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en, struct perf_insn *x, u8 *inbuf, int len, int insn, FILE *fp, int *total_cycles, struct perf_event_attr *attr, - struct thread *thread) + struct thread *thread, + int total_insn, bool end) { int ilen = 0;int printed =fprintf (fp,"\t%016" PRIx64"\t" , ip);
@@ -1227,6 +1228,11 @@ static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en,if (insn) printed +=fprintf (fp," %.2f IPC" , (float )insn / en->flags.cycles); } +if (end) { + printed +=fprintf (fp," %.2f total-IPC %d total-insns" , + (float )total_insn / *total_cycles, + total_insn); + }return printed +fprintf (fp,"\n" ); }
@@ -1285,6 +1291,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,unsigned off;struct symbol *lastsym =NULL ;int total_cycles =0 ; +int total_insn =0 ;if (!(br && br->nr))return 0 ;
@@ -1307,7 +1314,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, x.cpumode, x.cpu, &lastsym, attr, fp); printed +=ip__fprintf_jump (entries[nr -1 ].from, &entries[nr -1 ], &x, buffer, len,0 , fp, &total_cycles, - attr, thread); + attr, thread,0 , false);if (PRINT_FIELD (SRCCODE )) printed +=print_srccode (thread, x.cpumode, entries[nr -1 ].from); }
@@ -1338,7 +1345,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, printed +=ip__fprintf_sym (ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp);if (ip == end) { printed +=ip__fprintf_jump (ip, &entries[i], &x, buffer + off, len - off, ++insn, fp, - &total_cycles, attr, thread); + &total_cycles, attr, thread, total_insn, i ==0 );if (PRINT_FIELD (SRCCODE )) printed +=print_srccode (thread, x.cpumode, ip);break ;
@@ -1346,6 +1353,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, ilen =0 ; printed +=fprintf (fp,"\t%016" PRIx64"\t" , ip); printed +=any_dump_insn (attr, &x, ip, buffer + off, len - off, &ilen, fp); + total_insn++;if (PRINT_FIELD (BRSTACKINSNLEN )) printed +=fprintf (fp,"\tilen: %d" , ilen); printed +=fprintf (fp,"\n" );
Signature · 1 line
2.45.2
PATCH 2/2 perf report: Handle non capstone case for calling perf script
In reply to Andi KleenWhen perf is built without capstone trying to displaying assembler sample context would error out. Use the older --xed variant in this case.
Fixes 659663f0bccc ("perf: script: prefer capstone to XED")
Signed-off-by Andi Kleen <[email protected]>
--- tools/perf/ui/browsers/scripts.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/ui/browsers/scripts.c +5 -0
@@ -107,8 +107,13 @@ static int list_scripts(char *script_name, bool *custom,if (evsel)attr_to_script (scriptc.extra_format, &evsel->core.attr);add_script_option ("Show individual samples" ,"" , &scriptc); +#ifdef NO_CAPSTONE +add_script_option ("Show individual samples with assembler" ,"-F +insn --xed" , + &scriptc); +#else add_script_option ("Show individual samples with assembler" ,"-F +disasm" , &scriptc); +#endif add_script_option ("Show individual samples with source" ,"-F +srcline,+srccode" , &scriptc);perf_config (scripts_config, &scriptc);
Signature · 1 line
2.45.2