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->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->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, false, &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, false, &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 perf_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 perf_session__delete(d->session); in __cmd_diff()
1263 OPT_BOOLEAN('b', "baseline-only", &show_baseline_only,
1266 "delta,delta-abs,ratio,wdiff:w1,w2 (default delta-abs),cycles",
1273 OPT_BOOLEAN(0, "cycles-hist", &cycles_hist,
1275 "- WARNING: use only with -c cycles."),
1276 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
1282 "load module symbols - WARNING: use only with -k and LIVE kernel"),
1292 OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
1293 "separator for columns, no spaces will be added between "
1294 "columns '.' is reserved."),
1315 u64 total = hists__total_period(he->hists); in baseline_percent()
1317 return 100.0 * he->stat.period / total; in baseline_percent()
1328 if (!he->dummy) { in hpp__color_baseline()
1329 scnprintf(pfmt, 20, "%%%d.2f%%%%", dfmt->header_width - 1); in hpp__color_baseline()
1330 return percent_color_snprintf(hpp->buf, hpp->size, in hpp__color_baseline()
1333 return scnprintf(hpp->buf, hpp->size, "%*s", in hpp__color_baseline()
1334 dfmt->header_width, pfmt); in hpp__color_baseline()
1343 if (!he->dummy) in hpp__entry_baseline()
1359 block_he = hists__get_entry(&bh_pair->block_hists, bh->block_idx); in cycles_printf()
1361 hpp->skip = true; in cycles_printf()
1370 bi = block_he->block_info; in cycles_printf()
1372 start_line = map__srcline(he->ms.map, bi->sym->start + bi->start, in cycles_printf()
1373 he->ms.sym); in cycles_printf()
1375 end_line = map__srcline(he->ms.map, bi->sym->start + bi->end, in cycles_printf()
1376 he->ms.sym); in cycles_printf()
1380 scnprintf(buf, sizeof(buf), "[%s -> %s] %4ld", in cycles_printf()
1381 start_line, end_line, block_he->diff.cycles); in cycles_printf()
1383 scnprintf(buf, sizeof(buf), "[%7lx -> %7lx] %4ld", in cycles_printf()
1384 bi->start, bi->end, block_he->diff.cycles); in cycles_printf()
1390 return scnprintf(hpp->buf, hpp->size, "%*s", width, buf); in cycles_printf()
1409 if (bh->block_idx) in __hpp__color_compare()
1410 hpp->skip = true; in __hpp__color_compare()
1418 if (pair->diff.computed) in __hpp__color_compare()
1419 diff = pair->diff.period_ratio_delta; in __hpp__color_compare()
1423 scnprintf(pfmt, 20, "%%%+d.2f%%%%", dfmt->header_width - 1); in __hpp__color_compare()
1424 return percent_color_snprintf(hpp->buf, hpp->size, in __hpp__color_compare()
1427 if (he->dummy) in __hpp__color_compare()
1429 if (pair->diff.computed) in __hpp__color_compare()
1430 diff = pair->diff.period_ratio; in __hpp__color_compare()
1434 scnprintf(pfmt, 20, "%%%d.6f", dfmt->header_width); in __hpp__color_compare()
1435 return value_color_snprintf(hpp->buf, hpp->size, in __hpp__color_compare()
1438 if (he->dummy) in __hpp__color_compare()
1440 if (pair->diff.computed) in __hpp__color_compare()
1441 wdiff = pair->diff.wdiff; in __hpp__color_compare()
1445 scnprintf(pfmt, 20, "%%14ld", dfmt->header_width); in __hpp__color_compare()
1446 return color_snprintf(hpp->buf, hpp->size, in __hpp__color_compare()
1450 return cycles_printf(he, pair, hpp, dfmt->header_width); in __hpp__color_compare()
1455 return scnprintf(hpp->buf, hpp->size, "%*s", in __hpp__color_compare()
1456 dfmt->header_width, "N/A"); in __hpp__color_compare()
1458 return scnprintf(hpp->buf, hpp->size, "%*s", in __hpp__color_compare()
1459 dfmt->header_width, pfmt); in __hpp__color_compare()
1509 printed += scnprintf(bf + printed, size - printed, " "); in print_cycles_spark()
1527 if (bh->block_idx) in hpp__color_cycles_hist()
1528 hpp->skip = true; in hpp__color_cycles_hist()
1535 block_he = hists__get_entry(&bh_pair->block_hists, bh->block_idx); in hpp__color_cycles_hist()
1537 hpp->skip = true; in hpp__color_cycles_hist()
1541 ret = print_cycles_spark(spark, sizeof(spark), block_he->diff.svals, in hpp__color_cycles_hist()
1542 block_he->diff.stats.n); in hpp__color_cycles_hist()
1544 r = rel_stddev_stats(stddev_stats(&block_he->diff.stats), in hpp__color_cycles_hist()
1545 avg_stats(&block_he->diff.stats)); in hpp__color_cycles_hist()
1552 pad = NUM_SPARKS - ((ret - 1) / 3); in hpp__color_cycles_hist()
1554 ret = scnprintf(hpp->buf, hpp->size, "%*s", in hpp__color_cycles_hist()
1555 dfmt->header_width, buf); in hpp__color_cycles_hist()
1558 ret += scnprintf(hpp->buf + ret, hpp->size - ret, in hpp__color_cycles_hist()
1559 "%-*s", pad, " "); in hpp__color_cycles_hist()
1566 return scnprintf(hpp->buf, hpp->size, "%*s", in hpp__color_cycles_hist()
1567 dfmt->header_width, " "); in hpp__color_cycles_hist()
1575 scnprintf(buf, size, "%" PRIu64, he->stat.period); in hpp__entry_unpair()
1594 if (pair->diff.computed) in hpp__entry_pair()
1595 diff = pair->diff.period_ratio_delta; in hpp__entry_pair()
1604 if (he->dummy) { in hpp__entry_pair()
1609 if (pair->diff.computed) in hpp__entry_pair()
1610 ratio = pair->diff.period_ratio; in hpp__entry_pair()
1620 if (he->dummy) { in hpp__entry_pair()
1625 if (pair->diff.computed) in hpp__entry_pair()
1626 wdiff = pair->diff.wdiff; in hpp__entry_pair()
1639 scnprintf(buf, size, "%" PRIu64, pair->stat.period); in hpp__entry_pair()
1652 int idx = dfmt->idx; in __hpp__entry_global()
1675 return scnprintf(hpp->buf, hpp->size, "%s", buf); in hpp__entry_global()
1677 return scnprintf(hpp->buf, hpp->size, "%*s", in hpp__entry_global()
1678 dfmt->header_width, buf); in hpp__entry_global()
1689 BUG_ON(!dfmt->header); in hpp__header()
1690 return scnprintf(hpp->buf, hpp->size, dfmt->header); in hpp__header()
1700 BUG_ON(dfmt->header_width <= 0); in hpp__width()
1701 return dfmt->header_width; in hpp__width()
1712 BUG_ON(dfmt->idx >= PERF_HPP_DIFF__MAX_INDEX); in init_header()
1713 header = columns[dfmt->idx].name; in init_header()
1714 width = columns[dfmt->idx].width; in init_header()
1720 scnprintf(buf, MAX_HEADER_NAME, "%s/%d", header, d->idx); in init_header()
1723 dfmt->header_width = width; in init_header()
1725 if (dfmt->header_width < width) in init_header()
1726 dfmt->header_width = width; in init_header()
1729 dfmt->header_width, NAME); in init_header()
1731 dfmt->header = strdup(buf_indent); in init_header()
1738 struct diff_hpp_fmt *dfmt = &d->fmt[idx]; in data__hpp_register()
1739 struct perf_hpp_fmt *fmt = &dfmt->fmt; in data__hpp_register()
1741 dfmt->idx = idx; in data__hpp_register()
1743 fmt->header = hpp__header; in data__hpp_register()
1744 fmt->width = hpp__width; in data__hpp_register()
1745 fmt->entry = hpp__entry_global; in data__hpp_register()
1746 fmt->cmp = hist_entry__cmp_nop; in data__hpp_register()
1747 fmt->collapse = hist_entry__cmp_nop; in data__hpp_register()
1752 fmt->color = hpp__color_baseline; in data__hpp_register()
1753 fmt->sort = hist_entry__cmp_baseline; in data__hpp_register()
1756 fmt->color = hpp__color_delta; in data__hpp_register()
1757 fmt->sort = hist_entry__cmp_delta; in data__hpp_register()
1760 fmt->color = hpp__color_ratio; in data__hpp_register()
1761 fmt->sort = hist_entry__cmp_ratio; in data__hpp_register()
1764 fmt->color = hpp__color_wdiff; in data__hpp_register()
1765 fmt->sort = hist_entry__cmp_wdiff; in data__hpp_register()
1768 fmt->color = hpp__color_delta; in data__hpp_register()
1769 fmt->sort = hist_entry__cmp_delta_abs; in data__hpp_register()
1772 fmt->color = hpp__color_cycles; in data__hpp_register()
1773 fmt->sort = hist_entry__cmp_nop; in data__hpp_register()
1776 fmt->color = hpp__color_cycles_hist; in data__hpp_register()
1777 fmt->sort = hist_entry__cmp_nop; in data__hpp_register()
1780 fmt->sort = hist_entry__cmp_nop; in data__hpp_register()
1798 * Baseline or compute realted columns: in ui_init()
1831 * Prepend an fmt to sort on columns at 'sort_compute' first. in ui_init()
1835 * Note that this column (data) can be compared twice - one in ui_init()
1844 return -1; in ui_init()
1847 fmt->cmp = hist_entry__cmp_nop; in ui_init()
1848 fmt->collapse = hist_entry__cmp_nop; in ui_init()
1852 fmt->sort = hist_entry__cmp_delta_idx; in ui_init()
1855 fmt->sort = hist_entry__cmp_ratio_idx; in ui_init()
1858 fmt->sort = hist_entry__cmp_wdiff_idx; in ui_init()
1861 fmt->sort = hist_entry__cmp_delta_abs_idx; in ui_init()
1865 * Should set since 'fmt->sort' is called without in ui_init()
1868 fmt->sort = hist_entry__cmp_nop; in ui_init()
1904 return -EINVAL; in data_init()
1909 return -ENOMEM; in data_init()
1912 struct perf_data *data = &d->data; in data_init()
1914 data->path = use_default ? defaults[i] : argv[i]; in data_init()
1915 data->mode = PERF_DATA_MODE_READ, in data_init()
1916 data->force = force, in data_init()
1918 d->idx = i; in data_init()
1930 return -1; in diff__config()
1937 } else if (!strcmp(value, "delta-abs")) { in diff__config()
1945 return -1; in diff__config()
1975 return -1; in cmd_diff()
1978 return -1; in cmd_diff()
1981 return -1; in cmd_diff()
1985 return -1; in cmd_diff()
1999 return -1; in cmd_diff()