Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf hist: Add perf_hpp_fmt->init() callback

In __hists__insert_output_entry(), it calls fmt->sort() for dynamic
entries with NULL to update column width for tracepoint fields.
But it's a hacky abuse of the sort callback, better to have a proper
callback for that. I'll add more use cases later.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20221215192817.2734573-7-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
cb6e92c7 d5e33ce0

+33 -10
+5 -5
tools/perf/util/hist.c
··· 1781 1781 1782 1782 /* update column width of dynamic entry */ 1783 1783 perf_hpp_list__for_each_sort_list(he->hpp_list, fmt) { 1784 - if (perf_hpp__is_dynamic_entry(fmt)) 1785 - fmt->sort(fmt, he, NULL); 1784 + if (fmt->init) 1785 + fmt->init(fmt, he); 1786 1786 } 1787 1787 } 1788 1788 ··· 1879 1879 rb_link_node(&he->rb_node, parent, p); 1880 1880 rb_insert_color_cached(&he->rb_node, entries, leftmost); 1881 1881 1882 + /* update column width of dynamic entries */ 1882 1883 perf_hpp_list__for_each_sort_list(&perf_hpp_list, fmt) { 1883 - if (perf_hpp__is_dynamic_entry(fmt) && 1884 - perf_hpp__defined_dynamic_entry(fmt, he->hists)) 1885 - fmt->sort(fmt, he, NULL); /* update column width */ 1884 + if (fmt->init) 1885 + fmt->init(fmt, he); 1886 1886 } 1887 1887 } 1888 1888
+1
tools/perf/util/hist.h
··· 272 272 struct hists *hists, int line, int *span); 273 273 int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 274 274 struct hists *hists); 275 + void (*init)(struct perf_hpp_fmt *fmt, struct hist_entry *he); 275 276 int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 276 277 struct hist_entry *he); 277 278 int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
+26 -5
tools/perf/util/sort.c
··· 2251 2251 free(hse); 2252 2252 } 2253 2253 2254 + static void hse_init(struct perf_hpp_fmt *fmt, struct hist_entry *he) 2255 + { 2256 + struct hpp_sort_entry *hse; 2257 + 2258 + if (!perf_hpp__is_sort_entry(fmt)) 2259 + return; 2260 + 2261 + hse = container_of(fmt, struct hpp_sort_entry, hpp); 2262 + 2263 + if (hse->se->se_init) 2264 + hse->se->se_init(he); 2265 + } 2266 + 2254 2267 static struct hpp_sort_entry * 2255 2268 __sort_dimension__alloc_hpp(struct sort_dimension *sd, int level) 2256 2269 { ··· 2287 2274 hse->hpp.sort = __sort__hpp_sort; 2288 2275 hse->hpp.equal = __sort__hpp_equal; 2289 2276 hse->hpp.free = hse_free; 2277 + hse->hpp.init = hse_init; 2290 2278 2291 2279 INIT_LIST_HEAD(&hse->hpp.list); 2292 2280 INIT_LIST_HEAD(&hse->hpp.sort_list); ··· 2570 2556 2571 2557 hde = container_of(fmt, struct hpp_dynamic_entry, hpp); 2572 2558 2573 - if (b == NULL) { 2574 - update_dynamic_len(hde, a); 2575 - return 0; 2576 - } 2577 - 2578 2559 field = hde->field; 2579 2560 if (field->flags & TEP_FIELD_IS_DYNAMIC) { 2580 2561 unsigned long long dyn; ··· 2619 2610 free(hde); 2620 2611 } 2621 2612 2613 + static void __sort__hde_init(struct perf_hpp_fmt *fmt, struct hist_entry *he) 2614 + { 2615 + struct hpp_dynamic_entry *hde; 2616 + 2617 + if (!perf_hpp__is_dynamic_entry(fmt)) 2618 + return; 2619 + 2620 + hde = container_of(fmt, struct hpp_dynamic_entry, hpp); 2621 + update_dynamic_len(hde, he); 2622 + } 2623 + 2622 2624 static struct hpp_dynamic_entry * 2623 2625 __alloc_dynamic_entry(struct evsel *evsel, struct tep_format_field *field, 2624 2626 int level) ··· 2652 2632 hde->hpp.entry = __sort__hde_entry; 2653 2633 hde->hpp.color = NULL; 2654 2634 2635 + hde->hpp.init = __sort__hde_init; 2655 2636 hde->hpp.cmp = __sort__hde_cmp; 2656 2637 hde->hpp.collapse = __sort__hde_cmp; 2657 2638 hde->hpp.sort = __sort__hde_cmp;
+1
tools/perf/util/sort.h
··· 282 282 int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size, 283 283 unsigned int width); 284 284 int (*se_filter)(struct hist_entry *he, int type, const void *arg); 285 + void (*se_init)(struct hist_entry *he); 285 286 u8 se_width_idx; 286 287 }; 287 288