Lines Matching +full:num +full:- +full:columns

1 // SPDX-License-Identifier: GPL-2.0
3 * builtin-diff.c
23 #include "util/time-utils.h"
27 #include "util/block-info.h"
32 #include <subcmd/parse-options.h>
49 /* Diff command specific HPP columns. */
117 [COMPUTE_DELTA_ABS] = "delta-abs",
138 } columns[PERF_HPP_DIFF__MAX_INDEX] = { variable
185 int ret = -EINVAL; in setup_compute_opt_wdiff()
223 return -EINVAL; in setup_compute_opt()
232 int *cp = (int *) opt->value; in setup_compute()
245 unsigned len = option++ - str; in setup_compute()
254 return -EINVAL; in setup_compute()
269 return -EINVAL; in setup_compute()
274 u64 total = hists__total_period(he->hists); in period_percent()
281 double old_percent = period_percent(he, he->stat.period); in compute_delta()
282 double new_percent = period_percent(pair, pair->stat.period); in compute_delta()
284 pair->diff.period_ratio_delta = new_percent - old_percent; in compute_delta()
285 pair->diff.computed = true; in compute_delta()
286 return pair->diff.period_ratio_delta; in compute_delta()
291 double old_period = he->stat.period ?: 1; in compute_ratio()
292 double new_period = pair->stat.period; in compute_ratio()
294 pair->diff.computed = true; in compute_ratio()
295 pair->diff.period_ratio = new_period / old_period; in compute_ratio()
296 return pair->diff.period_ratio; in compute_ratio()
301 u64 old_period = he->stat.period; in compute_wdiff()
302 u64 new_period = pair->stat.period; in compute_wdiff()
304 pair->diff.computed = true; in compute_wdiff()
305 pair->diff.wdiff = new_period * compute_wdiff_w2 - in compute_wdiff()
308 return pair->diff.wdiff; in compute_wdiff()
314 u64 he_total = he->hists->stats.total_period; in formula_delta()
315 u64 pair_total = pair->hists->stats.total_period; in formula_delta()
318 he_total = he->hists->stats.total_non_filtered_period; in formula_delta()
319 pair_total = pair->hists->stats.total_non_filtered_period; in formula_delta()
322 "(%" PRIu64 " * 100 / %" PRIu64 ") - " in formula_delta()
324 pair->stat.period, pair_total, in formula_delta()
325 he->stat.period, he_total); in formula_delta()
331 double old_period = he->stat.period; in formula_ratio()
332 double new_period = pair->stat.period; in formula_ratio()
340 u64 old_period = he->stat.period; in formula_wdiff()
341 u64 new_period = pair->stat.period; in formula_wdiff()
344 "(%" PRIu64 " * " "%" PRId64 ") - (%" PRIu64 " * " "%" PRId64 ")", in formula_wdiff()
363 return -1; in formula_fprintf()
374 return &bh->he; in block_hist_zalloc()
382 hists__delete_entries(&bh->block_hists); in block_hist_free()
405 int ret = -1; in diff__process_sample_event()
407 if (perf_time__ranges_skip_sample(pdiff->ptime_range, pdiff->range_num, in diff__process_sample_event()
408 sample->time)) { in diff__process_sample_event()
414 event->header.type); in diff__process_sample_event()
415 return -1; in diff__process_sample_event()
418 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) { in diff__process_sample_event()
432 hist__account_cycles(sample->branch_stack, &al, sample, false, in diff__process_sample_event()
459 hists->stats.total_period += sample->period; in diff__process_sample_event()
461 hists->stats.total_non_filtered_period += sample->period; in diff__process_sample_event()
511 void *ptr = dfmt - dfmt->idx; in fmt_to_data_file()
523 list_for_each_entry(pair, &he->pairs.head, pairs.node) in get_pair_data()
524 if (pair->hists == d->hists) in get_pair_data()
534 struct data__file *d = fmt_to_data_file(&dfmt->fmt); in get_pair_fmt()
545 root = &hists->entries_collapsed; in hists__baseline_only()
547 root = hists->entries_in; in hists__baseline_only()
553 next = rb_next(&he->rb_node_in); in hists__baseline_only()
555 rb_erase_cached(&he->rb_node_in, root); in hists__baseline_only()
571 l = llabs(left->diff.cycles); in block_cycles_diff_cmp()
572 r = llabs(right->diff.cycles); in block_cycles_diff_cmp()
573 return r - l; in block_cycles_diff_cmp()
584 __hists__init(&bh->block_hists, &bh->block_list); in init_block_hist()
585 perf_hpp_list__init(&bh->block_list); in init_block_hist()
587 INIT_LIST_HEAD(&bh->block_fmt.list); in init_block_hist()
588 INIT_LIST_HEAD(&bh->block_fmt.sort_list); in init_block_hist()
589 bh->block_fmt.cmp = block_info__cmp; in init_block_hist()
590 bh->block_fmt.sort = block_sort; in init_block_hist()
591 perf_hpp_list__register_sort_field(&bh->block_list, in init_block_hist()
592 &bh->block_fmt); in init_block_hist()
593 bh->valid = true; in init_block_hist()
599 struct rb_root_cached *root = hists_pair->entries_in; in get_block_pair()
607 next = rb_next(&he_pair->rb_node_in); in get_block_pair()
617 static void init_spark_values(unsigned long *svals, int num) in init_spark_values() argument
619 for (int i = 0; i < num; i++) in init_spark_values()
623 static void update_spark_value(unsigned long *svals, int num, in update_spark_value() argument
626 int n = stats->n; in update_spark_value()
628 if (n < num) in update_spark_value()
635 pair->diff.computed = true; in compute_cycles_diff()
636 if (pair->block_info->num && he->block_info->num) { in compute_cycles_diff()
637 pair->diff.cycles = in compute_cycles_diff()
638 pair->block_info->cycles_aggr / pair->block_info->num_aggr - in compute_cycles_diff()
639 he->block_info->cycles_aggr / he->block_info->num_aggr; in compute_cycles_diff()
644 init_stats(&pair->diff.stats); in compute_cycles_diff()
645 init_spark_values(pair->diff.svals, NUM_SPARKS); in compute_cycles_diff()
647 for (int i = 0; i < pair->block_info->num; i++) { in compute_cycles_diff()
650 if (i >= he->block_info->num || i >= NUM_SPARKS) in compute_cycles_diff()
653 val = llabs(pair->block_info->cycles_spark[i] - in compute_cycles_diff()
654 he->block_info->cycles_spark[i]); in compute_cycles_diff()
656 update_spark_value(pair->diff.svals, NUM_SPARKS, in compute_cycles_diff()
657 &pair->diff.stats, val); in compute_cycles_diff()
658 update_stats(&pair->diff.stats, val); in compute_cycles_diff()
666 struct rb_root_cached *root = hists_base->entries_in; in block_hists_match()
674 next = rb_next(&he->rb_node_in); in block_hists_match()
689 root = &hists->entries_collapsed; in hists__precompute()
691 root = hists->entries_in; in hists__precompute()
701 next = rb_next(&he->rb_node_in); in hists__precompute()
733 if (bh->valid && pair_bh->valid) { in hists__precompute()
734 block_hists_match(&bh->block_hists, in hists__precompute()
735 &pair_bh->block_hists); in hists__precompute()
736 hists__output_resort(&pair_bh->block_hists, in hists__precompute()
750 return -1; in cmp_doubles()
764 double l = left->diff.period_ratio_delta; in __hist_entry__cmp_compute()
765 double r = right->diff.period_ratio_delta; in __hist_entry__cmp_compute()
771 double l = fabs(left->diff.period_ratio_delta); in __hist_entry__cmp_compute()
772 double r = fabs(right->diff.period_ratio_delta); in __hist_entry__cmp_compute()
778 double l = left->diff.period_ratio; in __hist_entry__cmp_compute()
779 double r = right->diff.period_ratio; in __hist_entry__cmp_compute()
785 s64 l = left->diff.wdiff; in __hist_entry__cmp_compute()
786 s64 r = right->diff.wdiff; in __hist_entry__cmp_compute()
788 return r - l; in __hist_entry__cmp_compute()
809 return pairs_left ? -1 : 1; in hist_entry__cmp_compute()
818 return p_left ? -1 : 1; in hist_entry__cmp_compute()
840 return p_left ? -1 : 1; in hist_entry__cmp_compute_idx()
848 if (left->dummy && right->dummy) in hist_entry__cmp_compute_idx()
851 if (left->dummy || right->dummy) in hist_entry__cmp_compute_idx()
852 return left->dummy ? 1 : -1; in hist_entry__cmp_compute_idx()
870 if (left->stat.period == right->stat.period) in hist_entry__cmp_baseline()
872 return left->stat.period > right->stat.period ? 1 : -1; in hist_entry__cmp_baseline()
881 return hist_entry__cmp_compute(right, left, COMPUTE_DELTA, d->idx); in hist_entry__cmp_delta()
890 return hist_entry__cmp_compute(right, left, COMPUTE_DELTA_ABS, d->idx); in hist_entry__cmp_delta_abs()
899 return hist_entry__cmp_compute(right, left, COMPUTE_RATIO, d->idx); in hist_entry__cmp_ratio()
908 return hist_entry__cmp_compute(right, left, COMPUTE_WEIGHTED_DIFF, d->idx); in hist_entry__cmp_wdiff()
967 d->idx, d->data.path, in data__fprintf()
968 !d->idx ? "(Baseline)" : ""); in data__fprintf()
975 struct evlist *evlist_base = data__files[0].session->evlist; in data_process()
985 struct evlist *evlist = d->session->evlist; in data_process()
994 d->hists = hists; in data_process()
1023 struct evlist *evlist_base = data_base->session->evlist; in process_base_stream()
1024 struct evlist *evlist_pair = data_pair->session->evlist; in process_base_stream()
1033 es_base = evsel_streams__entry(data_base->evlist_streams, in process_base_stream()
1034 evsel_base->core.idx); in process_base_stream()
1036 return -1; in process_base_stream()
1038 es_pair = evsel_streams__entry(data_pair->evlist_streams, in process_base_stream()
1039 evsel_pair->core.idx); in process_base_stream()
1041 return -1; in process_base_stream()
1065 if (d->evlist_streams) in data__free()
1066 evlist_streams__delete(d->evlist_streams); in data__free()
1069 struct diff_hpp_fmt *fmt = &d->fmt[col]; in data__free()
1071 zfree(&fmt->header); in data__free()
1082 return -ENOMEM; in abstime_str_dup()
1102 return -EINVAL; in parse_absolute_time()
1109 return -EINVAL; in parse_absolute_time()
1113 ret = perf_time__parse_for_ranges(*pstr, d->session, in parse_absolute_time()
1132 ret = perf_time__parse_for_ranges(pdiff.time_str, d->session, in parse_percent_time()
1159 d->session = perf_session__new(&d->data, &pdiff.tool); in check_file_brstack()
1160 if (IS_ERR(d->session)) { in check_file_brstack()
1161 pr_err("Failed to open %s\n", d->data.path); in check_file_brstack()
1162 return PTR_ERR(d->session); in check_file_brstack()
1165 has_br_stack = perf_header__has_feat(&d->session->header, in check_file_brstack()
1167 perf_session__delete(d->session); in check_file_brstack()
1188 ret = -EINVAL; in __cmd_diff()
1191 d->session = perf_session__new(&d->data, &pdiff.tool); in __cmd_diff()
1192 if (IS_ERR(d->session)) { in __cmd_diff()
1193 ret = PTR_ERR(d->session); in __cmd_diff()
1194 pr_err("Failed to open %s\n", d->data.path); in __cmd_diff()
1205 ret = perf_session__cpu_bitmap(d->session, cpu_list, in __cmd_diff()
1211 ret = perf_session__process_events(d->session); in __cmd_diff()
1213 pr_err("Failed to process %s\n", d->data.path); in __cmd_diff()
1217 evlist__collapse_resort(d->session->evlist); in __cmd_diff()
1223 d->evlist_streams = evlist__create_streams( in __cmd_diff()
1224 d->session->evlist, 5); in __cmd_diff()
1225 if (!d->evlist_streams) { in __cmd_diff()
1226 ret = -ENOMEM; in __cmd_diff()
1239 if (!IS_ERR(d->session)) in __cmd_diff()
1240 perf_session__delete(d->session); in __cmd_diff()
1264 OPT_BOOLEAN('b', "baseline-only", &show_baseline_only,
1267 "delta,delta-abs,ratio,wdiff:w1,w2 (default delta-abs),cycles",
1274 OPT_BOOLEAN(0, "cycles-hist", &cycles_hist,
1276 "- WARNING: use only with -c cycles."),
1277 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
1283 "load module symbols - WARNING: use only with -k and LIVE kernel"),
1293 OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
1294 "separator for columns, no spaces will be added between "
1295 "columns '.' is reserved."),
1316 u64 total = hists__total_period(he->hists); in baseline_percent()
1318 return 100.0 * he->stat.period / total; in baseline_percent()
1329 if (!he->dummy) { in hpp__color_baseline()
1330 scnprintf(pfmt, 20, "%%%d.2f%%%%", dfmt->header_width - 1); in hpp__color_baseline()
1331 return percent_color_snprintf(hpp->buf, hpp->size, in hpp__color_baseline()
1334 return scnprintf(hpp->buf, hpp->size, "%*s", in hpp__color_baseline()
1335 dfmt->header_width, pfmt); in hpp__color_baseline()
1344 if (!he->dummy) in hpp__entry_baseline()
1360 block_he = hists__get_entry(&bh_pair->block_hists, bh->block_idx); in cycles_printf()
1362 hpp->skip = true; in cycles_printf()
1371 bi = block_he->block_info; in cycles_printf()
1373 start_line = map__srcline(he->ms.map, bi->sym->start + bi->start, in cycles_printf()
1374 he->ms.sym); in cycles_printf()
1376 end_line = map__srcline(he->ms.map, bi->sym->start + bi->end, in cycles_printf()
1377 he->ms.sym); in cycles_printf()
1381 scnprintf(buf, sizeof(buf), "[%s -> %s] %4ld", in cycles_printf()
1382 start_line, end_line, block_he->diff.cycles); in cycles_printf()
1384 scnprintf(buf, sizeof(buf), "[%7lx -> %7lx] %4ld", in cycles_printf()
1385 bi->start, bi->end, block_he->diff.cycles); in cycles_printf()
1391 return scnprintf(hpp->buf, hpp->size, "%*s", width, buf); in cycles_printf()
1410 if (bh->block_idx) in __hpp__color_compare()
1411 hpp->skip = true; in __hpp__color_compare()
1419 if (pair->diff.computed) in __hpp__color_compare()
1420 diff = pair->diff.period_ratio_delta; in __hpp__color_compare()
1424 scnprintf(pfmt, 20, "%%%+d.2f%%%%", dfmt->header_width - 1); in __hpp__color_compare()
1425 return percent_color_snprintf(hpp->buf, hpp->size, in __hpp__color_compare()
1428 if (he->dummy) in __hpp__color_compare()
1430 if (pair->diff.computed) in __hpp__color_compare()
1431 diff = pair->diff.period_ratio; in __hpp__color_compare()
1435 scnprintf(pfmt, 20, "%%%d.6f", dfmt->header_width); in __hpp__color_compare()
1436 return value_color_snprintf(hpp->buf, hpp->size, in __hpp__color_compare()
1439 if (he->dummy) in __hpp__color_compare()
1441 if (pair->diff.computed) in __hpp__color_compare()
1442 wdiff = pair->diff.wdiff; in __hpp__color_compare()
1446 scnprintf(pfmt, 20, "%%14ld", dfmt->header_width); in __hpp__color_compare()
1447 return color_snprintf(hpp->buf, hpp->size, in __hpp__color_compare()
1451 return cycles_printf(he, pair, hpp, dfmt->header_width); in __hpp__color_compare()
1456 return scnprintf(hpp->buf, hpp->size, "%*s", in __hpp__color_compare()
1457 dfmt->header_width, "N/A"); in __hpp__color_compare()
1459 return scnprintf(hpp->buf, hpp->size, "%*s", in __hpp__color_compare()
1460 dfmt->header_width, pfmt); in __hpp__color_compare()
1510 printed += scnprintf(bf + printed, size - printed, " "); in print_cycles_spark()
1528 if (bh->block_idx) in hpp__color_cycles_hist()
1529 hpp->skip = true; in hpp__color_cycles_hist()
1536 block_he = hists__get_entry(&bh_pair->block_hists, bh->block_idx); in hpp__color_cycles_hist()
1538 hpp->skip = true; in hpp__color_cycles_hist()
1542 ret = print_cycles_spark(spark, sizeof(spark), block_he->diff.svals, in hpp__color_cycles_hist()
1543 block_he->diff.stats.n); in hpp__color_cycles_hist()
1545 r = rel_stddev_stats(stddev_stats(&block_he->diff.stats), in hpp__color_cycles_hist()
1546 avg_stats(&block_he->diff.stats)); in hpp__color_cycles_hist()
1553 pad = NUM_SPARKS - ((ret - 1) / 3); in hpp__color_cycles_hist()
1555 ret = scnprintf(hpp->buf, hpp->size, "%*s", in hpp__color_cycles_hist()
1556 dfmt->header_width, buf); in hpp__color_cycles_hist()
1559 ret += scnprintf(hpp->buf + ret, hpp->size - ret, in hpp__color_cycles_hist()
1560 "%-*s", pad, " "); in hpp__color_cycles_hist()
1567 return scnprintf(hpp->buf, hpp->size, "%*s", in hpp__color_cycles_hist()
1568 dfmt->header_width, " "); in hpp__color_cycles_hist()
1576 scnprintf(buf, size, "%" PRIu64, he->stat.period); in hpp__entry_unpair()
1595 if (pair->diff.computed) in hpp__entry_pair()
1596 diff = pair->diff.period_ratio_delta; in hpp__entry_pair()
1605 if (he->dummy) { in hpp__entry_pair()
1610 if (pair->diff.computed) in hpp__entry_pair()
1611 ratio = pair->diff.period_ratio; in hpp__entry_pair()
1621 if (he->dummy) { in hpp__entry_pair()
1626 if (pair->diff.computed) in hpp__entry_pair()
1627 wdiff = pair->diff.wdiff; in hpp__entry_pair()
1640 scnprintf(buf, size, "%" PRIu64, pair->stat.period); in hpp__entry_pair()
1653 int idx = dfmt->idx; in __hpp__entry_global()
1676 return scnprintf(hpp->buf, hpp->size, "%s", buf); in hpp__entry_global()
1678 return scnprintf(hpp->buf, hpp->size, "%*s", in hpp__entry_global()
1679 dfmt->header_width, buf); in hpp__entry_global()
1690 BUG_ON(!dfmt->header); in hpp__header()
1691 return scnprintf(hpp->buf, hpp->size, dfmt->header); in hpp__header()
1701 BUG_ON(dfmt->header_width <= 0); in hpp__width()
1702 return dfmt->header_width; in hpp__width()
1713 BUG_ON(dfmt->idx >= PERF_HPP_DIFF__MAX_INDEX); in init_header()
1714 header = columns[dfmt->idx].name; in init_header()
1715 width = columns[dfmt->idx].width; in init_header()
1721 scnprintf(buf, MAX_HEADER_NAME, "%s/%d", header, d->idx); in init_header()
1724 dfmt->header_width = width; in init_header()
1726 if (dfmt->header_width < width) in init_header()
1727 dfmt->header_width = width; in init_header()
1730 dfmt->header_width, NAME); in init_header()
1732 dfmt->header = strdup(buf_indent); in init_header()
1739 struct diff_hpp_fmt *dfmt = &d->fmt[idx]; in data__hpp_register()
1740 struct perf_hpp_fmt *fmt = &dfmt->fmt; in data__hpp_register()
1742 dfmt->idx = idx; in data__hpp_register()
1744 fmt->header = hpp__header; in data__hpp_register()
1745 fmt->width = hpp__width; in data__hpp_register()
1746 fmt->entry = hpp__entry_global; in data__hpp_register()
1747 fmt->cmp = hist_entry__cmp_nop; in data__hpp_register()
1748 fmt->collapse = hist_entry__cmp_nop; in data__hpp_register()
1753 fmt->color = hpp__color_baseline; in data__hpp_register()
1754 fmt->sort = hist_entry__cmp_baseline; in data__hpp_register()
1757 fmt->color = hpp__color_delta; in data__hpp_register()
1758 fmt->sort = hist_entry__cmp_delta; in data__hpp_register()
1761 fmt->color = hpp__color_ratio; in data__hpp_register()
1762 fmt->sort = hist_entry__cmp_ratio; in data__hpp_register()
1765 fmt->color = hpp__color_wdiff; in data__hpp_register()
1766 fmt->sort = hist_entry__cmp_wdiff; in data__hpp_register()
1769 fmt->color = hpp__color_delta; in data__hpp_register()
1770 fmt->sort = hist_entry__cmp_delta_abs; in data__hpp_register()
1773 fmt->color = hpp__color_cycles; in data__hpp_register()
1774 fmt->sort = hist_entry__cmp_nop; in data__hpp_register()
1777 fmt->color = hpp__color_cycles_hist; in data__hpp_register()
1778 fmt->sort = hist_entry__cmp_nop; in data__hpp_register()
1781 fmt->sort = hist_entry__cmp_nop; in data__hpp_register()
1799 * Baseline or compute related columns: in ui_init()
1832 * Prepend an fmt to sort on columns at 'sort_compute' first. in ui_init()
1836 * Note that this column (data) can be compared twice - one in ui_init()
1845 return -1; in ui_init()
1848 fmt->cmp = hist_entry__cmp_nop; in ui_init()
1849 fmt->collapse = hist_entry__cmp_nop; in ui_init()
1853 fmt->sort = hist_entry__cmp_delta_idx; in ui_init()
1856 fmt->sort = hist_entry__cmp_ratio_idx; in ui_init()
1859 fmt->sort = hist_entry__cmp_wdiff_idx; in ui_init()
1862 fmt->sort = hist_entry__cmp_delta_abs_idx; in ui_init()
1866 * Should set since 'fmt->sort' is called without in ui_init()
1869 fmt->sort = hist_entry__cmp_nop; in ui_init()
1905 return -EINVAL; in data_init()
1910 return -ENOMEM; in data_init()
1913 struct perf_data *data = &d->data; in data_init()
1915 data->path = use_default ? defaults[i] : argv[i]; in data_init()
1916 data->mode = PERF_DATA_MODE_READ, in data_init()
1917 data->force = force, in data_init()
1919 d->idx = i; in data_init()
1931 return -1; in diff__config()
1938 } else if (!strcmp(value, "delta-abs")) { in diff__config()
1946 return -1; in diff__config()
1976 return -1; in cmd_diff()
1979 return -1; in cmd_diff()
1982 return -1; in cmd_diff()
1986 return -1; in cmd_diff()
2000 return -1; in cmd_diff()