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

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>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
32a5c2b8 fbb70bd3

+97 -1
+97 -1
tools/perf/builtin-kvm.c
··· 223 223 .width = 14, 224 224 }; 225 225 226 + #define PERC_STR(__s, __v) \ 227 + ({ \ 228 + scnprintf(__s, sizeof(__s), "%.2F%%", __v); \ 229 + __s; \ 230 + }) 231 + 232 + static double percent(u64 st, u64 tot) 233 + { 234 + return tot ? 100. * (double) st / (double) tot : 0; 235 + } 236 + 237 + #define EV_METRIC_PERCENT(metric) \ 238 + static int ev_percent_##metric(struct hist_entry *he) \ 239 + { \ 240 + struct kvm_event *event; \ 241 + struct perf_kvm_stat *perf_kvm; \ 242 + \ 243 + event = container_of(he, struct kvm_event, he); \ 244 + perf_kvm = event->perf_kvm; \ 245 + \ 246 + return percent(get_event_##metric(event, perf_kvm->trace_vcpu), \ 247 + perf_kvm->total_##metric); \ 248 + } 249 + 250 + EV_METRIC_PERCENT(time) 251 + EV_METRIC_PERCENT(count) 252 + 253 + static int ev_entry_time_precent(struct perf_hpp_fmt *fmt, 254 + struct perf_hpp *hpp, 255 + struct hist_entry *he) 256 + { 257 + int width = fmt_width(fmt, hpp, he->hists); 258 + double per; 259 + char buf[10]; 260 + 261 + per = ev_percent_time(he); 262 + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); 263 + } 264 + 265 + static int64_t 266 + ev_cmp_time_precent(struct perf_hpp_fmt *fmt __maybe_unused, 267 + struct hist_entry *left, struct hist_entry *right) 268 + { 269 + double per_left; 270 + double per_right; 271 + 272 + per_left = ev_percent_time(left); 273 + per_right = ev_percent_time(right); 274 + 275 + return per_left - per_right; 276 + } 277 + 278 + static struct kvm_dimension dim_time_percent = { 279 + .header = "Time%", 280 + .name = "percent_time", 281 + .cmp = ev_cmp_time_precent, 282 + .entry = ev_entry_time_precent, 283 + .width = 12, 284 + }; 285 + 286 + static int ev_entry_count_precent(struct perf_hpp_fmt *fmt, 287 + struct perf_hpp *hpp, 288 + struct hist_entry *he) 289 + { 290 + int width = fmt_width(fmt, hpp, he->hists); 291 + double per; 292 + char buf[10]; 293 + 294 + per = ev_percent_count(he); 295 + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); 296 + } 297 + 298 + static int64_t 299 + ev_cmp_count_precent(struct perf_hpp_fmt *fmt __maybe_unused, 300 + struct hist_entry *left, struct hist_entry *right) 301 + { 302 + double per_left; 303 + double per_right; 304 + 305 + per_left = ev_percent_count(left); 306 + per_right = ev_percent_count(right); 307 + 308 + return per_left - per_right; 309 + } 310 + 311 + static struct kvm_dimension dim_count_percent = { 312 + .header = "Sample%", 313 + .name = "percent_sample", 314 + .cmp = ev_cmp_count_precent, 315 + .entry = ev_entry_count_precent, 316 + .width = 12, 317 + }; 318 + 226 319 static struct kvm_dimension *dimensions[] = { 227 320 &dim_event, 228 321 &dim_time, 322 + &dim_time_percent, 229 323 &dim_count, 324 + &dim_count_percent, 230 325 &dim_max_time, 231 326 &dim_min_time, 232 327 &dim_mean_time, ··· 972 877 973 878 static void sort_result(struct perf_kvm_stat *kvm) 974 879 { 975 - const char *output_columns = "ev_name,sample,time,max_t,min_t,mean_t"; 880 + const char *output_columns = "ev_name,sample,percent_sample," 881 + "time,percent_time,max_t,min_t,mean_t"; 976 882 977 883 kvm_hists__reinit(output_columns, kvm->sort_key); 978 884 hists__collapse_resort(&kvm_hists.hists, NULL);