mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
perf hist: Simplify __hpp_fmt() using hpp_fmt_data
The struct hpp_fmt_data is to keep the values for each group members so it doesn't need to check the event index in the group. Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20240607202918.2357459-3-namhyung@kernel.org
This commit is contained in:
parent
cc2621cecd
commit
8f6071a3dc
1 changed files with 37 additions and 40 deletions
|
@ -46,65 +46,62 @@ static int __hpp__fmt_print(struct perf_hpp *hpp, struct hists *hists, u64 val,
|
||||||
return hpp__call_print_fn(hpp, print_fn, fmt, len, val);
|
return hpp__call_print_fn(hpp, print_fn, fmt, len, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct hpp_fmt_value {
|
||||||
|
struct hists *hists;
|
||||||
|
u64 val;
|
||||||
|
int samples;
|
||||||
|
};
|
||||||
|
|
||||||
static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
|
static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
|
||||||
hpp_field_fn get_field, const char *fmt, int len,
|
hpp_field_fn get_field, const char *fmt, int len,
|
||||||
hpp_snprint_fn print_fn, enum perf_hpp_fmt_type fmtype)
|
hpp_snprint_fn print_fn, enum perf_hpp_fmt_type fmtype)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
struct hists *hists = he->hists;
|
struct hists *hists = he->hists;
|
||||||
struct evsel *evsel = hists_to_evsel(hists);
|
struct evsel *evsel = hists_to_evsel(hists);
|
||||||
|
struct evsel *pos;
|
||||||
char *buf = hpp->buf;
|
char *buf = hpp->buf;
|
||||||
size_t size = hpp->size;
|
size_t size = hpp->size;
|
||||||
|
int i, nr_members = 1;
|
||||||
|
struct hpp_fmt_value *values;
|
||||||
|
|
||||||
ret = __hpp__fmt_print(hpp, hists, get_field(he), he->stat.nr_events,
|
if (evsel__is_group_event(evsel))
|
||||||
fmt, len, print_fn, fmtype);
|
nr_members = evsel->core.nr_members;
|
||||||
|
|
||||||
|
values = calloc(nr_members, sizeof(*values));
|
||||||
|
if (values == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
for_each_group_evsel(pos, evsel)
|
||||||
|
values[i++].hists = evsel__hists(pos);
|
||||||
|
|
||||||
|
values[0].val = get_field(he);
|
||||||
|
values[0].samples = he->stat.nr_events;
|
||||||
|
|
||||||
if (evsel__is_group_event(evsel)) {
|
if (evsel__is_group_event(evsel)) {
|
||||||
int prev_idx, idx_delta;
|
|
||||||
struct hist_entry *pair;
|
struct hist_entry *pair;
|
||||||
int nr_members = evsel->core.nr_members;
|
|
||||||
|
|
||||||
prev_idx = evsel__group_idx(evsel);
|
|
||||||
|
|
||||||
list_for_each_entry(pair, &he->pairs.head, pairs.node) {
|
list_for_each_entry(pair, &he->pairs.head, pairs.node) {
|
||||||
u64 period = get_field(pair);
|
for (i = 0; i < nr_members; i++) {
|
||||||
u64 total = hists__total_period(pair->hists);
|
if (values[i].hists != pair->hists)
|
||||||
int nr_samples = pair->stat.nr_events;
|
continue;
|
||||||
|
|
||||||
if (!total)
|
values[i].val = get_field(pair);
|
||||||
continue;
|
values[i].samples = pair->stat.nr_events;
|
||||||
|
break;
|
||||||
evsel = hists_to_evsel(pair->hists);
|
|
||||||
idx_delta = evsel__group_idx(evsel) - prev_idx - 1;
|
|
||||||
|
|
||||||
while (idx_delta--) {
|
|
||||||
/*
|
|
||||||
* zero-fill group members in the middle which have
|
|
||||||
* no samples, pair->hists is not correct but it's
|
|
||||||
* fine since the value is 0.
|
|
||||||
*/
|
|
||||||
ret += __hpp__fmt_print(hpp, pair->hists, 0, 0,
|
|
||||||
fmt, len, print_fn, fmtype);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += __hpp__fmt_print(hpp, pair->hists, period, nr_samples,
|
|
||||||
fmt, len, print_fn, fmtype);
|
|
||||||
|
|
||||||
prev_idx = evsel__group_idx(evsel);
|
|
||||||
}
|
|
||||||
|
|
||||||
idx_delta = nr_members - prev_idx - 1;
|
|
||||||
|
|
||||||
while (idx_delta--) {
|
|
||||||
/*
|
|
||||||
* zero-fill group members at last which have no sample.
|
|
||||||
* the hists is not correct but it's fine like above.
|
|
||||||
*/
|
|
||||||
ret += __hpp__fmt_print(hpp, evsel__hists(evsel), 0, 0,
|
|
||||||
fmt, len, print_fn, fmtype);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < nr_members; i++) {
|
||||||
|
ret += __hpp__fmt_print(hpp, values[i].hists, values[i].val,
|
||||||
|
values[i].samples, fmt, len,
|
||||||
|
print_fn, fmtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(values);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Restore original buf and size as it's where caller expects
|
* Restore original buf and size as it's where caller expects
|
||||||
* the result will be saved.
|
* the result will be saved.
|
||||||
|
|
Loading…
Add table
Reference in a new issue