diff options
author | Leo Yan <leo.yan@linaro.org> | 2023-03-15 17:51:10 +0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-03-15 22:49:57 +0300 |
commit | 32a5c2b84236d1eebf341ae4a90dd5e04aae97ae (patch) | |
tree | d823cdaa8cd54aa0f58a7d4c17dba8cea363891b /tools/perf/builtin-kvm.c | |
parent | fbb70bd3100527b9fea86c58e88a63a28f24f428 (diff) | |
download | linux-32a5c2b84236d1eebf341ae4a90dd5e04aae97ae.tar.xz |
perf kvm: Add dimensions for percentages
Add dimensions for count and time percentages, it would be useful for
user to review percentage statistics.
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230315145112.186603-2-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-kvm.c')
-rw-r--r-- | tools/perf/builtin-kvm.c | 98 |
1 files changed, 97 insertions, 1 deletions
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 07f75663083a..9bfde8b7ac65 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -223,10 +223,105 @@ static struct kvm_dimension dim_mean_time = { .width = 14, }; +#define PERC_STR(__s, __v) \ +({ \ + scnprintf(__s, sizeof(__s), "%.2F%%", __v); \ + __s; \ +}) + +static double percent(u64 st, u64 tot) +{ + return tot ? 100. * (double) st / (double) tot : 0; +} + +#define EV_METRIC_PERCENT(metric) \ +static int ev_percent_##metric(struct hist_entry *he) \ +{ \ + struct kvm_event *event; \ + struct perf_kvm_stat *perf_kvm; \ + \ + event = container_of(he, struct kvm_event, he); \ + perf_kvm = event->perf_kvm; \ + \ + return percent(get_event_##metric(event, perf_kvm->trace_vcpu), \ + perf_kvm->total_##metric); \ +} + +EV_METRIC_PERCENT(time) +EV_METRIC_PERCENT(count) + +static int ev_entry_time_precent(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width = fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per = ev_percent_time(he); + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); +} + +static int64_t +ev_cmp_time_precent(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, struct hist_entry *right) +{ + double per_left; + double per_right; + + per_left = ev_percent_time(left); + per_right = ev_percent_time(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_time_percent = { + .header = "Time%", + .name = "percent_time", + .cmp = ev_cmp_time_precent, + .entry = ev_entry_time_precent, + .width = 12, +}; + +static int ev_entry_count_precent(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width = fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per = ev_percent_count(he); + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); +} + +static int64_t +ev_cmp_count_precent(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, struct hist_entry *right) +{ + double per_left; + double per_right; + + per_left = ev_percent_count(left); + per_right = ev_percent_count(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_count_percent = { + .header = "Sample%", + .name = "percent_sample", + .cmp = ev_cmp_count_precent, + .entry = ev_entry_count_precent, + .width = 12, +}; + static struct kvm_dimension *dimensions[] = { &dim_event, &dim_time, + &dim_time_percent, &dim_count, + &dim_count_percent, &dim_max_time, &dim_min_time, &dim_mean_time, @@ -877,7 +972,8 @@ static int filter_cb(struct hist_entry *he, void *arg __maybe_unused) static void sort_result(struct perf_kvm_stat *kvm) { - const char *output_columns = "ev_name,sample,time,max_t,min_t,mean_t"; + const char *output_columns = "ev_name,sample,percent_sample," + "time,percent_time,max_t,min_t,mean_t"; kvm_hists__reinit(output_columns, kvm->sort_key); hists__collapse_resort(&kvm_hists.hists, NULL); |