1 // SPDX-License-Identifier: GPL-2.0
5 * Builtin diff command: Analyze two perf.data input files, look up and read
6 * DSOs and symbol information, sort them and produce a diff.
11 #include "util/debug.h"
12 #include "util/event.h"
13 #include "util/hist.h"
14 #include "util/evsel.h"
15 #include "util/evlist.h"
16 #include "util/session.h"
17 #include "util/tool.h"
18 #include "util/sort.h"
19 #include "util/srcline.h"
20 #include "util/symbol.h"
21 #include "util/data.h"
22 #include "util/config.h"
23 #include "util/time-utils.h"
24 #include "util/annotate.h"
26 #include "util/spark.h"
27 #include "util/block-info.h"
28 #include "util/stream.h"
29 #include "util/util.h"
30 #include <linux/err.h>
31 #include <linux/zalloc.h>
32 #include <subcmd/pager.h>
33 #include <subcmd/parse-options.h>
41 struct perf_tool tool;
43 struct perf_time_interval *ptime_range;
50 /* Diff command specific HPP columns. */
52 PERF_HPP_DIFF__BASELINE,
53 PERF_HPP_DIFF__PERIOD,
54 PERF_HPP_DIFF__PERIOD_BASELINE,
57 PERF_HPP_DIFF__WEIGHTED_DIFF,
58 PERF_HPP_DIFF__FORMULA,
59 PERF_HPP_DIFF__DELTA_ABS,
60 PERF_HPP_DIFF__CYCLES,
61 PERF_HPP_DIFF__CYCLES_HIST,
63 PERF_HPP_DIFF__MAX_INDEX
67 struct perf_hpp_fmt fmt;
74 struct perf_session *session;
75 struct perf_data data;
78 struct evlist_streams *evlist_streams;
79 struct diff_hpp_fmt fmt[PERF_HPP_DIFF__MAX_INDEX];
82 static struct data__file *data__files;
83 static int data__files_cnt;
85 #define data__for_each_file_start(i, d, s) \
86 for (i = s, d = &data__files[s]; \
87 i < data__files_cnt; \
88 i++, d = &data__files[i])
90 #define data__for_each_file(i, d) data__for_each_file_start(i, d, 0)
91 #define data__for_each_file_new(i, d) data__for_each_file_start(i, d, 1)
94 static bool show_period;
95 static bool show_formula;
96 static bool show_baseline_only;
97 static bool cycles_hist;
98 static unsigned int sort_compute = 1;
100 static s64 compute_wdiff_w1;
101 static s64 compute_wdiff_w2;
103 static const char *cpu_list;
104 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
109 COMPUTE_WEIGHTED_DIFF,
113 COMPUTE_STREAM, /* After COMPUTE_MAX to avoid use current compute arrays */
116 const char *compute_names[COMPUTE_MAX] = {
117 [COMPUTE_DELTA] = "delta",
118 [COMPUTE_DELTA_ABS] = "delta-abs",
119 [COMPUTE_RATIO] = "ratio",
120 [COMPUTE_WEIGHTED_DIFF] = "wdiff",
121 [COMPUTE_CYCLES] = "cycles",
124 static int compute = COMPUTE_DELTA_ABS;
126 static int compute_2_hpp[COMPUTE_MAX] = {
127 [COMPUTE_DELTA] = PERF_HPP_DIFF__DELTA,
128 [COMPUTE_DELTA_ABS] = PERF_HPP_DIFF__DELTA_ABS,
129 [COMPUTE_RATIO] = PERF_HPP_DIFF__RATIO,
130 [COMPUTE_WEIGHTED_DIFF] = PERF_HPP_DIFF__WEIGHTED_DIFF,
131 [COMPUTE_CYCLES] = PERF_HPP_DIFF__CYCLES,
134 #define MAX_COL_WIDTH 70
136 static struct header_column {
139 } columns[PERF_HPP_DIFF__MAX_INDEX] = {
140 [PERF_HPP_DIFF__BASELINE] = {
143 [PERF_HPP_DIFF__PERIOD] = {
147 [PERF_HPP_DIFF__PERIOD_BASELINE] = {
148 .name = "Base period",
151 [PERF_HPP_DIFF__DELTA] = {
155 [PERF_HPP_DIFF__DELTA_ABS] = {
159 [PERF_HPP_DIFF__RATIO] = {
163 [PERF_HPP_DIFF__WEIGHTED_DIFF] = {
164 .name = "Weighted diff",
167 [PERF_HPP_DIFF__FORMULA] = {
169 .width = MAX_COL_WIDTH,
171 [PERF_HPP_DIFF__CYCLES] = {
172 .name = "[Program Block Range] Cycles Diff",
175 [PERF_HPP_DIFF__CYCLES_HIST] = {
176 .name = "stddev/Hist",
177 .width = NUM_SPARKS + 9,
181 static int setup_compute_opt_wdiff(char *opt)
191 w2_str = strchr(opt, ',');
199 compute_wdiff_w1 = strtol(w1_str, NULL, 10);
200 compute_wdiff_w2 = strtol(w2_str, NULL, 10);
202 if (!compute_wdiff_w1 || !compute_wdiff_w2)
205 pr_debug("compute wdiff w1(%" PRId64 ") w2(%" PRId64 ")\n",
206 compute_wdiff_w1, compute_wdiff_w2);
212 pr_err("Failed: wrong weight data, use 'wdiff:w1,w2'\n");
217 static int setup_compute_opt(char *opt)
219 if (compute == COMPUTE_WEIGHTED_DIFF)
220 return setup_compute_opt_wdiff(opt);
223 pr_err("Failed: extra option specified '%s'", opt);
230 static int setup_compute(const struct option *opt, const char *str,
231 int unset __maybe_unused)
233 int *cp = (int *) opt->value;
234 char *cstr = (char *) str;
244 option = strchr(str, ':');
246 unsigned len = option++ - str;
249 * The str data are not writeable, so we need
250 * to use another buffer.
253 /* No option value is longer. */
254 if (len >= sizeof(buf))
257 strncpy(buf, str, len);
262 for (i = 0; i < COMPUTE_MAX; i++)
263 if (!strcmp(cstr, compute_names[i])) {
265 return setup_compute_opt(option);
268 pr_err("Failed: '%s' is not computation method "
269 "(use 'delta','ratio' or 'wdiff')\n", str);
273 static double period_percent(struct hist_entry *he, u64 period)
275 u64 total = hists__total_period(he->hists);
277 return (period * 100.0) / total;
280 static double compute_delta(struct hist_entry *he, struct hist_entry *pair)
282 double old_percent = period_percent(he, he->stat.period);
283 double new_percent = period_percent(pair, pair->stat.period);
285 pair->diff.period_ratio_delta = new_percent - old_percent;
286 pair->diff.computed = true;
287 return pair->diff.period_ratio_delta;
290 static double compute_ratio(struct hist_entry *he, struct hist_entry *pair)
292 double old_period = he->stat.period ?: 1;
293 double new_period = pair->stat.period;
295 pair->diff.computed = true;
296 pair->diff.period_ratio = new_period / old_period;
297 return pair->diff.period_ratio;
300 static s64 compute_wdiff(struct hist_entry *he, struct hist_entry *pair)
302 u64 old_period = he->stat.period;
303 u64 new_period = pair->stat.period;
305 pair->diff.computed = true;
306 pair->diff.wdiff = new_period * compute_wdiff_w2 -
307 old_period * compute_wdiff_w1;
309 return pair->diff.wdiff;
312 static int formula_delta(struct hist_entry *he, struct hist_entry *pair,
313 char *buf, size_t size)
315 u64 he_total = he->hists->stats.total_period;
316 u64 pair_total = pair->hists->stats.total_period;
318 if (symbol_conf.filter_relative) {
319 he_total = he->hists->stats.total_non_filtered_period;
320 pair_total = pair->hists->stats.total_non_filtered_period;
322 return scnprintf(buf, size,
323 "(%" PRIu64 " * 100 / %" PRIu64 ") - "
324 "(%" PRIu64 " * 100 / %" PRIu64 ")",
325 pair->stat.period, pair_total,
326 he->stat.period, he_total);
329 static int formula_ratio(struct hist_entry *he, struct hist_entry *pair,
330 char *buf, size_t size)
332 double old_period = he->stat.period;
333 double new_period = pair->stat.period;
335 return scnprintf(buf, size, "%.0F / %.0F", new_period, old_period);
338 static int formula_wdiff(struct hist_entry *he, struct hist_entry *pair,
339 char *buf, size_t size)
341 u64 old_period = he->stat.period;
342 u64 new_period = pair->stat.period;
344 return scnprintf(buf, size,
345 "(%" PRIu64 " * " "%" PRId64 ") - (%" PRIu64 " * " "%" PRId64 ")",
346 new_period, compute_wdiff_w2, old_period, compute_wdiff_w1);
349 static int formula_fprintf(struct hist_entry *he, struct hist_entry *pair,
350 char *buf, size_t size)
354 case COMPUTE_DELTA_ABS:
355 return formula_delta(he, pair, buf, size);
357 return formula_ratio(he, pair, buf, size);
358 case COMPUTE_WEIGHTED_DIFF:
359 return formula_wdiff(he, pair, buf, size);
367 static void *block_hist_zalloc(size_t size)
369 struct block_hist *bh;
371 bh = zalloc(size + sizeof(*bh));
378 static void block_hist_free(void *he)
380 struct block_hist *bh;
382 bh = container_of(he, struct block_hist, he);
383 hists__delete_entries(&bh->block_hists);
387 struct hist_entry_ops block_hist_ops = {
388 .new = block_hist_zalloc,
389 .free = block_hist_free,
392 static int diff__process_sample_event(const struct perf_tool *tool,
393 union perf_event *event,
394 struct perf_sample *sample,
396 struct machine *machine)
398 struct perf_diff *pdiff = container_of(tool, struct perf_diff, tool);
399 struct addr_location al;
400 struct hists *hists = evsel__hists(evsel);
401 struct hist_entry_iter iter = {
404 .ops = &hist_iter_normal,
408 if (perf_time__ranges_skip_sample(pdiff->ptime_range, pdiff->range_num,
413 addr_location__init(&al);
414 if (machine__resolve(machine, &al, sample) < 0) {
415 pr_warning("problem processing %d event, skipping it.\n",
421 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) {
428 if (!hists__add_entry_ops(hists, &block_hist_ops, &al, NULL,
429 NULL, NULL, NULL, sample, true)) {
430 pr_warning("problem incrementing symbol period, "
435 hist__account_cycles(sample->branch_stack, &al, sample,
440 if (hist_entry_iter__add(&iter, &al, PERF_MAX_STACK_DEPTH,
442 pr_debug("problem adding hist entry, skipping event\n");
448 if (!hists__add_entry(hists, &al, NULL, NULL, NULL, NULL, sample,
450 pr_warning("problem incrementing symbol period, "
457 * The total_period is updated here before going to the output
458 * tree since normally only the baseline hists will call
459 * hists__output_resort() and precompute needs the total
460 * period in order to sort entries by percentage delta.
462 hists->stats.total_period += sample->period;
464 hists->stats.total_non_filtered_period += sample->period;
467 addr_location__exit(&al);
471 static struct perf_diff pdiff;
473 static struct evsel *evsel_match(struct evsel *evsel, struct evlist *evlist)
477 evlist__for_each_entry(evlist, e) {
478 if ((evsel->core.attr.type == e->core.attr.type) &&
479 (evsel->core.attr.config == e->core.attr.config))
486 static void evlist__collapse_resort(struct evlist *evlist)
490 evlist__for_each_entry(evlist, evsel) {
491 struct hists *hists = evsel__hists(evsel);
493 hists__collapse_resort(hists, NULL);
497 static struct data__file *fmt_to_data_file(struct perf_hpp_fmt *fmt)
499 struct diff_hpp_fmt *dfmt = container_of(fmt, struct diff_hpp_fmt, fmt);
500 void *ptr = dfmt - dfmt->idx;
501 struct data__file *d = container_of(ptr, struct data__file, fmt);
506 static struct hist_entry*
507 get_pair_data(struct hist_entry *he, struct data__file *d)
509 if (hist_entry__has_pairs(he)) {
510 struct hist_entry *pair;
512 list_for_each_entry(pair, &he->pairs.head, pairs.node)
513 if (pair->hists == d->hists)
520 static struct hist_entry*
521 get_pair_fmt(struct hist_entry *he, struct diff_hpp_fmt *dfmt)
523 struct data__file *d = fmt_to_data_file(&dfmt->fmt);
525 return get_pair_data(he, d);
528 static void hists__baseline_only(struct hists *hists)
530 struct rb_root_cached *root;
531 struct rb_node *next;
533 if (hists__has(hists, need_collapse))
534 root = &hists->entries_collapsed;
536 root = hists->entries_in;
538 next = rb_first_cached(root);
539 while (next != NULL) {
540 struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node_in);
542 next = rb_next(&he->rb_node_in);
543 if (!hist_entry__next_pair(he)) {
544 rb_erase_cached(&he->rb_node_in, root);
545 hist_entry__delete(he);
550 static int64_t block_cycles_diff_cmp(struct hist_entry *left,
551 struct hist_entry *right)
553 bool pairs_left = hist_entry__has_pairs(left);
554 bool pairs_right = hist_entry__has_pairs(right);
557 if (!pairs_left && !pairs_right)
560 l = llabs(left->diff.cycles);
561 r = llabs(right->diff.cycles);
565 static int64_t block_sort(struct perf_hpp_fmt *fmt __maybe_unused,
566 struct hist_entry *left, struct hist_entry *right)
568 return block_cycles_diff_cmp(right, left);
571 static void init_block_hist(struct block_hist *bh)
573 __hists__init(&bh->block_hists, &bh->block_list);
574 perf_hpp_list__init(&bh->block_list);
576 INIT_LIST_HEAD(&bh->block_fmt.list);
577 INIT_LIST_HEAD(&bh->block_fmt.sort_list);
578 bh->block_fmt.cmp = block_info__cmp;
579 bh->block_fmt.sort = block_sort;
580 perf_hpp_list__register_sort_field(&bh->block_list,
585 static struct hist_entry *get_block_pair(struct hist_entry *he,
586 struct hists *hists_pair)
588 struct rb_root_cached *root = hists_pair->entries_in;
589 struct rb_node *next = rb_first_cached(root);
592 while (next != NULL) {
593 struct hist_entry *he_pair = rb_entry(next, struct hist_entry,
596 next = rb_next(&he_pair->rb_node_in);
598 cmp = __block_info__cmp(he_pair, he);
606 static void init_spark_values(unsigned long *svals, int num)
608 for (int i = 0; i < num; i++)
612 static void update_spark_value(unsigned long *svals, int num,
613 struct stats *stats, u64 val)
621 static void compute_cycles_diff(struct hist_entry *he,
622 struct hist_entry *pair)
624 pair->diff.computed = true;
625 if (pair->block_info->num && he->block_info->num) {
627 pair->block_info->cycles_aggr / pair->block_info->num_aggr -
628 he->block_info->cycles_aggr / he->block_info->num_aggr;
633 init_stats(&pair->diff.stats);
634 init_spark_values(pair->diff.svals, NUM_SPARKS);
636 for (int i = 0; i < pair->block_info->num; i++) {
639 if (i >= he->block_info->num || i >= NUM_SPARKS)
642 val = llabs(pair->block_info->cycles_spark[i] -
643 he->block_info->cycles_spark[i]);
645 update_spark_value(pair->diff.svals, NUM_SPARKS,
646 &pair->diff.stats, val);
647 update_stats(&pair->diff.stats, val);
652 static void block_hists_match(struct hists *hists_base,
653 struct hists *hists_pair)
655 struct rb_root_cached *root = hists_base->entries_in;
656 struct rb_node *next = rb_first_cached(root);
658 while (next != NULL) {
659 struct hist_entry *he = rb_entry(next, struct hist_entry,
661 struct hist_entry *pair = get_block_pair(he, hists_pair);
663 next = rb_next(&he->rb_node_in);
666 hist_entry__add_pair(pair, he);
667 compute_cycles_diff(he, pair);
672 static void hists__precompute(struct hists *hists)
674 struct rb_root_cached *root;
675 struct rb_node *next;
677 if (hists__has(hists, need_collapse))
678 root = &hists->entries_collapsed;
680 root = hists->entries_in;
682 next = rb_first_cached(root);
683 while (next != NULL) {
684 struct block_hist *bh, *pair_bh;
685 struct hist_entry *he, *pair;
686 struct data__file *d;
689 he = rb_entry(next, struct hist_entry, rb_node_in);
690 next = rb_next(&he->rb_node_in);
692 if (compute == COMPUTE_CYCLES) {
693 bh = container_of(he, struct block_hist, he);
695 block_info__process_sym(he, bh, NULL, 0, 0);
698 data__for_each_file_new(i, d) {
699 pair = get_pair_data(he, d);
705 case COMPUTE_DELTA_ABS:
706 compute_delta(he, pair);
709 compute_ratio(he, pair);
711 case COMPUTE_WEIGHTED_DIFF:
712 compute_wdiff(he, pair);
715 pair_bh = container_of(pair, struct block_hist,
717 init_block_hist(pair_bh);
718 block_info__process_sym(pair, pair_bh, NULL, 0, 0);
720 bh = container_of(he, struct block_hist, he);
722 if (bh->valid && pair_bh->valid) {
723 block_hists_match(&bh->block_hists,
724 &pair_bh->block_hists);
725 hists__output_resort(&pair_bh->block_hists,
736 static int64_t cmp_doubles(double l, double r)
747 __hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right,
753 double l = left->diff.period_ratio_delta;
754 double r = right->diff.period_ratio_delta;
756 return cmp_doubles(l, r);
758 case COMPUTE_DELTA_ABS:
760 double l = fabs(left->diff.period_ratio_delta);
761 double r = fabs(right->diff.period_ratio_delta);
763 return cmp_doubles(l, r);
767 double l = left->diff.period_ratio;
768 double r = right->diff.period_ratio;
770 return cmp_doubles(l, r);
772 case COMPUTE_WEIGHTED_DIFF:
774 s64 l = left->diff.wdiff;
775 s64 r = right->diff.wdiff;
787 hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right,
790 bool pairs_left = hist_entry__has_pairs(left);
791 bool pairs_right = hist_entry__has_pairs(right);
792 struct hist_entry *p_right, *p_left;
794 if (!pairs_left && !pairs_right)
797 if (!pairs_left || !pairs_right)
798 return pairs_left ? -1 : 1;
800 p_left = get_pair_data(left, &data__files[sort_idx]);
801 p_right = get_pair_data(right, &data__files[sort_idx]);
803 if (!p_left && !p_right)
806 if (!p_left || !p_right)
807 return p_left ? -1 : 1;
810 * We have 2 entries of same kind, let's
811 * make the data comparison.
813 return __hist_entry__cmp_compute(p_left, p_right, c);
817 hist_entry__cmp_compute_idx(struct hist_entry *left, struct hist_entry *right,
820 struct hist_entry *p_right, *p_left;
822 p_left = get_pair_data(left, &data__files[sort_idx]);
823 p_right = get_pair_data(right, &data__files[sort_idx]);
825 if (!p_left && !p_right)
828 if (!p_left || !p_right)
829 return p_left ? -1 : 1;
831 if (c != COMPUTE_DELTA && c != COMPUTE_DELTA_ABS) {
833 * The delta can be computed without the baseline, but
834 * others are not. Put those entries which have no
837 if (left->dummy && right->dummy)
840 if (left->dummy || right->dummy)
841 return left->dummy ? 1 : -1;
844 return __hist_entry__cmp_compute(p_left, p_right, c);
848 hist_entry__cmp_nop(struct perf_hpp_fmt *fmt __maybe_unused,
849 struct hist_entry *left __maybe_unused,
850 struct hist_entry *right __maybe_unused)
856 hist_entry__cmp_baseline(struct perf_hpp_fmt *fmt __maybe_unused,
857 struct hist_entry *left, struct hist_entry *right)
859 if (left->stat.period == right->stat.period)
861 return left->stat.period > right->stat.period ? 1 : -1;
865 hist_entry__cmp_delta(struct perf_hpp_fmt *fmt,
866 struct hist_entry *left, struct hist_entry *right)
868 struct data__file *d = fmt_to_data_file(fmt);
870 return hist_entry__cmp_compute(right, left, COMPUTE_DELTA, d->idx);
874 hist_entry__cmp_delta_abs(struct perf_hpp_fmt *fmt,
875 struct hist_entry *left, struct hist_entry *right)
877 struct data__file *d = fmt_to_data_file(fmt);
879 return hist_entry__cmp_compute(right, left, COMPUTE_DELTA_ABS, d->idx);
883 hist_entry__cmp_ratio(struct perf_hpp_fmt *fmt,
884 struct hist_entry *left, struct hist_entry *right)
886 struct data__file *d = fmt_to_data_file(fmt);
888 return hist_entry__cmp_compute(right, left, COMPUTE_RATIO, d->idx);
892 hist_entry__cmp_wdiff(struct perf_hpp_fmt *fmt,
893 struct hist_entry *left, struct hist_entry *right)
895 struct data__file *d = fmt_to_data_file(fmt);
897 return hist_entry__cmp_compute(right, left, COMPUTE_WEIGHTED_DIFF, d->idx);
901 hist_entry__cmp_delta_idx(struct perf_hpp_fmt *fmt __maybe_unused,
902 struct hist_entry *left, struct hist_entry *right)
904 return hist_entry__cmp_compute_idx(right, left, COMPUTE_DELTA,
909 hist_entry__cmp_delta_abs_idx(struct perf_hpp_fmt *fmt __maybe_unused,
910 struct hist_entry *left, struct hist_entry *right)
912 return hist_entry__cmp_compute_idx(right, left, COMPUTE_DELTA_ABS,
917 hist_entry__cmp_ratio_idx(struct perf_hpp_fmt *fmt __maybe_unused,
918 struct hist_entry *left, struct hist_entry *right)
920 return hist_entry__cmp_compute_idx(right, left, COMPUTE_RATIO,
925 hist_entry__cmp_wdiff_idx(struct perf_hpp_fmt *fmt __maybe_unused,
926 struct hist_entry *left, struct hist_entry *right)
928 return hist_entry__cmp_compute_idx(right, left, COMPUTE_WEIGHTED_DIFF,
932 static void hists__process(struct hists *hists)
934 if (show_baseline_only)
935 hists__baseline_only(hists);
937 hists__precompute(hists);
938 hists__output_resort(hists, NULL);
940 if (compute == COMPUTE_CYCLES)
941 symbol_conf.report_block = true;
943 hists__fprintf(hists, !quiet, 0, 0, 0, stdout,
944 !symbol_conf.use_callchain);
947 static void data__fprintf(void)
949 struct data__file *d;
952 fprintf(stdout, "# Data files:\n");
954 data__for_each_file(i, d)
955 fprintf(stdout, "# [%d] %s %s\n",
956 d->idx, d->data.path,
957 !d->idx ? "(Baseline)" : "");
959 fprintf(stdout, "#\n");
962 static void data_process(void)
964 struct evlist *evlist_base = data__files[0].session->evlist;
965 struct evsel *evsel_base;
968 evlist__for_each_entry(evlist_base, evsel_base) {
969 struct hists *hists_base = evsel__hists(evsel_base);
970 struct data__file *d;
973 data__for_each_file_new(i, d) {
974 struct evlist *evlist = d->session->evlist;
978 evsel = evsel_match(evsel_base, evlist);
982 hists = evsel__hists(evsel);
985 hists__match(hists_base, hists);
987 if (!show_baseline_only)
988 hists__link(hists_base, hists);
992 fprintf(stdout, "%s# Event '%s'\n#\n", first ? "" : "\n",
993 evsel__name(evsel_base));
998 if (verbose > 0 || ((data__files_cnt > 2) && !quiet))
1001 /* Don't sort callchain for perf diff */
1002 evsel__reset_sample_bit(evsel_base, CALLCHAIN);
1004 hists__process(hists_base);
1008 static int process_base_stream(struct data__file *data_base,
1009 struct data__file *data_pair,
1010 const char *title __maybe_unused)
1012 struct evlist *evlist_base = data_base->session->evlist;
1013 struct evlist *evlist_pair = data_pair->session->evlist;
1014 struct evsel *evsel_base, *evsel_pair;
1015 struct evsel_streams *es_base, *es_pair;
1017 evlist__for_each_entry(evlist_base, evsel_base) {
1018 evsel_pair = evsel_match(evsel_base, evlist_pair);
1022 es_base = evsel_streams__entry(data_base->evlist_streams,
1027 es_pair = evsel_streams__entry(data_pair->evlist_streams,
1032 evsel_streams__match(es_base, es_pair);
1033 evsel_streams__report(es_base, es_pair);
1039 static void stream_process(void)
1042 * Stream comparison only supports two data files.
1043 * perf.data.old and perf.data. data__files[0] is perf.data.old,
1044 * data__files[1] is perf.data.
1046 process_base_stream(&data__files[0], &data__files[1],
1047 "# Output based on old perf data:\n#\n");
1050 static void data__free(struct data__file *d)
1054 if (d->evlist_streams)
1055 evlist_streams__delete(d->evlist_streams);
1057 for (col = 0; col < PERF_HPP_DIFF__MAX_INDEX; col++) {
1058 struct diff_hpp_fmt *fmt = &d->fmt[col];
1060 zfree(&fmt->header);
1064 static int abstime_str_dup(char **pstr)
1068 if (pdiff.time_str && strchr(pdiff.time_str, ':')) {
1069 str = strdup(pdiff.time_str);
1078 static int parse_absolute_time(struct data__file *d, char **pstr)
1084 * Absolute timestamp for one file has the format: a.b,c.d
1085 * For multiple files, the format is: a.b,c.d:a.b,c.d
1087 p = strchr(*pstr, ':');
1090 pr_err("Invalid time string\n");
1097 pr_err("Invalid time string\n");
1102 ret = perf_time__parse_for_ranges(*pstr, d->session,
1117 static int parse_percent_time(struct data__file *d)
1121 ret = perf_time__parse_for_ranges(pdiff.time_str, d->session,
1128 static int parse_time_str(struct data__file *d, char *abstime_ostr,
1129 char **pabstime_tmp)
1134 ret = parse_absolute_time(d, pabstime_tmp);
1135 else if (pdiff.time_str)
1136 ret = parse_percent_time(d);
1141 static int check_file_brstack(void)
1143 struct data__file *d;
1147 data__for_each_file(i, d) {
1148 d->session = perf_session__new(&d->data, &pdiff.tool);
1149 if (IS_ERR(d->session)) {
1150 pr_err("Failed to open %s\n", d->data.path);
1151 return PTR_ERR(d->session);
1154 has_br_stack = perf_header__has_feat(&d->session->header,
1155 HEADER_BRANCH_STACK);
1156 perf_session__delete(d->session);
1161 /* Set only all files having branch stacks */
1162 pdiff.has_br_stack = true;
1166 static int __cmd_diff(void)
1168 struct data__file *d;
1170 char *abstime_ostr, *abstime_tmp;
1172 ret = abstime_str_dup(&abstime_ostr);
1176 abstime_tmp = abstime_ostr;
1179 data__for_each_file(i, d) {
1180 d->session = perf_session__new(&d->data, &pdiff.tool);
1181 if (IS_ERR(d->session)) {
1182 ret = PTR_ERR(d->session);
1183 pr_err("Failed to open %s\n", d->data.path);
1187 if (pdiff.time_str) {
1188 ret = parse_time_str(d, abstime_ostr, &abstime_tmp);
1194 ret = perf_session__cpu_bitmap(d->session, cpu_list,
1200 ret = perf_session__process_events(d->session);
1202 pr_err("Failed to process %s\n", d->data.path);
1206 evlist__collapse_resort(d->session->evlist);
1208 if (pdiff.ptime_range)
1209 zfree(&pdiff.ptime_range);
1211 if (compute == COMPUTE_STREAM) {
1212 d->evlist_streams = evlist__create_streams(
1213 d->session->evlist, 5);
1214 if (!d->evlist_streams) {
1221 if (compute == COMPUTE_STREAM)
1227 data__for_each_file(i, d) {
1228 if (!IS_ERR(d->session))
1229 perf_session__delete(d->session);
1235 if (pdiff.ptime_range)
1236 zfree(&pdiff.ptime_range);
1244 static const char * const diff_usage[] = {
1245 "perf diff [<options>] [old_file] [new_file]",
1249 static const struct option options[] = {
1250 OPT_INCR('v', "verbose", &verbose,
1251 "be more verbose (show symbol address, etc)"),
1252 OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any warnings or messages"),
1253 OPT_BOOLEAN('b', "baseline-only", &show_baseline_only,
1254 "Show only items with match in baseline"),
1255 OPT_CALLBACK('c', "compute", &compute,
1256 "delta,delta-abs,ratio,wdiff:w1,w2 (default delta-abs),cycles",
1257 "Entries differential computation selection",
1259 OPT_BOOLEAN('p', "period", &show_period,
1260 "Show period values."),
1261 OPT_BOOLEAN('F', "formula", &show_formula,
1263 OPT_BOOLEAN(0, "cycles-hist", &cycles_hist,
1264 "Show cycles histogram and standard deviation "
1265 "- WARNING: use only with -c cycles."),
1266 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
1267 "dump raw trace in ASCII"),
1268 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
1269 OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
1270 "file", "kallsyms pathname"),
1271 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
1272 "load module symbols - WARNING: use only with -k and LIVE kernel"),
1273 OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
1274 "only consider symbols in these dsos"),
1275 OPT_STRING('C', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
1276 "only consider symbols in these comms"),
1277 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
1278 "only consider these symbols"),
1279 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
1280 "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
1281 " Please refer the man page for the complete list."),
1282 OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
1283 "separator for columns, no spaces will be added between "
1284 "columns '.' is reserved."),
1285 OPT_CALLBACK(0, "symfs", NULL, "directory",
1286 "Look for files with symbols relative to this directory",
1287 symbol__config_symfs),
1288 OPT_UINTEGER('o', "order", &sort_compute, "Specify compute sorting."),
1289 OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
1290 "How to display percentage of filtered entries", parse_filter_percentage),
1291 OPT_STRING(0, "time", &pdiff.time_str, "str",
1292 "Time span (time percent or absolute timestamp)"),
1293 OPT_STRING(0, "cpu", &cpu_list, "cpu", "list of cpus to profile"),
1294 OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]",
1295 "only consider symbols in these pids"),
1296 OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
1297 "only consider symbols in these tids"),
1298 OPT_BOOLEAN(0, "stream", &pdiff.stream,
1299 "Enable hot streams comparison."),
1303 static double baseline_percent(struct hist_entry *he)
1305 u64 total = hists__total_period(he->hists);
1307 return 100.0 * he->stat.period / total;
1310 static int hpp__color_baseline(struct perf_hpp_fmt *fmt,
1311 struct perf_hpp *hpp, struct hist_entry *he)
1313 struct diff_hpp_fmt *dfmt =
1314 container_of(fmt, struct diff_hpp_fmt, fmt);
1315 double percent = baseline_percent(he);
1316 char pfmt[20] = " ";
1319 scnprintf(pfmt, 20, "%%%d.2f%%%%", dfmt->header_width - 1);
1320 return percent_color_snprintf(hpp->buf, hpp->size,
1323 return scnprintf(hpp->buf, hpp->size, "%*s",
1324 dfmt->header_width, pfmt);
1327 static int hpp__entry_baseline(struct hist_entry *he, char *buf, size_t size)
1329 double percent = baseline_percent(he);
1330 const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%";
1334 ret = scnprintf(buf, size, fmt, percent);
1339 static int cycles_printf(struct hist_entry *he, struct hist_entry *pair,
1340 struct perf_hpp *hpp, int width)
1342 struct block_hist *bh = container_of(he, struct block_hist, he);
1343 struct block_hist *bh_pair = container_of(pair, struct block_hist, he);
1344 struct hist_entry *block_he;
1345 struct block_info *bi;
1347 char *start_line, *end_line;
1349 block_he = hists__get_entry(&bh_pair->block_hists, bh->block_idx);
1356 * Avoid printing the warning "addr2line_init failed for ..."
1358 symbol_conf.disable_add2line_warn = true;
1360 bi = block_he->block_info;
1362 start_line = map__srcline(he->ms.map, bi->sym->start + bi->start,
1365 end_line = map__srcline(he->ms.map, bi->sym->start + bi->end,
1368 if (start_line != SRCLINE_UNKNOWN &&
1369 end_line != SRCLINE_UNKNOWN) {
1370 scnprintf(buf, sizeof(buf), "[%s -> %s] %4ld",
1371 start_line, end_line, block_he->diff.cycles);
1373 scnprintf(buf, sizeof(buf), "[%7lx -> %7lx] %4ld",
1374 bi->start, bi->end, block_he->diff.cycles);
1377 zfree_srcline(&start_line);
1378 zfree_srcline(&end_line);
1380 return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
1383 static int __hpp__color_compare(struct perf_hpp_fmt *fmt,
1384 struct perf_hpp *hpp, struct hist_entry *he,
1385 int comparison_method)
1387 struct diff_hpp_fmt *dfmt =
1388 container_of(fmt, struct diff_hpp_fmt, fmt);
1389 struct hist_entry *pair = get_pair_fmt(he, dfmt);
1392 char pfmt[20] = " ";
1395 if (comparison_method == COMPUTE_CYCLES) {
1396 struct block_hist *bh;
1398 bh = container_of(he, struct block_hist, he);
1406 switch (comparison_method) {
1408 if (pair->diff.computed)
1409 diff = pair->diff.period_ratio_delta;
1411 diff = compute_delta(he, pair);
1413 scnprintf(pfmt, 20, "%%%+d.2f%%%%", dfmt->header_width - 1);
1414 return percent_color_snprintf(hpp->buf, hpp->size,
1419 if (pair->diff.computed)
1420 diff = pair->diff.period_ratio;
1422 diff = compute_ratio(he, pair);
1424 scnprintf(pfmt, 20, "%%%d.6f", dfmt->header_width);
1425 return value_color_snprintf(hpp->buf, hpp->size,
1427 case COMPUTE_WEIGHTED_DIFF:
1430 if (pair->diff.computed)
1431 wdiff = pair->diff.wdiff;
1433 wdiff = compute_wdiff(he, pair);
1435 scnprintf(pfmt, 20, "%%14ld", dfmt->header_width);
1436 return color_snprintf(hpp->buf, hpp->size,
1437 get_percent_color(wdiff),
1439 case COMPUTE_CYCLES:
1440 return cycles_printf(he, pair, hpp, dfmt->header_width);
1445 return scnprintf(hpp->buf, hpp->size, "%*s",
1446 dfmt->header_width, "N/A");
1448 return scnprintf(hpp->buf, hpp->size, "%*s",
1449 dfmt->header_width, pfmt);
1452 static int hpp__color_delta(struct perf_hpp_fmt *fmt,
1453 struct perf_hpp *hpp, struct hist_entry *he)
1455 return __hpp__color_compare(fmt, hpp, he, COMPUTE_DELTA);
1458 static int hpp__color_ratio(struct perf_hpp_fmt *fmt,
1459 struct perf_hpp *hpp, struct hist_entry *he)
1461 return __hpp__color_compare(fmt, hpp, he, COMPUTE_RATIO);
1464 static int hpp__color_wdiff(struct perf_hpp_fmt *fmt,
1465 struct perf_hpp *hpp, struct hist_entry *he)
1467 return __hpp__color_compare(fmt, hpp, he, COMPUTE_WEIGHTED_DIFF);
1470 static int hpp__color_cycles(struct perf_hpp_fmt *fmt,
1471 struct perf_hpp *hpp, struct hist_entry *he)
1473 return __hpp__color_compare(fmt, hpp, he, COMPUTE_CYCLES);
1476 static int all_zero(unsigned long *vals, int len)
1480 for (i = 0; i < len; i++)
1486 static int print_cycles_spark(char *bf, int size, unsigned long *svals, u64 n)
1495 if (all_zero(svals, n))
1498 printed = print_spark(bf, size, svals, n);
1499 printed += scnprintf(bf + printed, size - printed, " ");
1503 static int hpp__color_cycles_hist(struct perf_hpp_fmt *fmt,
1504 struct perf_hpp *hpp, struct hist_entry *he)
1506 struct diff_hpp_fmt *dfmt =
1507 container_of(fmt, struct diff_hpp_fmt, fmt);
1508 struct hist_entry *pair = get_pair_fmt(he, dfmt);
1509 struct block_hist *bh = container_of(he, struct block_hist, he);
1510 struct block_hist *bh_pair;
1511 struct hist_entry *block_he;
1512 char spark[32], buf[128];
1523 bh_pair = container_of(pair, struct block_hist, he);
1525 block_he = hists__get_entry(&bh_pair->block_hists, bh->block_idx);
1531 ret = print_cycles_spark(spark, sizeof(spark), block_he->diff.svals,
1532 block_he->diff.stats.n);
1534 r = rel_stddev_stats(stddev_stats(&block_he->diff.stats),
1535 avg_stats(&block_he->diff.stats));
1539 * Padding spaces if number of sparks less than NUM_SPARKS
1540 * otherwise the output is not aligned.
1542 pad = NUM_SPARKS - ((ret - 1) / 3);
1543 scnprintf(buf, sizeof(buf), "%s%5.1f%% %s", "\u00B1", r, spark);
1544 ret = scnprintf(hpp->buf, hpp->size, "%*s",
1545 dfmt->header_width, buf);
1548 ret += scnprintf(hpp->buf + ret, hpp->size - ret,
1556 return scnprintf(hpp->buf, hpp->size, "%*s",
1557 dfmt->header_width, " ");
1561 hpp__entry_unpair(struct hist_entry *he, int idx, char *buf, size_t size)
1564 case PERF_HPP_DIFF__PERIOD_BASELINE:
1565 scnprintf(buf, size, "%" PRIu64, he->stat.period);
1574 hpp__entry_pair(struct hist_entry *he, struct hist_entry *pair,
1575 int idx, char *buf, size_t size)
1582 case PERF_HPP_DIFF__DELTA:
1583 case PERF_HPP_DIFF__DELTA_ABS:
1584 if (pair->diff.computed)
1585 diff = pair->diff.period_ratio_delta;
1587 diff = compute_delta(he, pair);
1589 scnprintf(buf, size, "%+4.2F%%", diff);
1592 case PERF_HPP_DIFF__RATIO:
1593 /* No point for ratio number if we are dummy.. */
1595 scnprintf(buf, size, "N/A");
1599 if (pair->diff.computed)
1600 ratio = pair->diff.period_ratio;
1602 ratio = compute_ratio(he, pair);
1605 scnprintf(buf, size, "%14.6F", ratio);
1608 case PERF_HPP_DIFF__WEIGHTED_DIFF:
1609 /* No point for wdiff number if we are dummy.. */
1611 scnprintf(buf, size, "N/A");
1615 if (pair->diff.computed)
1616 wdiff = pair->diff.wdiff;
1618 wdiff = compute_wdiff(he, pair);
1621 scnprintf(buf, size, "%14ld", wdiff);
1624 case PERF_HPP_DIFF__FORMULA:
1625 formula_fprintf(he, pair, buf, size);
1628 case PERF_HPP_DIFF__PERIOD:
1629 scnprintf(buf, size, "%" PRIu64, pair->stat.period);
1638 __hpp__entry_global(struct hist_entry *he, struct diff_hpp_fmt *dfmt,
1639 char *buf, size_t size)
1641 struct hist_entry *pair = get_pair_fmt(he, dfmt);
1642 int idx = dfmt->idx;
1644 /* baseline is special */
1645 if (idx == PERF_HPP_DIFF__BASELINE)
1646 hpp__entry_baseline(he, buf, size);
1649 hpp__entry_pair(he, pair, idx, buf, size);
1651 hpp__entry_unpair(he, idx, buf, size);
1655 static int hpp__entry_global(struct perf_hpp_fmt *_fmt, struct perf_hpp *hpp,
1656 struct hist_entry *he)
1658 struct diff_hpp_fmt *dfmt =
1659 container_of(_fmt, struct diff_hpp_fmt, fmt);
1660 char buf[MAX_COL_WIDTH] = " ";
1662 __hpp__entry_global(he, dfmt, buf, MAX_COL_WIDTH);
1664 if (symbol_conf.field_sep)
1665 return scnprintf(hpp->buf, hpp->size, "%s", buf);
1667 return scnprintf(hpp->buf, hpp->size, "%*s",
1668 dfmt->header_width, buf);
1671 static int hpp__header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
1672 struct hists *hists __maybe_unused,
1673 int line __maybe_unused,
1674 int *span __maybe_unused)
1676 struct diff_hpp_fmt *dfmt =
1677 container_of(fmt, struct diff_hpp_fmt, fmt);
1679 BUG_ON(!dfmt->header);
1680 return scnprintf(hpp->buf, hpp->size, dfmt->header);
1683 static int hpp__width(struct perf_hpp_fmt *fmt,
1684 struct perf_hpp *hpp __maybe_unused,
1685 struct hists *hists __maybe_unused)
1687 struct diff_hpp_fmt *dfmt =
1688 container_of(fmt, struct diff_hpp_fmt, fmt);
1690 BUG_ON(dfmt->header_width <= 0);
1691 return dfmt->header_width;
1694 static void init_header(struct data__file *d, struct diff_hpp_fmt *dfmt)
1696 #define MAX_HEADER_NAME 100
1697 char buf_indent[MAX_HEADER_NAME];
1698 char buf[MAX_HEADER_NAME];
1699 const char *header = NULL;
1702 BUG_ON(dfmt->idx >= PERF_HPP_DIFF__MAX_INDEX);
1703 header = columns[dfmt->idx].name;
1704 width = columns[dfmt->idx].width;
1706 /* Only our defined HPP fmts should appear here. */
1709 if (data__files_cnt > 2)
1710 scnprintf(buf, MAX_HEADER_NAME, "%s/%d", header, d->idx);
1712 #define NAME (data__files_cnt > 2 ? buf : header)
1713 dfmt->header_width = width;
1714 width = (int) strlen(NAME);
1715 if (dfmt->header_width < width)
1716 dfmt->header_width = width;
1718 scnprintf(buf_indent, MAX_HEADER_NAME, "%*s",
1719 dfmt->header_width, NAME);
1721 dfmt->header = strdup(buf_indent);
1722 #undef MAX_HEADER_NAME
1726 static void data__hpp_register(struct data__file *d, int idx)
1728 struct diff_hpp_fmt *dfmt = &d->fmt[idx];
1729 struct perf_hpp_fmt *fmt = &dfmt->fmt;
1733 fmt->header = hpp__header;
1734 fmt->width = hpp__width;
1735 fmt->entry = hpp__entry_global;
1736 fmt->cmp = hist_entry__cmp_nop;
1737 fmt->collapse = hist_entry__cmp_nop;
1739 /* TODO more colors */
1741 case PERF_HPP_DIFF__BASELINE:
1742 fmt->color = hpp__color_baseline;
1743 fmt->sort = hist_entry__cmp_baseline;
1745 case PERF_HPP_DIFF__DELTA:
1746 fmt->color = hpp__color_delta;
1747 fmt->sort = hist_entry__cmp_delta;
1749 case PERF_HPP_DIFF__RATIO:
1750 fmt->color = hpp__color_ratio;
1751 fmt->sort = hist_entry__cmp_ratio;
1753 case PERF_HPP_DIFF__WEIGHTED_DIFF:
1754 fmt->color = hpp__color_wdiff;
1755 fmt->sort = hist_entry__cmp_wdiff;
1757 case PERF_HPP_DIFF__DELTA_ABS:
1758 fmt->color = hpp__color_delta;
1759 fmt->sort = hist_entry__cmp_delta_abs;
1761 case PERF_HPP_DIFF__CYCLES:
1762 fmt->color = hpp__color_cycles;
1763 fmt->sort = hist_entry__cmp_nop;
1765 case PERF_HPP_DIFF__CYCLES_HIST:
1766 fmt->color = hpp__color_cycles_hist;
1767 fmt->sort = hist_entry__cmp_nop;
1770 fmt->sort = hist_entry__cmp_nop;
1774 init_header(d, dfmt);
1775 perf_hpp__column_register(fmt);
1776 perf_hpp__register_sort_field(fmt);
1779 static int ui_init(void)
1781 struct data__file *d;
1782 struct perf_hpp_fmt *fmt;
1785 data__for_each_file(i, d) {
1788 * Baseline or compute related columns:
1790 * PERF_HPP_DIFF__BASELINE
1791 * PERF_HPP_DIFF__DELTA
1792 * PERF_HPP_DIFF__RATIO
1793 * PERF_HPP_DIFF__WEIGHTED_DIFF
1794 * PERF_HPP_DIFF__CYCLES
1796 data__hpp_register(d, i ? compute_2_hpp[compute] :
1797 PERF_HPP_DIFF__BASELINE);
1799 if (cycles_hist && i)
1800 data__hpp_register(d, PERF_HPP_DIFF__CYCLES_HIST);
1805 * PERF_HPP_DIFF__FORMULA
1806 * PERF_HPP_DIFF__PERIOD
1807 * PERF_HPP_DIFF__PERIOD_BASELINE
1809 if (show_formula && i)
1810 data__hpp_register(d, PERF_HPP_DIFF__FORMULA);
1813 data__hpp_register(d, i ? PERF_HPP_DIFF__PERIOD :
1814 PERF_HPP_DIFF__PERIOD_BASELINE);
1821 * Prepend an fmt to sort on columns at 'sort_compute' first.
1822 * This fmt is added only to the sort list but not to the
1823 * output fields list.
1825 * Note that this column (data) can be compared twice - one
1826 * for this 'sort_compute' fmt and another for the normal
1827 * diff_hpp_fmt. But it shouldn't a problem as most entries
1828 * will be sorted out by first try or baseline and comparing
1829 * is not a costly operation.
1831 fmt = zalloc(sizeof(*fmt));
1833 pr_err("Memory allocation failed\n");
1837 fmt->cmp = hist_entry__cmp_nop;
1838 fmt->collapse = hist_entry__cmp_nop;
1842 fmt->sort = hist_entry__cmp_delta_idx;
1845 fmt->sort = hist_entry__cmp_ratio_idx;
1847 case COMPUTE_WEIGHTED_DIFF:
1848 fmt->sort = hist_entry__cmp_wdiff_idx;
1850 case COMPUTE_DELTA_ABS:
1851 fmt->sort = hist_entry__cmp_delta_abs_idx;
1853 case COMPUTE_CYCLES:
1855 * Should set since 'fmt->sort' is called without
1856 * checking valid during sorting
1858 fmt->sort = hist_entry__cmp_nop;
1864 perf_hpp__prepend_sort_field(fmt);
1868 static int data_init(int argc, const char **argv)
1870 struct data__file *d;
1871 static const char *defaults[] = {
1875 bool use_default = true;
1878 data__files_cnt = 2;
1882 defaults[1] = argv[0];
1884 data__files_cnt = argc;
1885 use_default = false;
1887 } else if (perf_guest) {
1888 defaults[0] = "perf.data.host";
1889 defaults[1] = "perf.data.guest";
1892 if (sort_compute >= (unsigned int) data__files_cnt) {
1893 pr_err("Order option out of limit.\n");
1897 data__files = zalloc(sizeof(*data__files) * data__files_cnt);
1901 data__for_each_file(i, d) {
1902 struct perf_data *data = &d->data;
1904 data->path = use_default ? defaults[i] : argv[i];
1905 data->mode = PERF_DATA_MODE_READ;
1906 data->force = force;
1914 static int diff__config(const char *var, const char *value,
1915 void *cb __maybe_unused)
1917 if (!strcmp(var, "diff.order")) {
1919 if (perf_config_int(&ret, var, value) < 0)
1924 if (!strcmp(var, "diff.compute")) {
1925 if (!strcmp(value, "delta")) {
1926 compute = COMPUTE_DELTA;
1927 } else if (!strcmp(value, "delta-abs")) {
1928 compute = COMPUTE_DELTA_ABS;
1929 } else if (!strcmp(value, "ratio")) {
1930 compute = COMPUTE_RATIO;
1931 } else if (!strcmp(value, "wdiff")) {
1932 compute = COMPUTE_WEIGHTED_DIFF;
1934 pr_err("Invalid compute method: %s\n", value);
1942 int cmd_diff(int argc, const char **argv)
1944 int ret = hists__init();
1949 perf_tool__init(&pdiff.tool, /*ordered_events=*/true);
1950 pdiff.tool.sample = diff__process_sample_event;
1951 pdiff.tool.mmap = perf_event__process_mmap;
1952 pdiff.tool.mmap2 = perf_event__process_mmap2;
1953 pdiff.tool.comm = perf_event__process_comm;
1954 pdiff.tool.exit = perf_event__process_exit;
1955 pdiff.tool.fork = perf_event__process_fork;
1956 pdiff.tool.lost = perf_event__process_lost;
1957 pdiff.tool.namespaces = perf_event__process_namespaces;
1958 pdiff.tool.cgroup = perf_event__process_cgroup;
1959 pdiff.tool.ordering_requires_timestamps = true;
1961 perf_config(diff__config, NULL);
1963 argc = parse_options(argc, argv, options, diff_usage, 0);
1966 perf_quiet_option();
1968 if (cycles_hist && (compute != COMPUTE_CYCLES))
1969 usage_with_options(diff_usage, options);
1972 compute = COMPUTE_STREAM;
1974 symbol__annotation_init();
1976 if (symbol__init(NULL) < 0)
1979 if (data_init(argc, argv) < 0)
1982 if (check_file_brstack() < 0)
1985 if ((compute == COMPUTE_CYCLES || compute == COMPUTE_STREAM)
1986 && !pdiff.has_br_stack) {
1990 if (compute == COMPUTE_STREAM) {
1991 symbol_conf.show_branchflag_count = true;
1992 symbol_conf.disable_add2line_warn = true;
1993 callchain_param.mode = CHAIN_FLAT;
1994 callchain_param.key = CCKEY_SRCLINE;
1995 callchain_param.branch_callstack = 1;
1996 symbol_conf.use_callchain = true;
1997 callchain_register_param(&callchain_param);
1998 sort_order = "srcline,symbol,dso";
2003 sort__mode = SORT_MODE__DIFF;
2006 if (setup_sorting(NULL) < 0)
2007 usage_with_options(diff_usage, options);
2011 sort__setup_elide(NULL);
2013 return __cmd_diff();