perf util: Move block_pair_cmp to block-info
PATCH v2 1/3 perf util: Move block_pair_cmp to block-info
block_pair_cmp() is a function which is used to compare two blocks. Moving it from builtin-diff.c to block-info.c to let it be used by other builtins.
In block_pair_cmp, there is a minor change. It checks valid for map, dso and sym first. If they are invalid, we will not compare the address because the address might not make sense.
v2:
---
New patch created in v2
--- tools/perf/builtin-diff.c | 17 ----------------- tools/perf/util/block-info.c | 23 +++++++++++++++++++++++ tools/perf/util/block-info.h | 2 ++ 3 files changed, 25 insertions(+), 17 deletions(-)
tools/perf/builtin-diff.c +0 -17
@@ -572,23 +572,6 @@ static void init_block_hist(struct block_hist *bh) bh->valid = true; } -static int block_pair_cmp (struct hist_entry *a,struct hist_entry *b) -{ -struct block_info *bi_a = a->block_info; -struct block_info *bi_b = b->block_info; -int cmp; - -if (!bi_a->sym || !bi_b->sym) -return -1 ; - - cmp =strcmp (bi_a->sym->name, bi_b->sym->name); - -if ((!cmp) && (bi_a->start == bi_b->start) && (bi_a->end == bi_b->end)) -return 0 ; - -return -1 ; -} -static struct hist_entry *get_block_pair (struct hist_entry *he,struct hists *hists_pair) {
tools/perf/util/block-info.c +23 -0
@@ -475,3 +475,26 @@ float block_info__total_cycles_percent(struct hist_entry *he)return 0.0 ; } + +int block_pair_cmp (struct hist_entry *pair,struct hist_entry *he) +{ +struct block_info *bi_p = pair->block_info; +struct block_info *bi_h = he->block_info; +struct map_symbol *ms_p = &pair->ms; +struct map_symbol *ms_h = &he->ms; +int cmp; + +if (!ms_p->map || !ms_p->map->dso || !ms_p->sym || + !ms_h->map || !ms_h->map->dso || !ms_h->sym) { +return -1 ; + } + + cmp =strcmp (ms_p->sym->name, ms_h->sym->name); +if (cmp) +return -1 ; + +if ((bi_p->start == bi_h->start) && (bi_p->end == bi_h->end)) +return 0 ; + +return -1 ; +}
tools/perf/util/block-info.h +2 -0
@@ -76,4 +76,6 @@ int report__browse_block_hists(struct block_hist *bh, float min_percent,float block_info__total_cycles_percent (struct hist_entry *he); +int block_pair_cmp (struct hist_entry *pair,struct hist_entry *he); +#endif /* __PERF_BLOCK_H */
Signature · 1 line
2.17.1
PATCH v2 2/3 perf util: Flexible to set block info output formats
Currently we use a predefined array to set the block info output formats, it's fixed and inflexible.
This patch adds two parameters "block_hpps" and "nr_hpps" in block_info__create_report and other static functions, in order to let user decide which columns to report and with specified report ordering. It should be more flexible.
Buffers will be allocated to contain the new fmts, of course, we need to release them before perf exits.
v2:
---
New patch created in v2.
--- tools/perf/builtin-report.c | 25 +++++++++++--- tools/perf/util/block-info.c | 64 ++++++++++++++++++++++++++---------- tools/perf/util/block-info.h | 12 +++++-- 3 files changed, 76 insertions(+), 25 deletions(-)
tools/perf/builtin-report.c +20 -5
@@ -104,6 +104,7 @@ struct report {bool symbol_ipc;bool total_cycles_mode;struct block_report *block_reports; +int nr_block_reports; };static int report__config (const char *var,const char *value,void *cb)
@@ -503,7 +504,7 @@ static int perf_evlist__tui_block_hists_browse(struct evlist *evlist, ret =report__browse_block_hists (&rep->block_reports[i++].hist, rep->min_percent, pos, &rep->session->header.env, - &rep->annotation_opts); + &rep->annotation_opts, true);if (ret !=0 )return ret; }
@@ -536,7 +537,7 @@ static int perf_evlist__tty_browse_hists(struct evlist *evlist,if (rep->total_cycles_mode) {report__browse_block_hists (&rep->block_reports[i++].hist, rep->min_percent, pos, -NULL ,NULL ); +NULL ,NULL , true);continue ; }
@@ -966,8 +967,19 @@ static int __cmd_report(struct report *rep)report__output_resort (rep);if (rep->total_cycles_mode) { +int block_hpps[6 ] = { +PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT , +PERF_HPP_REPORT__BLOCK_LBR_CYCLES , +PERF_HPP_REPORT__BLOCK_CYCLES_PCT , +PERF_HPP_REPORT__BLOCK_AVG_CYCLES , +PERF_HPP_REPORT__BLOCK_RANGE , +PERF_HPP_REPORT__BLOCK_DSO , + }; + rep->block_reports =block_info__create_report (session->evlist, - rep->total_cycles); + rep->total_cycles, + block_hpps,6 , + &rep->nr_block_reports);if (!rep->block_reports)return -1 ; }
@@ -1543,8 +1555,11 @@ int cmd_report(int argc, const char **argv)zfree (&report.ptime_range); } -if (report.block_reports) -zfree (&report.block_reports); +if (report.block_reports) { +block_info__free_report (report.block_reports, + report.nr_block_reports); + report.block_reports =NULL ; + }zstd_fini (&(session->zstd_data));perf_session__delete (session);
tools/perf/util/block-info.c +47 -17
125 lines not on this page · raw message
tools/perf/util/block-info.h +9 -3
@@ -44,7 +44,8 @@ enum {struct block_report {struct block_hist hist;u64 cycles; -struct block_fmt fmts[PERF_HPP_REPORT__BLOCK_MAX_INDEX ]; +struct block_fmt *fmts; +int nr_fmts; };struct block_hist ;
@@ -68,11 +69,16 @@ int block_info__process_sym(struct hist_entry *he, struct block_hist *bh, u64 *block_cycles_aggr, u64 total_cycles);struct block_report *block_info__create_report (struct evlist *evlist, -u64 total_cycles); +u64 total_cycles, +int *block_hpps,int nr_hpps, +int *nr_reps); + +void block_info__free_report (struct block_report *reps,int nr_reps);int report__browse_block_hists (struct block_hist *bh,float min_percent,struct evsel *evsel,struct perf_env *env, -struct annotation_options *annotation_opts); +struct annotation_options *annotation_opts, +bool release);float block_info__total_cycles_percent (struct hist_entry *he);
Signature · 1 line
2.17.1
Re: [PATCH v2 2/3] perf util: Flexible to set block info output formats
Quoted 54 lines · Jin Yao
Currently we use a predefined array to set the block info output formats, it's fixed and inflexible.
This patch adds two parameters "
block_hpps" and "nr_hpps" inblock_info__create_reportand other static functions, in order to let user decide which columns to report and with specified report ordering. It should be more flexible.Buffers will be allocated to contain the new fmts, of course, we need to release them before perf exits.
v2:
---
New patch created in v2.Signed-off-by Jin Yao <[email protected]>--- tools/perf/builtin-report.c | 25 +++++++++++--- tools/perf/util/block-info.c | 64 ++++++++++++++++++++++++++---------- tools/perf/util/block-info.h | 12 +++++-- 3 files changed, 76 insertions(+), 25 deletions(-)tools/perf/builtin-report.c +3
-2@@ -104,6 +104,7 @@ struct report {bool symbol_ipc;bool total_cycles_mode;struct block_report *block_reports; +int nr_block_reports; };static int report__config (const char *var,const char *value,void *cb)@@ -503,7 +504,7 @@ static int perf_evlist__tui_block_hists_browse(struct evlist *evlist, ret =report__browse_block_hists (&rep->block_reports[i++].hist, rep->min_percent, pos, &rep->session->header.env, - &rep->annotation_opts); + &rep->annotation_opts, true);if (ret !=0 )return ret; }@@ -536,7 +537,7 @@ static int perf_evlist__tty_browse_hists(struct evlist *evlist,if (rep->total_cycles_mode) {report__browse_block_hists (&rep->block_reports[i++].hist, rep->min_percent, pos, -NULL ,NULL ); +NULL ,NULL , true);continue ; }@@ -966,8 +967,19 @@ static int __cmd_report(struct report *rep)report__output_resort (rep);
tools/perf/builtin-report.c static int __cmd_report(struct report *rep) · line 977
Quoted 10 lines
tools/perf/builtin-report.c +8
-0if (rep->total_cycles_mode) { +int block_hpps[6 ] = { +PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT , +PERF_HPP_REPORT__BLOCK_LBR_CYCLES , +PERF_HPP_REPORT__BLOCK_CYCLES_PCT , +PERF_HPP_REPORT__BLOCK_AVG_CYCLES , +PERF_HPP_REPORT__BLOCK_RANGE , +PERF_HPP_REPORT__BLOCK_DSO , + };
I'd understand this change if there was another place in the code using this, but it's not part of this patchset.. is it comming later?
thanks,
jirka
Re: [PATCH v2 2/3] perf util: Flexible to set block info output formats
Quoted 56 lines · Jiri Olsa
Quoted 55 lines · Jin Yao
Currently we use a predefined array to set the block info output formats, it's fixed and inflexible.
This patch adds two parameters "
block_hpps" and "nr_hpps" inblock_info__create_reportand other static functions, in order to let user decide which columns to report and with specified report ordering. It should be more flexible.Buffers will be allocated to contain the new fmts, of course, we need to release them before perf exits.
v2:
---
New patch created in v2.Signed-off-by Jin Yao <[email protected]>--- tools/perf/builtin-report.c | 25 +++++++++++--- tools/perf/util/block-info.c | 64 ++++++++++++++++++++++++++---------- tools/perf/util/block-info.h | 12 +++++-- 3 files changed, 76 insertions(+), 25 deletions(-)tools/perf/builtin-report.c +3
-2@@ -104,6 +104,7 @@ struct report {bool symbol_ipc;bool total_cycles_mode;struct block_report *block_reports; +int nr_block_reports; };static int report__config (const char *var,const char *value,void *cb)@@ -503,7 +504,7 @@ static int perf_evlist__tui_block_hists_browse(struct evlist *evlist, ret =report__browse_block_hists (&rep->block_reports[i++].hist, rep->min_percent, pos, &rep->session->header.env, - &rep->annotation_opts); + &rep->annotation_opts, true);if (ret !=0 )return ret; }@@ -536,7 +537,7 @@ static int perf_evlist__tty_browse_hists(struct evlist *evlist,if (rep->total_cycles_mode) {report__browse_block_hists (&rep->block_reports[i++].hist, rep->min_percent, pos, -NULL ,NULL ); +NULL ,NULL , true);continue ; }@@ -966,8 +967,19 @@ static int __cmd_report(struct report *rep)report__output_resort (rep);
Quoted 13 lines
tools/perf/builtin-report.c static int __cmd_report(struct report *rep) · line 977
Quoted 9 lines
tools/perf/builtin-report.c +8
-0if (rep->total_cycles_mode) { +int block_hpps[6 ] = { +PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT , +PERF_HPP_REPORT__BLOCK_LBR_CYCLES , +PERF_HPP_REPORT__BLOCK_CYCLES_PCT , +PERF_HPP_REPORT__BLOCK_AVG_CYCLES , +PERF_HPP_REPORT__BLOCK_RANGE , +PERF_HPP_REPORT__BLOCK_DSO , + };I'd understand this change if there was another place in the code using this, but it's not part of this patchset.. is it comming later?
Yes, you guessed it. :)
I will have some follow-up patches, maybe post some weeks later.
Thanks
Jin Yao
Quoted 3 lines
thanks,
jirka
PATCH v2 3/3 perf util: Support color ops to print block percents in color
In reply to Jin YaoIt would be nice to print the block percents with colors.
This patch supports the 'Sampled Cycles%' and 'Avg Cycles%' printed in colors.
For example,
perf record -b ...
perf report --total-cycles or perf report --total-cycles --stdio
percent > 5%, colored in red percent > 0.5%, colored in green percent < 0.5%, default color
v2:
---
No functional change
--- tools/perf/util/block-info.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
tools/perf/util/block-info.c +15 -10
@@ -185,6 +185,17 @@ static int block_column_width(struct perf_hpp_fmt *fmt,return block_fmt->width; } +static int color_pct (struct perf_hpp *hpp,int width,double pct) +{ +#ifdef HAVE_SLANG_SUPPORT +if (use_browser) { +return __hpp__slsmg_color_printf (hpp,"%*.2f%%" , + width -1 , pct); + } +#endif +return hpp_color_scnprintf (hpp,"%*.2f%%" , width -1 , pct); +} +static int block_total_cycles_pct_entry (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp,struct hist_entry *he)
@@ -192,14 +203,11 @@ static int block_total_cycles_pct_entry(struct perf_hpp_fmt *fmt, struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);struct block_info *bi = he->block_info;double ratio =0.0 ; -char buf[16 ];if (block_fmt->total_cycles) ratio = (double )bi->cycles / (double )block_fmt->total_cycles; -sprintf (buf,"%.2f%%" ,100.0 * ratio); - -return scnprintf (hpp->buf, hpp->size,"%*s" , block_fmt->width, buf); +return color_pct (hpp, block_fmt->width,100.0 * ratio); } static int64_t block_total_cycles_pct_sort(struct perf_hpp_fmt *fmt,
@@ -252,16 +260,13 @@ static int block_cycles_pct_entry(struct perf_hpp_fmt *fmt,struct block_info *bi = he->block_info;double ratio =0.0 ;u64 avg; -char buf[16 ];if (block_fmt->block_cycles && bi->num_aggr) { avg = bi->cycles_aggr / bi->num_aggr; ratio = (double )avg / (double )block_fmt->block_cycles; } -sprintf (buf,"%.2f%%" ,100.0 * ratio); - -return scnprintf (hpp->buf, hpp->size,"%*s" , block_fmt->width, buf); +return color_pct (hpp, block_fmt->width,100.0 * ratio); } static int block_avg_cycles_entry(struct perf_hpp_fmt *fmt,
@@ -348,7 +353,7 @@ static void hpp_register(struct block_fmt *block_fmt, int idx,switch (idx) {case PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT : - fmt->entry = block_total_cycles_pct_entry; + fmt->color = block_total_cycles_pct_entry; fmt->cmp = block_info__cmp; fmt->sort = block_total_cycles_pct_sort;break ;
@@ -356,7 +361,7 @@ static void hpp_register(struct block_fmt *block_fmt, int idx, fmt->entry = block_cycles_lbr_entry;break ;case PERF_HPP_REPORT__BLOCK_CYCLES_PCT : - fmt->entry = block_cycles_pct_entry; + fmt->color = block_cycles_pct_entry;break ;case PERF_HPP_REPORT__BLOCK_AVG_CYCLES : fmt->entry = block_avg_cycles_entry;
Signature · 1 line
2.17.1
Quoted 7 lines · Jin Yao
block_pair_cmp()is a function which is used to compare two blocks. Moving it frombuiltin-diff.ctoblock-info.cto let it be used by other builtins.In
block_pair_cmp, there is a minor change. It checks valid for map, dso and sym first. If they are invalid, we will not compare the address because the address might not make sense.
please separate the change as well, it's hard to track what you did when the whole function is moved
Quoted 55 lines
v2:
---
New patch created in v2Signed-off-by Jin Yao <[email protected]>--- tools/perf/builtin-diff.c | 17 ----------------- tools/perf/util/block-info.c | 23 +++++++++++++++++++++++ tools/perf/util/block-info.h | 2 ++ 3 files changed, 25 insertions(+), 17 deletions(-)tools/perf/builtin-diff.c +0
-17@@ -572,23 +572,6 @@ static void init_block_hist(struct block_hist *bh) bh->valid = true; } -static int block_pair_cmp (struct hist_entry *a,struct hist_entry *b) -{ -struct block_info *bi_a = a->block_info; -struct block_info *bi_b = b->block_info; -int cmp; - -if (!bi_a->sym || !bi_b->sym) -return -1 ; - - cmp =strcmp (bi_a->sym->name, bi_b->sym->name); - -if ((!cmp) && (bi_a->start == bi_b->start) && (bi_a->end == bi_b->end)) -return 0 ; - -return -1 ; -} -static struct hist_entry *get_block_pair (struct hist_entry *he,struct hists *hists_pair) {tools/perf/util/block-info.c +7
-0@@ -475,3 +475,26 @@ float block_info__total_cycles_percent(struct hist_entry *he)return 0.0 ; } + +int block_pair_cmp (struct hist_entry *pair,struct hist_entry *he) +{ +struct block_info *bi_p = pair->block_info; +struct block_info *bi_h = he->block_info; +struct map_symbol *ms_p = &pair->ms; +struct map_symbol *ms_h = &he->ms;
tools/perf/util/block-info.c float block_info__total_cycles_percent(struct hist_entry *he) · line 494
Quoted 10 lines
tools/perf/util/block-info.c +10
-0+int cmp; + +if (!ms_p->map || !ms_p->map->dso || !ms_p->sym || + !ms_h->map || !ms_h->map->dso || !ms_h->sym) { +return -1 ; + } + + cmp =strcmp (ms_p->sym->name, ms_h->sym->name); +if (cmp) +return -1 ;
should this return cmp? also you don't mention this change in the changelog
thanks,
jirka
Quoted 5 lines · Jiri Olsa
Quoted 4 lines · Jin Yao
block_pair_cmp()is a function which is used to compare two blocks. Moving it frombuiltin-diff.ctoblock-info.cto let it be used by other builtins.
Quoted 7 lines
Quoted 3 lines
In
block_pair_cmp, there is a minor change. It checks valid for map, dso and sym first. If they are invalid, we will not compare the address because the address might not make sense.please separate the change as well, it's hard to track what you did when the whole function is moved
Got it, thanks! I will separate this too.
Quoted 59 lines
Quoted 59 lines
v2:
---
New patch created in v2Signed-off-by Jin Yao <[email protected]>--- tools/perf/builtin-diff.c | 17 ----------------- tools/perf/util/block-info.c | 23 +++++++++++++++++++++++ tools/perf/util/block-info.h | 2 ++ 3 files changed, 25 insertions(+), 17 deletions(-)tools/perf/builtin-diff.c +0
-17@@ -572,23 +572,6 @@ static void init_block_hist(struct block_hist *bh) bh->valid = true; } -static int block_pair_cmp (struct hist_entry *a,struct hist_entry *b) -{ -struct block_info *bi_a = a->block_info; -struct block_info *bi_b = b->block_info; -int cmp; - -if (!bi_a->sym || !bi_b->sym) -return -1 ; - - cmp =strcmp (bi_a->sym->name, bi_b->sym->name); - -if ((!cmp) && (bi_a->start == bi_b->start) && (bi_a->end == bi_b->end)) -return 0 ; - -return -1 ; -} -static struct hist_entry *get_block_pair (struct hist_entry *he,struct hists *hists_pair) {tools/perf/util/block-info.c +11
-0@@ -475,3 +475,26 @@ float block_info__total_cycles_percent(struct hist_entry *he)return 0.0 ; } + +int block_pair_cmp (struct hist_entry *pair,struct hist_entry *he) +{ +struct block_info *bi_p = pair->block_info; +struct block_info *bi_h = he->block_info; +struct map_symbol *ms_p = &pair->ms; +struct map_symbol *ms_h = &he->ms; +int cmp; + +if (!ms_p->map || !ms_p->map->dso || !ms_p->sym || + !ms_h->map || !ms_h->map->dso || !ms_h->sym) {
Quoted 9 lines
tools/perf/util/block-info.c float block_info__total_cycles_percent(struct hist_entry *he) · line 494
Quoted 6 lines
tools/perf/util/block-info.c +6
-0+return -1 ; + } + + cmp =strcmp (ms_p->sym->name, ms_h->sym->name); +if (cmp) +return -1 ;should this return cmp? also you don't mention this change in the changelog
Yes, return cmp should be OK.
It's changed from "strcmp(bi_a->sym->name, bi_b->sym->name)" to "strcmp(ms_p->sym->name, ms_h->sym->name)" is because we don't need an additional checking for bi_a->sym and bi_b->sym.
If we use "strcmp(bi_a->sym->name, bi_b->sym->name)" here, I think we'd better check the sym first. I will mention that in changelog.
Thanks
Jin Yao
Quoted 3 lines
thanks,
jirka