Commit cb6e92c7 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

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: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarIan 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent d5e33ce0
...@@ -1781,8 +1781,8 @@ static void hierarchy_insert_output_entry(struct rb_root_cached *root, ...@@ -1781,8 +1781,8 @@ static void hierarchy_insert_output_entry(struct rb_root_cached *root,
/* update column width of dynamic entry */ /* update column width of dynamic entry */
perf_hpp_list__for_each_sort_list(he->hpp_list, fmt) { perf_hpp_list__for_each_sort_list(he->hpp_list, fmt) {
if (perf_hpp__is_dynamic_entry(fmt)) if (fmt->init)
fmt->sort(fmt, he, NULL); fmt->init(fmt, he);
} }
} }
...@@ -1879,10 +1879,10 @@ static void __hists__insert_output_entry(struct rb_root_cached *entries, ...@@ -1879,10 +1879,10 @@ static void __hists__insert_output_entry(struct rb_root_cached *entries,
rb_link_node(&he->rb_node, parent, p); rb_link_node(&he->rb_node, parent, p);
rb_insert_color_cached(&he->rb_node, entries, leftmost); rb_insert_color_cached(&he->rb_node, entries, leftmost);
/* update column width of dynamic entries */
perf_hpp_list__for_each_sort_list(&perf_hpp_list, fmt) { perf_hpp_list__for_each_sort_list(&perf_hpp_list, fmt) {
if (perf_hpp__is_dynamic_entry(fmt) && if (fmt->init)
perf_hpp__defined_dynamic_entry(fmt, he->hists)) fmt->init(fmt, he);
fmt->sort(fmt, he, NULL); /* update column width */
} }
} }
......
...@@ -272,6 +272,7 @@ struct perf_hpp_fmt { ...@@ -272,6 +272,7 @@ struct perf_hpp_fmt {
struct hists *hists, int line, int *span); struct hists *hists, int line, int *span);
int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
struct hists *hists); struct hists *hists);
void (*init)(struct perf_hpp_fmt *fmt, struct hist_entry *he);
int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
struct hist_entry *he); struct hist_entry *he);
int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
......
...@@ -2251,6 +2251,19 @@ static void hse_free(struct perf_hpp_fmt *fmt) ...@@ -2251,6 +2251,19 @@ static void hse_free(struct perf_hpp_fmt *fmt)
free(hse); free(hse);
} }
static void hse_init(struct perf_hpp_fmt *fmt, struct hist_entry *he)
{
struct hpp_sort_entry *hse;
if (!perf_hpp__is_sort_entry(fmt))
return;
hse = container_of(fmt, struct hpp_sort_entry, hpp);
if (hse->se->se_init)
hse->se->se_init(he);
}
static struct hpp_sort_entry * static struct hpp_sort_entry *
__sort_dimension__alloc_hpp(struct sort_dimension *sd, int level) __sort_dimension__alloc_hpp(struct sort_dimension *sd, int level)
{ {
...@@ -2274,6 +2287,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd, int level) ...@@ -2274,6 +2287,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd, int level)
hse->hpp.sort = __sort__hpp_sort; hse->hpp.sort = __sort__hpp_sort;
hse->hpp.equal = __sort__hpp_equal; hse->hpp.equal = __sort__hpp_equal;
hse->hpp.free = hse_free; hse->hpp.free = hse_free;
hse->hpp.init = hse_init;
INIT_LIST_HEAD(&hse->hpp.list); INIT_LIST_HEAD(&hse->hpp.list);
INIT_LIST_HEAD(&hse->hpp.sort_list); INIT_LIST_HEAD(&hse->hpp.sort_list);
...@@ -2556,11 +2570,6 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt, ...@@ -2556,11 +2570,6 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,
hde = container_of(fmt, struct hpp_dynamic_entry, hpp); hde = container_of(fmt, struct hpp_dynamic_entry, hpp);
if (b == NULL) {
update_dynamic_len(hde, a);
return 0;
}
field = hde->field; field = hde->field;
if (field->flags & TEP_FIELD_IS_DYNAMIC) { if (field->flags & TEP_FIELD_IS_DYNAMIC) {
unsigned long long dyn; unsigned long long dyn;
...@@ -2610,6 +2619,17 @@ static void hde_free(struct perf_hpp_fmt *fmt) ...@@ -2610,6 +2619,17 @@ static void hde_free(struct perf_hpp_fmt *fmt)
free(hde); free(hde);
} }
static void __sort__hde_init(struct perf_hpp_fmt *fmt, struct hist_entry *he)
{
struct hpp_dynamic_entry *hde;
if (!perf_hpp__is_dynamic_entry(fmt))
return;
hde = container_of(fmt, struct hpp_dynamic_entry, hpp);
update_dynamic_len(hde, he);
}
static struct hpp_dynamic_entry * static struct hpp_dynamic_entry *
__alloc_dynamic_entry(struct evsel *evsel, struct tep_format_field *field, __alloc_dynamic_entry(struct evsel *evsel, struct tep_format_field *field,
int level) int level)
...@@ -2632,6 +2652,7 @@ __alloc_dynamic_entry(struct evsel *evsel, struct tep_format_field *field, ...@@ -2632,6 +2652,7 @@ __alloc_dynamic_entry(struct evsel *evsel, struct tep_format_field *field,
hde->hpp.entry = __sort__hde_entry; hde->hpp.entry = __sort__hde_entry;
hde->hpp.color = NULL; hde->hpp.color = NULL;
hde->hpp.init = __sort__hde_init;
hde->hpp.cmp = __sort__hde_cmp; hde->hpp.cmp = __sort__hde_cmp;
hde->hpp.collapse = __sort__hde_cmp; hde->hpp.collapse = __sort__hde_cmp;
hde->hpp.sort = __sort__hde_cmp; hde->hpp.sort = __sort__hde_cmp;
......
...@@ -282,6 +282,7 @@ struct sort_entry { ...@@ -282,6 +282,7 @@ struct sort_entry {
int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size, int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
unsigned int width); unsigned int width);
int (*se_filter)(struct hist_entry *he, int type, const void *arg); int (*se_filter)(struct hist_entry *he, int type, const void *arg);
void (*se_init)(struct hist_entry *he);
u8 se_width_idx; u8 se_width_idx;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment