OSDN Git Service

perf kvm: Add dimensions for percentages
authorLeo Yan <leo.yan@linaro.org>
Wed, 15 Mar 2023 14:51:10 +0000 (22:51 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 15 Mar 2023 19:49:57 +0000 (16:49 -0300)
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>
tools/perf/builtin-kvm.c

index 07f7566..9bfde8b 100644 (file)
@@ -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);