diff options
Diffstat (limited to 'tools/perf/ui/stdio/hist.c')
-rw-r--r-- | tools/perf/ui/stdio/hist.c | 238 |
1 files changed, 41 insertions, 197 deletions
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 9bf7e9e5a72e..4228b4c6b72d 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c | |||
@@ -1,5 +1,4 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <math.h> | ||
3 | 2 | ||
4 | #include "../../util/util.h" | 3 | #include "../../util/util.h" |
5 | #include "../../util/hist.h" | 4 | #include "../../util/hist.h" |
@@ -291,138 +290,6 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he, | |||
291 | return 0; | 290 | return 0; |
292 | } | 291 | } |
293 | 292 | ||
294 | static int hist_entry__period_snprintf(struct hist_entry *he, char *s, | ||
295 | size_t size, struct hists *pair_hists, | ||
296 | bool show_displacement, long displacement, | ||
297 | bool color, u64 total_period) | ||
298 | { | ||
299 | u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us; | ||
300 | u64 nr_events; | ||
301 | const char *sep = symbol_conf.field_sep; | ||
302 | int ret; | ||
303 | |||
304 | if (symbol_conf.exclude_other && !he->parent) | ||
305 | return 0; | ||
306 | |||
307 | if (pair_hists) { | ||
308 | period = he->pair ? he->pair->period : 0; | ||
309 | nr_events = he->pair ? he->pair->nr_events : 0; | ||
310 | total = pair_hists->stats.total_period; | ||
311 | period_sys = he->pair ? he->pair->period_sys : 0; | ||
312 | period_us = he->pair ? he->pair->period_us : 0; | ||
313 | period_guest_sys = he->pair ? he->pair->period_guest_sys : 0; | ||
314 | period_guest_us = he->pair ? he->pair->period_guest_us : 0; | ||
315 | } else { | ||
316 | period = he->period; | ||
317 | nr_events = he->nr_events; | ||
318 | total = total_period; | ||
319 | period_sys = he->period_sys; | ||
320 | period_us = he->period_us; | ||
321 | period_guest_sys = he->period_guest_sys; | ||
322 | period_guest_us = he->period_guest_us; | ||
323 | } | ||
324 | |||
325 | if (total) { | ||
326 | if (color) | ||
327 | ret = percent_color_snprintf(s, size, | ||
328 | sep ? "%.2f" : " %6.2f%%", | ||
329 | (period * 100.0) / total); | ||
330 | else | ||
331 | ret = scnprintf(s, size, sep ? "%.2f" : " %6.2f%%", | ||
332 | (period * 100.0) / total); | ||
333 | if (symbol_conf.show_cpu_utilization) { | ||
334 | ret += percent_color_snprintf(s + ret, size - ret, | ||
335 | sep ? "%.2f" : " %6.2f%%", | ||
336 | (period_sys * 100.0) / total); | ||
337 | ret += percent_color_snprintf(s + ret, size - ret, | ||
338 | sep ? "%.2f" : " %6.2f%%", | ||
339 | (period_us * 100.0) / total); | ||
340 | if (perf_guest) { | ||
341 | ret += percent_color_snprintf(s + ret, | ||
342 | size - ret, | ||
343 | sep ? "%.2f" : " %6.2f%%", | ||
344 | (period_guest_sys * 100.0) / | ||
345 | total); | ||
346 | ret += percent_color_snprintf(s + ret, | ||
347 | size - ret, | ||
348 | sep ? "%.2f" : " %6.2f%%", | ||
349 | (period_guest_us * 100.0) / | ||
350 | total); | ||
351 | } | ||
352 | } | ||
353 | } else | ||
354 | ret = scnprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period); | ||
355 | |||
356 | if (symbol_conf.show_nr_samples) { | ||
357 | if (sep) | ||
358 | ret += scnprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events); | ||
359 | else | ||
360 | ret += scnprintf(s + ret, size - ret, "%11" PRIu64, nr_events); | ||
361 | } | ||
362 | |||
363 | if (symbol_conf.show_total_period) { | ||
364 | if (sep) | ||
365 | ret += scnprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period); | ||
366 | else | ||
367 | ret += scnprintf(s + ret, size - ret, " %12" PRIu64, period); | ||
368 | } | ||
369 | |||
370 | if (pair_hists) { | ||
371 | char bf[32]; | ||
372 | double old_percent = 0, new_percent = 0, diff; | ||
373 | |||
374 | if (total > 0) | ||
375 | old_percent = (period * 100.0) / total; | ||
376 | if (total_period > 0) | ||
377 | new_percent = (he->period * 100.0) / total_period; | ||
378 | |||
379 | diff = new_percent - old_percent; | ||
380 | |||
381 | if (fabs(diff) >= 0.01) | ||
382 | scnprintf(bf, sizeof(bf), "%+4.2F%%", diff); | ||
383 | else | ||
384 | scnprintf(bf, sizeof(bf), " "); | ||
385 | |||
386 | if (sep) | ||
387 | ret += scnprintf(s + ret, size - ret, "%c%s", *sep, bf); | ||
388 | else | ||
389 | ret += scnprintf(s + ret, size - ret, "%11.11s", bf); | ||
390 | |||
391 | if (show_displacement) { | ||
392 | if (displacement) | ||
393 | scnprintf(bf, sizeof(bf), "%+4ld", displacement); | ||
394 | else | ||
395 | scnprintf(bf, sizeof(bf), " "); | ||
396 | |||
397 | if (sep) | ||
398 | ret += scnprintf(s + ret, size - ret, "%c%s", *sep, bf); | ||
399 | else | ||
400 | ret += scnprintf(s + ret, size - ret, "%6.6s", bf); | ||
401 | } | ||
402 | } | ||
403 | |||
404 | return ret; | ||
405 | } | ||
406 | |||
407 | int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size, | ||
408 | struct hists *hists) | ||
409 | { | ||
410 | const char *sep = symbol_conf.field_sep; | ||
411 | struct sort_entry *se; | ||
412 | int ret = 0; | ||
413 | |||
414 | list_for_each_entry(se, &hist_entry__sort_list, list) { | ||
415 | if (se->elide) | ||
416 | continue; | ||
417 | |||
418 | ret += scnprintf(s + ret, size - ret, "%s", sep ?: " "); | ||
419 | ret += se->se_snprintf(he, s + ret, size - ret, | ||
420 | hists__col_len(hists, se->se_width_idx)); | ||
421 | } | ||
422 | |||
423 | return ret; | ||
424 | } | ||
425 | |||
426 | static size_t hist_entry__callchain_fprintf(struct hist_entry *he, | 293 | static size_t hist_entry__callchain_fprintf(struct hist_entry *he, |
427 | struct hists *hists, | 294 | struct hists *hists, |
428 | u64 total_period, FILE *fp) | 295 | u64 total_period, FILE *fp) |
@@ -441,18 +308,22 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he, | |||
441 | 308 | ||
442 | static int hist_entry__fprintf(struct hist_entry *he, size_t size, | 309 | static int hist_entry__fprintf(struct hist_entry *he, size_t size, |
443 | struct hists *hists, struct hists *pair_hists, | 310 | struct hists *hists, struct hists *pair_hists, |
444 | bool show_displacement, long displacement, | 311 | long displacement, u64 total_period, FILE *fp) |
445 | u64 total_period, FILE *fp) | ||
446 | { | 312 | { |
447 | char bf[512]; | 313 | char bf[512]; |
448 | int ret; | 314 | int ret; |
315 | struct perf_hpp hpp = { | ||
316 | .buf = bf, | ||
317 | .size = size, | ||
318 | .total_period = total_period, | ||
319 | .displacement = displacement, | ||
320 | .ptr = pair_hists, | ||
321 | }; | ||
449 | 322 | ||
450 | if (size == 0 || size > sizeof(bf)) | 323 | if (size == 0 || size > sizeof(bf)) |
451 | size = sizeof(bf); | 324 | size = hpp.size = sizeof(bf); |
452 | 325 | ||
453 | ret = hist_entry__period_snprintf(he, bf, size, pair_hists, | 326 | ret = hist_entry__period_snprintf(&hpp, he, true); |
454 | show_displacement, displacement, | ||
455 | true, total_period); | ||
456 | hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); | 327 | hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); |
457 | 328 | ||
458 | ret = fprintf(fp, "%s\n", bf); | 329 | ret = fprintf(fp, "%s\n", bf); |
@@ -477,59 +348,29 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, | |||
477 | unsigned int width; | 348 | unsigned int width; |
478 | const char *sep = symbol_conf.field_sep; | 349 | const char *sep = symbol_conf.field_sep; |
479 | const char *col_width = symbol_conf.col_width_list_str; | 350 | const char *col_width = symbol_conf.col_width_list_str; |
480 | int nr_rows = 0; | 351 | int idx, nr_rows = 0; |
352 | char bf[64]; | ||
353 | struct perf_hpp dummy_hpp = { | ||
354 | .buf = bf, | ||
355 | .size = sizeof(bf), | ||
356 | .ptr = pair, | ||
357 | }; | ||
481 | 358 | ||
482 | init_rem_hits(); | 359 | init_rem_hits(); |
483 | 360 | ||
484 | if (!show_header) | 361 | if (!show_header) |
485 | goto print_entries; | 362 | goto print_entries; |
486 | 363 | ||
487 | fprintf(fp, "# %s", pair ? "Baseline" : "Overhead"); | 364 | fprintf(fp, "# "); |
488 | 365 | for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) { | |
489 | if (symbol_conf.show_cpu_utilization) { | 366 | if (!perf_hpp__format[idx].cond) |
490 | if (sep) { | 367 | continue; |
491 | ret += fprintf(fp, "%csys", *sep); | ||
492 | ret += fprintf(fp, "%cus", *sep); | ||
493 | if (perf_guest) { | ||
494 | ret += fprintf(fp, "%cguest sys", *sep); | ||
495 | ret += fprintf(fp, "%cguest us", *sep); | ||
496 | } | ||
497 | } else { | ||
498 | ret += fprintf(fp, " sys "); | ||
499 | ret += fprintf(fp, " us "); | ||
500 | if (perf_guest) { | ||
501 | ret += fprintf(fp, " guest sys "); | ||
502 | ret += fprintf(fp, " guest us "); | ||
503 | } | ||
504 | } | ||
505 | } | ||
506 | |||
507 | if (symbol_conf.show_nr_samples) { | ||
508 | if (sep) | ||
509 | fprintf(fp, "%cSamples", *sep); | ||
510 | else | ||
511 | fputs(" Samples ", fp); | ||
512 | } | ||
513 | |||
514 | if (symbol_conf.show_total_period) { | ||
515 | if (sep) | ||
516 | ret += fprintf(fp, "%cPeriod", *sep); | ||
517 | else | ||
518 | ret += fprintf(fp, " Period "); | ||
519 | } | ||
520 | 368 | ||
521 | if (pair) { | 369 | if (idx) |
522 | if (sep) | 370 | fprintf(fp, "%s", sep ?: " "); |
523 | ret += fprintf(fp, "%cDelta", *sep); | ||
524 | else | ||
525 | ret += fprintf(fp, " Delta "); | ||
526 | 371 | ||
527 | if (show_displacement) { | 372 | perf_hpp__format[idx].header(&dummy_hpp); |
528 | if (sep) | 373 | fprintf(fp, "%s", bf); |
529 | ret += fprintf(fp, "%cDisplacement", *sep); | ||
530 | else | ||
531 | ret += fprintf(fp, " Displ"); | ||
532 | } | ||
533 | } | 374 | } |
534 | 375 | ||
535 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 376 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
@@ -561,18 +402,21 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, | |||
561 | if (sep) | 402 | if (sep) |
562 | goto print_entries; | 403 | goto print_entries; |
563 | 404 | ||
564 | fprintf(fp, "# ........"); | 405 | fprintf(fp, "# "); |
565 | if (symbol_conf.show_cpu_utilization) | 406 | for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) { |
566 | fprintf(fp, " ....... ......."); | 407 | unsigned int i; |
567 | if (symbol_conf.show_nr_samples) | 408 | |
568 | fprintf(fp, " .........."); | 409 | if (!perf_hpp__format[idx].cond) |
569 | if (symbol_conf.show_total_period) | 410 | continue; |
570 | fprintf(fp, " ............"); | 411 | |
571 | if (pair) { | 412 | if (idx) |
572 | fprintf(fp, " .........."); | 413 | fprintf(fp, "%s", sep ?: " "); |
573 | if (show_displacement) | 414 | |
574 | fprintf(fp, " ....."); | 415 | width = perf_hpp__format[idx].width(&dummy_hpp); |
416 | for (i = 0; i < width; i++) | ||
417 | fprintf(fp, "."); | ||
575 | } | 418 | } |
419 | |||
576 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 420 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
577 | unsigned int i; | 421 | unsigned int i; |
578 | 422 | ||
@@ -612,8 +456,8 @@ print_entries: | |||
612 | displacement = 0; | 456 | displacement = 0; |
613 | ++position; | 457 | ++position; |
614 | } | 458 | } |
615 | ret += hist_entry__fprintf(h, max_cols, hists, pair, show_displacement, | 459 | ret += hist_entry__fprintf(h, max_cols, hists, pair, displacement, |
616 | displacement, total_period, fp); | 460 | total_period, fp); |
617 | 461 | ||
618 | if (max_rows && ++nr_rows >= max_rows) | 462 | if (max_rows && ++nr_rows >= max_rows) |
619 | goto out; | 463 | goto out; |