Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 2 | /* |
| 3 | * builtin-diff.c |
| 4 | * |
| 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. |
| 7 | */ |
| 8 | #include "builtin.h" |
| 9 | |
| 10 | #include "util/debug.h" |
| 11 | #include "util/event.h" |
| 12 | #include "util/hist.h" |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 13 | #include "util/evsel.h" |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 14 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 15 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 16 | #include "util/tool.h" |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 17 | #include "util/sort.h" |
| 18 | #include "util/symbol.h" |
| 19 | #include "util/util.h" |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 20 | #include "util/data.h" |
Namhyung Kim | d49dd15 | 2017-02-10 16:36:12 +0900 | [diff] [blame] | 21 | #include "util/config.h" |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 22 | #include "util/time-utils.h" |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 23 | #include "util/annotate.h" |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 24 | |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 25 | #include <errno.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 26 | #include <inttypes.h> |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 27 | #include <stdlib.h> |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 28 | #include <math.h> |
| 29 | |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 30 | struct perf_diff { |
| 31 | struct perf_tool tool; |
| 32 | const char *time_str; |
| 33 | struct perf_time_interval *ptime_range; |
| 34 | int range_size; |
| 35 | int range_num; |
Jin Yao | 30d8155 | 2019-06-28 17:23:00 +0800 | [diff] [blame] | 36 | bool has_br_stack; |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 37 | }; |
| 38 | |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 39 | /* Diff command specific HPP columns. */ |
| 40 | enum { |
| 41 | PERF_HPP_DIFF__BASELINE, |
| 42 | PERF_HPP_DIFF__PERIOD, |
| 43 | PERF_HPP_DIFF__PERIOD_BASELINE, |
| 44 | PERF_HPP_DIFF__DELTA, |
| 45 | PERF_HPP_DIFF__RATIO, |
| 46 | PERF_HPP_DIFF__WEIGHTED_DIFF, |
| 47 | PERF_HPP_DIFF__FORMULA, |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 48 | PERF_HPP_DIFF__DELTA_ABS, |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 49 | |
| 50 | PERF_HPP_DIFF__MAX_INDEX |
| 51 | }; |
| 52 | |
| 53 | struct diff_hpp_fmt { |
| 54 | struct perf_hpp_fmt fmt; |
| 55 | int idx; |
| 56 | char *header; |
| 57 | int header_width; |
| 58 | }; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 59 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 60 | struct data__file { |
| 61 | struct perf_session *session; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 62 | struct perf_data data; |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 63 | int idx; |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 64 | struct hists *hists; |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 65 | struct diff_hpp_fmt fmt[PERF_HPP_DIFF__MAX_INDEX]; |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static struct data__file *data__files; |
| 69 | static int data__files_cnt; |
| 70 | |
| 71 | #define data__for_each_file_start(i, d, s) \ |
| 72 | for (i = s, d = &data__files[s]; \ |
| 73 | i < data__files_cnt; \ |
| 74 | i++, d = &data__files[i]) |
| 75 | |
| 76 | #define data__for_each_file(i, d) data__for_each_file_start(i, d, 0) |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 77 | #define data__for_each_file_new(i, d) data__for_each_file_start(i, d, 1) |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 78 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 79 | static bool force; |
Jiri Olsa | 61949b2 | 2012-10-05 16:44:44 +0200 | [diff] [blame] | 80 | static bool show_period; |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 81 | static bool show_formula; |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 82 | static bool show_baseline_only; |
Namhyung Kim | be57b3f | 2017-02-11 01:18:56 +0900 | [diff] [blame] | 83 | static unsigned int sort_compute = 1; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 84 | |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 85 | static s64 compute_wdiff_w1; |
| 86 | static s64 compute_wdiff_w2; |
| 87 | |
Jin Yao | daca23b | 2019-03-05 21:05:42 +0800 | [diff] [blame] | 88 | static const char *cpu_list; |
| 89 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); |
| 90 | |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 91 | static struct addr_location dummy_al; |
| 92 | |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 93 | enum { |
| 94 | COMPUTE_DELTA, |
| 95 | COMPUTE_RATIO, |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 96 | COMPUTE_WEIGHTED_DIFF, |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 97 | COMPUTE_DELTA_ABS, |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 98 | COMPUTE_CYCLES, |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 99 | COMPUTE_MAX, |
| 100 | }; |
| 101 | |
| 102 | const char *compute_names[COMPUTE_MAX] = { |
| 103 | [COMPUTE_DELTA] = "delta", |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 104 | [COMPUTE_DELTA_ABS] = "delta-abs", |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 105 | [COMPUTE_RATIO] = "ratio", |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 106 | [COMPUTE_WEIGHTED_DIFF] = "wdiff", |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 107 | [COMPUTE_CYCLES] = "cycles", |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 108 | }; |
| 109 | |
Namhyung Kim | be57b3f | 2017-02-11 01:18:56 +0900 | [diff] [blame] | 110 | static int compute = COMPUTE_DELTA_ABS; |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 111 | |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 112 | static int compute_2_hpp[COMPUTE_MAX] = { |
| 113 | [COMPUTE_DELTA] = PERF_HPP_DIFF__DELTA, |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 114 | [COMPUTE_DELTA_ABS] = PERF_HPP_DIFF__DELTA_ABS, |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 115 | [COMPUTE_RATIO] = PERF_HPP_DIFF__RATIO, |
| 116 | [COMPUTE_WEIGHTED_DIFF] = PERF_HPP_DIFF__WEIGHTED_DIFF, |
| 117 | }; |
| 118 | |
| 119 | #define MAX_COL_WIDTH 70 |
| 120 | |
| 121 | static struct header_column { |
| 122 | const char *name; |
| 123 | int width; |
| 124 | } columns[PERF_HPP_DIFF__MAX_INDEX] = { |
| 125 | [PERF_HPP_DIFF__BASELINE] = { |
| 126 | .name = "Baseline", |
| 127 | }, |
| 128 | [PERF_HPP_DIFF__PERIOD] = { |
| 129 | .name = "Period", |
| 130 | .width = 14, |
| 131 | }, |
| 132 | [PERF_HPP_DIFF__PERIOD_BASELINE] = { |
| 133 | .name = "Base period", |
| 134 | .width = 14, |
| 135 | }, |
| 136 | [PERF_HPP_DIFF__DELTA] = { |
| 137 | .name = "Delta", |
| 138 | .width = 7, |
| 139 | }, |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 140 | [PERF_HPP_DIFF__DELTA_ABS] = { |
| 141 | .name = "Delta Abs", |
| 142 | .width = 7, |
| 143 | }, |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 144 | [PERF_HPP_DIFF__RATIO] = { |
| 145 | .name = "Ratio", |
| 146 | .width = 14, |
| 147 | }, |
| 148 | [PERF_HPP_DIFF__WEIGHTED_DIFF] = { |
| 149 | .name = "Weighted diff", |
| 150 | .width = 14, |
| 151 | }, |
| 152 | [PERF_HPP_DIFF__FORMULA] = { |
| 153 | .name = "Formula", |
| 154 | .width = MAX_COL_WIDTH, |
| 155 | } |
| 156 | }; |
| 157 | |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 158 | static int setup_compute_opt_wdiff(char *opt) |
| 159 | { |
| 160 | char *w1_str = opt; |
| 161 | char *w2_str; |
| 162 | |
| 163 | int ret = -EINVAL; |
| 164 | |
| 165 | if (!opt) |
| 166 | goto out; |
| 167 | |
| 168 | w2_str = strchr(opt, ','); |
| 169 | if (!w2_str) |
| 170 | goto out; |
| 171 | |
| 172 | *w2_str++ = 0x0; |
| 173 | if (!*w2_str) |
| 174 | goto out; |
| 175 | |
| 176 | compute_wdiff_w1 = strtol(w1_str, NULL, 10); |
| 177 | compute_wdiff_w2 = strtol(w2_str, NULL, 10); |
| 178 | |
| 179 | if (!compute_wdiff_w1 || !compute_wdiff_w2) |
| 180 | goto out; |
| 181 | |
| 182 | pr_debug("compute wdiff w1(%" PRId64 ") w2(%" PRId64 ")\n", |
| 183 | compute_wdiff_w1, compute_wdiff_w2); |
| 184 | |
| 185 | ret = 0; |
| 186 | |
| 187 | out: |
| 188 | if (ret) |
| 189 | pr_err("Failed: wrong weight data, use 'wdiff:w1,w2'\n"); |
| 190 | |
| 191 | return ret; |
| 192 | } |
| 193 | |
| 194 | static int setup_compute_opt(char *opt) |
| 195 | { |
| 196 | if (compute == COMPUTE_WEIGHTED_DIFF) |
| 197 | return setup_compute_opt_wdiff(opt); |
| 198 | |
| 199 | if (opt) { |
| 200 | pr_err("Failed: extra option specified '%s'", opt); |
| 201 | return -EINVAL; |
| 202 | } |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 207 | static int setup_compute(const struct option *opt, const char *str, |
| 208 | int unset __maybe_unused) |
| 209 | { |
| 210 | int *cp = (int *) opt->value; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 211 | char *cstr = (char *) str; |
| 212 | char buf[50]; |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 213 | unsigned i; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 214 | char *option; |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 215 | |
| 216 | if (!str) { |
| 217 | *cp = COMPUTE_DELTA; |
| 218 | return 0; |
| 219 | } |
| 220 | |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 221 | option = strchr(str, ':'); |
| 222 | if (option) { |
| 223 | unsigned len = option++ - str; |
| 224 | |
| 225 | /* |
| 226 | * The str data are not writeable, so we need |
| 227 | * to use another buffer. |
| 228 | */ |
| 229 | |
| 230 | /* No option value is longer. */ |
| 231 | if (len >= sizeof(buf)) |
| 232 | return -EINVAL; |
| 233 | |
| 234 | strncpy(buf, str, len); |
| 235 | buf[len] = 0x0; |
| 236 | cstr = buf; |
| 237 | } |
| 238 | |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 239 | for (i = 0; i < COMPUTE_MAX; i++) |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 240 | if (!strcmp(cstr, compute_names[i])) { |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 241 | *cp = i; |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 242 | if (i == COMPUTE_CYCLES) |
| 243 | break; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 244 | return setup_compute_opt(option); |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | pr_err("Failed: '%s' is not computation method " |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 248 | "(use 'delta','ratio' or 'wdiff')\n", str); |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 249 | return -EINVAL; |
| 250 | } |
| 251 | |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 252 | static double period_percent(struct hist_entry *he, u64 period) |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 253 | { |
Namhyung Kim | 8810f6c | 2014-02-07 12:06:07 +0900 | [diff] [blame] | 254 | u64 total = hists__total_period(he->hists); |
| 255 | |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 256 | return (period * 100.0) / total; |
| 257 | } |
| 258 | |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 259 | static double compute_delta(struct hist_entry *he, struct hist_entry *pair) |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 260 | { |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 261 | double old_percent = period_percent(he, he->stat.period); |
| 262 | double new_percent = period_percent(pair, pair->stat.period); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 263 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame] | 264 | pair->diff.period_ratio_delta = new_percent - old_percent; |
| 265 | pair->diff.computed = true; |
| 266 | return pair->diff.period_ratio_delta; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 269 | static double compute_ratio(struct hist_entry *he, struct hist_entry *pair) |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 270 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame] | 271 | double old_period = he->stat.period ?: 1; |
| 272 | double new_period = pair->stat.period; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 273 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame] | 274 | pair->diff.computed = true; |
| 275 | pair->diff.period_ratio = new_period / old_period; |
| 276 | return pair->diff.period_ratio; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 277 | } |
| 278 | |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 279 | static s64 compute_wdiff(struct hist_entry *he, struct hist_entry *pair) |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 280 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame] | 281 | u64 old_period = he->stat.period; |
| 282 | u64 new_period = pair->stat.period; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 283 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame] | 284 | pair->diff.computed = true; |
| 285 | pair->diff.wdiff = new_period * compute_wdiff_w2 - |
| 286 | old_period * compute_wdiff_w1; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 287 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame] | 288 | return pair->diff.wdiff; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 291 | static int formula_delta(struct hist_entry *he, struct hist_entry *pair, |
| 292 | char *buf, size_t size) |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 293 | { |
Namhyung Kim | 8810f6c | 2014-02-07 12:06:07 +0900 | [diff] [blame] | 294 | u64 he_total = he->hists->stats.total_period; |
| 295 | u64 pair_total = pair->hists->stats.total_period; |
| 296 | |
| 297 | if (symbol_conf.filter_relative) { |
| 298 | he_total = he->hists->stats.total_non_filtered_period; |
| 299 | pair_total = pair->hists->stats.total_non_filtered_period; |
| 300 | } |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 301 | return scnprintf(buf, size, |
| 302 | "(%" PRIu64 " * 100 / %" PRIu64 ") - " |
| 303 | "(%" PRIu64 " * 100 / %" PRIu64 ")", |
Namhyung Kim | 8810f6c | 2014-02-07 12:06:07 +0900 | [diff] [blame] | 304 | pair->stat.period, pair_total, |
| 305 | he->stat.period, he_total); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 306 | } |
| 307 | |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 308 | static int formula_ratio(struct hist_entry *he, struct hist_entry *pair, |
| 309 | char *buf, size_t size) |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 310 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame] | 311 | double old_period = he->stat.period; |
| 312 | double new_period = pair->stat.period; |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 313 | |
| 314 | return scnprintf(buf, size, "%.0F / %.0F", new_period, old_period); |
| 315 | } |
| 316 | |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 317 | static int formula_wdiff(struct hist_entry *he, struct hist_entry *pair, |
| 318 | char *buf, size_t size) |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 319 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame] | 320 | u64 old_period = he->stat.period; |
| 321 | u64 new_period = pair->stat.period; |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 322 | |
| 323 | return scnprintf(buf, size, |
| 324 | "(%" PRIu64 " * " "%" PRId64 ") - (%" PRIu64 " * " "%" PRId64 ")", |
| 325 | new_period, compute_wdiff_w2, old_period, compute_wdiff_w1); |
| 326 | } |
| 327 | |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 328 | static int formula_fprintf(struct hist_entry *he, struct hist_entry *pair, |
| 329 | char *buf, size_t size) |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 330 | { |
| 331 | switch (compute) { |
| 332 | case COMPUTE_DELTA: |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 333 | case COMPUTE_DELTA_ABS: |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 334 | return formula_delta(he, pair, buf, size); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 335 | case COMPUTE_RATIO: |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 336 | return formula_ratio(he, pair, buf, size); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 337 | case COMPUTE_WEIGHTED_DIFF: |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 338 | return formula_wdiff(he, pair, buf, size); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 339 | default: |
| 340 | BUG_ON(1); |
| 341 | } |
| 342 | |
| 343 | return -1; |
| 344 | } |
| 345 | |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 346 | static void *block_hist_zalloc(size_t size) |
| 347 | { |
| 348 | struct block_hist *bh; |
| 349 | |
| 350 | bh = zalloc(size + sizeof(*bh)); |
| 351 | if (!bh) |
| 352 | return NULL; |
| 353 | |
| 354 | return &bh->he; |
| 355 | } |
| 356 | |
| 357 | static void block_hist_free(void *he) |
| 358 | { |
| 359 | struct block_hist *bh; |
| 360 | |
| 361 | bh = container_of(he, struct block_hist, he); |
| 362 | hists__delete_entries(&bh->block_hists); |
| 363 | free(bh); |
| 364 | } |
| 365 | |
| 366 | struct hist_entry_ops block_hist_ops = { |
| 367 | .new = block_hist_zalloc, |
| 368 | .free = block_hist_free, |
| 369 | }; |
| 370 | |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 371 | static int diff__process_sample_event(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 372 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 373 | struct perf_sample *sample, |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 374 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 375 | struct machine *machine) |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 376 | { |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 377 | struct perf_diff *pdiff = container_of(tool, struct perf_diff, tool); |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 378 | struct addr_location al; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 379 | struct hists *hists = evsel__hists(evsel); |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 380 | int ret = -1; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 381 | |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 382 | if (perf_time__ranges_skip_sample(pdiff->ptime_range, pdiff->range_num, |
| 383 | sample->time)) { |
| 384 | return 0; |
| 385 | } |
| 386 | |
Arnaldo Carvalho de Melo | bb3eb56 | 2016-03-22 18:39:09 -0300 | [diff] [blame] | 387 | if (machine__resolve(machine, &al, sample) < 0) { |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 388 | pr_warning("problem processing %d event, skipping it.\n", |
| 389 | event->header.type); |
| 390 | return -1; |
| 391 | } |
| 392 | |
Jin Yao | daca23b | 2019-03-05 21:05:42 +0800 | [diff] [blame] | 393 | if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) { |
| 394 | ret = 0; |
| 395 | goto out_put; |
| 396 | } |
| 397 | |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 398 | if (compute != COMPUTE_CYCLES) { |
| 399 | if (!hists__add_entry(hists, &al, NULL, NULL, NULL, sample, |
| 400 | true)) { |
| 401 | pr_warning("problem incrementing symbol period, " |
| 402 | "skipping event\n"); |
| 403 | goto out_put; |
| 404 | } |
| 405 | } else { |
| 406 | if (!hists__add_entry_ops(hists, &block_hist_ops, &al, NULL, |
| 407 | NULL, NULL, sample, true)) { |
| 408 | pr_warning("problem incrementing symbol period, " |
| 409 | "skipping event\n"); |
| 410 | goto out_put; |
| 411 | } |
| 412 | |
| 413 | hist__account_cycles(sample->branch_stack, &al, sample, false); |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 414 | } |
| 415 | |
Namhyung Kim | 820bc81 | 2014-04-22 11:44:21 +0900 | [diff] [blame] | 416 | /* |
| 417 | * The total_period is updated here before going to the output |
| 418 | * tree since normally only the baseline hists will call |
| 419 | * hists__output_resort() and precompute needs the total |
| 420 | * period in order to sort entries by percentage delta. |
| 421 | */ |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 422 | hists->stats.total_period += sample->period; |
Namhyung Kim | 820bc81 | 2014-04-22 11:44:21 +0900 | [diff] [blame] | 423 | if (!al.filtered) |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 424 | hists->stats.total_non_filtered_period += sample->period; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 425 | ret = 0; |
| 426 | out_put: |
| 427 | addr_location__put(&al); |
| 428 | return ret; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 429 | } |
| 430 | |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 431 | static struct perf_diff pdiff = { |
| 432 | .tool = { |
| 433 | .sample = diff__process_sample_event, |
| 434 | .mmap = perf_event__process_mmap, |
| 435 | .mmap2 = perf_event__process_mmap2, |
| 436 | .comm = perf_event__process_comm, |
| 437 | .exit = perf_event__process_exit, |
| 438 | .fork = perf_event__process_fork, |
| 439 | .lost = perf_event__process_lost, |
| 440 | .namespaces = perf_event__process_namespaces, |
| 441 | .ordered_events = true, |
| 442 | .ordering_requires_timestamps = true, |
| 443 | }, |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 444 | }; |
| 445 | |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 446 | static struct perf_evsel *evsel_match(struct perf_evsel *evsel, |
| 447 | struct perf_evlist *evlist) |
| 448 | { |
| 449 | struct perf_evsel *e; |
| 450 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 451 | evlist__for_each_entry(evlist, e) { |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 452 | if (perf_evsel__match2(evsel, e)) |
| 453 | return e; |
Arnaldo Carvalho de Melo | 0050f7a | 2014-01-10 10:37:27 -0300 | [diff] [blame] | 454 | } |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 455 | |
| 456 | return NULL; |
| 457 | } |
| 458 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 459 | static void perf_evlist__collapse_resort(struct perf_evlist *evlist) |
Jiri Olsa | dd46434 | 2012-10-04 21:49:36 +0900 | [diff] [blame] | 460 | { |
| 461 | struct perf_evsel *evsel; |
| 462 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 463 | evlist__for_each_entry(evlist, evsel) { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 464 | struct hists *hists = evsel__hists(evsel); |
Jiri Olsa | dd46434 | 2012-10-04 21:49:36 +0900 | [diff] [blame] | 465 | |
Namhyung Kim | c1fb565 | 2013-10-11 14:15:38 +0900 | [diff] [blame] | 466 | hists__collapse_resort(hists, NULL); |
Jiri Olsa | dd46434 | 2012-10-04 21:49:36 +0900 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
Namhyung Kim | ff21cef | 2015-01-08 09:45:45 +0900 | [diff] [blame] | 470 | static struct data__file *fmt_to_data_file(struct perf_hpp_fmt *fmt) |
| 471 | { |
| 472 | struct diff_hpp_fmt *dfmt = container_of(fmt, struct diff_hpp_fmt, fmt); |
| 473 | void *ptr = dfmt - dfmt->idx; |
| 474 | struct data__file *d = container_of(ptr, struct data__file, fmt); |
| 475 | |
| 476 | return d; |
| 477 | } |
| 478 | |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 479 | static struct hist_entry* |
| 480 | get_pair_data(struct hist_entry *he, struct data__file *d) |
| 481 | { |
| 482 | if (hist_entry__has_pairs(he)) { |
| 483 | struct hist_entry *pair; |
| 484 | |
| 485 | list_for_each_entry(pair, &he->pairs.head, pairs.node) |
| 486 | if (pair->hists == d->hists) |
| 487 | return pair; |
| 488 | } |
| 489 | |
| 490 | return NULL; |
| 491 | } |
| 492 | |
| 493 | static struct hist_entry* |
| 494 | get_pair_fmt(struct hist_entry *he, struct diff_hpp_fmt *dfmt) |
| 495 | { |
Namhyung Kim | ff21cef | 2015-01-08 09:45:45 +0900 | [diff] [blame] | 496 | struct data__file *d = fmt_to_data_file(&dfmt->fmt); |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 497 | |
| 498 | return get_pair_data(he, d); |
| 499 | } |
| 500 | |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 501 | static void hists__baseline_only(struct hists *hists) |
| 502 | { |
Davidlohr Bueso | 2eb3d68 | 2018-12-06 11:18:18 -0800 | [diff] [blame] | 503 | struct rb_root_cached *root; |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 504 | struct rb_node *next; |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 505 | |
Jiri Olsa | 5222503 | 2016-05-03 13:54:42 +0200 | [diff] [blame] | 506 | if (hists__has(hists, need_collapse)) |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 507 | root = &hists->entries_collapsed; |
| 508 | else |
| 509 | root = hists->entries_in; |
| 510 | |
Davidlohr Bueso | 2eb3d68 | 2018-12-06 11:18:18 -0800 | [diff] [blame] | 511 | next = rb_first_cached(root); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 512 | while (next != NULL) { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 513 | struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node_in); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 514 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 515 | next = rb_next(&he->rb_node_in); |
Arnaldo Carvalho de Melo | b821c73 | 2012-10-25 14:42:45 -0200 | [diff] [blame] | 516 | if (!hist_entry__next_pair(he)) { |
Davidlohr Bueso | 2eb3d68 | 2018-12-06 11:18:18 -0800 | [diff] [blame] | 517 | rb_erase_cached(&he->rb_node_in, root); |
Arnaldo Carvalho de Melo | 6733d1b | 2014-12-19 12:31:40 -0300 | [diff] [blame] | 518 | hist_entry__delete(he); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | } |
| 522 | |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 523 | static int64_t block_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 524 | struct hist_entry *left, struct hist_entry *right) |
| 525 | { |
| 526 | struct block_info *bi_l = left->block_info; |
| 527 | struct block_info *bi_r = right->block_info; |
| 528 | int cmp; |
| 529 | |
| 530 | if (!bi_l->sym || !bi_r->sym) { |
| 531 | if (!bi_l->sym && !bi_r->sym) |
| 532 | return 0; |
| 533 | else if (!bi_l->sym) |
| 534 | return -1; |
| 535 | else |
| 536 | return 1; |
| 537 | } |
| 538 | |
| 539 | if (bi_l->sym == bi_r->sym) { |
| 540 | if (bi_l->start == bi_r->start) { |
| 541 | if (bi_l->end == bi_r->end) |
| 542 | return 0; |
| 543 | else |
| 544 | return (int64_t)(bi_r->end - bi_l->end); |
| 545 | } else |
| 546 | return (int64_t)(bi_r->start - bi_l->start); |
| 547 | } else { |
| 548 | cmp = strcmp(bi_l->sym->name, bi_r->sym->name); |
| 549 | return cmp; |
| 550 | } |
| 551 | |
| 552 | if (bi_l->sym->start != bi_r->sym->start) |
| 553 | return (int64_t)(bi_r->sym->start - bi_l->sym->start); |
| 554 | |
| 555 | return (int64_t)(bi_r->sym->end - bi_l->sym->end); |
| 556 | } |
| 557 | |
| 558 | static int64_t block_cycles_diff_cmp(struct hist_entry *left, |
| 559 | struct hist_entry *right) |
| 560 | { |
| 561 | bool pairs_left = hist_entry__has_pairs(left); |
| 562 | bool pairs_right = hist_entry__has_pairs(right); |
| 563 | s64 l, r; |
| 564 | |
| 565 | if (!pairs_left && !pairs_right) |
| 566 | return 0; |
| 567 | |
| 568 | l = labs(left->diff.cycles); |
| 569 | r = labs(right->diff.cycles); |
| 570 | return r - l; |
| 571 | } |
| 572 | |
| 573 | static int64_t block_sort(struct perf_hpp_fmt *fmt __maybe_unused, |
| 574 | struct hist_entry *left, struct hist_entry *right) |
| 575 | { |
| 576 | return block_cycles_diff_cmp(right, left); |
| 577 | } |
| 578 | |
| 579 | static void init_block_hist(struct block_hist *bh) |
| 580 | { |
| 581 | __hists__init(&bh->block_hists, &bh->block_list); |
| 582 | perf_hpp_list__init(&bh->block_list); |
| 583 | |
| 584 | INIT_LIST_HEAD(&bh->block_fmt.list); |
| 585 | INIT_LIST_HEAD(&bh->block_fmt.sort_list); |
| 586 | bh->block_fmt.cmp = block_cmp; |
| 587 | bh->block_fmt.sort = block_sort; |
| 588 | perf_hpp_list__register_sort_field(&bh->block_list, |
| 589 | &bh->block_fmt); |
| 590 | bh->valid = true; |
| 591 | } |
| 592 | |
| 593 | static void init_block_info(struct block_info *bi, struct symbol *sym, |
| 594 | struct cyc_hist *ch, int offset) |
| 595 | { |
| 596 | bi->sym = sym; |
| 597 | bi->start = ch->start; |
| 598 | bi->end = offset; |
| 599 | bi->cycles = ch->cycles; |
| 600 | bi->cycles_aggr = ch->cycles_aggr; |
| 601 | bi->num = ch->num; |
| 602 | bi->num_aggr = ch->num_aggr; |
| 603 | } |
| 604 | |
| 605 | static int process_block_per_sym(struct hist_entry *he) |
| 606 | { |
| 607 | struct annotation *notes; |
| 608 | struct cyc_hist *ch; |
| 609 | struct block_hist *bh; |
| 610 | |
| 611 | if (!he->ms.map || !he->ms.sym) |
| 612 | return 0; |
| 613 | |
| 614 | notes = symbol__annotation(he->ms.sym); |
| 615 | if (!notes || !notes->src || !notes->src->cycles_hist) |
| 616 | return 0; |
| 617 | |
| 618 | bh = container_of(he, struct block_hist, he); |
| 619 | init_block_hist(bh); |
| 620 | |
| 621 | ch = notes->src->cycles_hist; |
| 622 | for (unsigned int i = 0; i < symbol__size(he->ms.sym); i++) { |
| 623 | if (ch[i].num_aggr) { |
| 624 | struct block_info *bi; |
| 625 | struct hist_entry *he_block; |
| 626 | |
| 627 | bi = block_info__new(); |
| 628 | if (!bi) |
| 629 | return -1; |
| 630 | |
| 631 | init_block_info(bi, he->ms.sym, &ch[i], i); |
| 632 | he_block = hists__add_entry_block(&bh->block_hists, |
| 633 | &dummy_al, bi); |
| 634 | if (!he_block) { |
| 635 | block_info__put(bi); |
| 636 | return -1; |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | return 0; |
| 642 | } |
| 643 | |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 644 | static void hists__precompute(struct hists *hists) |
| 645 | { |
Davidlohr Bueso | 2eb3d68 | 2018-12-06 11:18:18 -0800 | [diff] [blame] | 646 | struct rb_root_cached *root; |
Jiri Olsa | 367c53c | 2012-12-13 14:08:59 +0100 | [diff] [blame] | 647 | struct rb_node *next; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 648 | |
Jiri Olsa | 5222503 | 2016-05-03 13:54:42 +0200 | [diff] [blame] | 649 | if (hists__has(hists, need_collapse)) |
Jiri Olsa | 367c53c | 2012-12-13 14:08:59 +0100 | [diff] [blame] | 650 | root = &hists->entries_collapsed; |
| 651 | else |
| 652 | root = hists->entries_in; |
| 653 | |
Davidlohr Bueso | 2eb3d68 | 2018-12-06 11:18:18 -0800 | [diff] [blame] | 654 | next = rb_first_cached(root); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 655 | while (next != NULL) { |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 656 | struct hist_entry *he, *pair; |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 657 | struct data__file *d; |
| 658 | int i; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 659 | |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 660 | he = rb_entry(next, struct hist_entry, rb_node_in); |
Jiri Olsa | 367c53c | 2012-12-13 14:08:59 +0100 | [diff] [blame] | 661 | next = rb_next(&he->rb_node_in); |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 662 | |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 663 | if (compute == COMPUTE_CYCLES) |
| 664 | process_block_per_sym(he); |
| 665 | |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 666 | data__for_each_file_new(i, d) { |
| 667 | pair = get_pair_data(he, d); |
| 668 | if (!pair) |
| 669 | continue; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 670 | |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 671 | switch (compute) { |
| 672 | case COMPUTE_DELTA: |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 673 | case COMPUTE_DELTA_ABS: |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 674 | compute_delta(he, pair); |
| 675 | break; |
| 676 | case COMPUTE_RATIO: |
| 677 | compute_ratio(he, pair); |
| 678 | break; |
| 679 | case COMPUTE_WEIGHTED_DIFF: |
| 680 | compute_wdiff(he, pair); |
| 681 | break; |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 682 | case COMPUTE_CYCLES: |
| 683 | process_block_per_sym(pair); |
| 684 | break; |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 685 | default: |
| 686 | BUG_ON(1); |
| 687 | } |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | static int64_t cmp_doubles(double l, double r) |
| 693 | { |
| 694 | if (l > r) |
| 695 | return -1; |
| 696 | else if (l < r) |
| 697 | return 1; |
| 698 | else |
| 699 | return 0; |
| 700 | } |
| 701 | |
| 702 | static int64_t |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 703 | __hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right, |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 704 | int c) |
| 705 | { |
| 706 | switch (c) { |
| 707 | case COMPUTE_DELTA: |
| 708 | { |
| 709 | double l = left->diff.period_ratio_delta; |
| 710 | double r = right->diff.period_ratio_delta; |
| 711 | |
| 712 | return cmp_doubles(l, r); |
| 713 | } |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 714 | case COMPUTE_DELTA_ABS: |
| 715 | { |
| 716 | double l = fabs(left->diff.period_ratio_delta); |
| 717 | double r = fabs(right->diff.period_ratio_delta); |
| 718 | |
| 719 | return cmp_doubles(l, r); |
| 720 | } |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 721 | case COMPUTE_RATIO: |
| 722 | { |
| 723 | double l = left->diff.period_ratio; |
| 724 | double r = right->diff.period_ratio; |
| 725 | |
| 726 | return cmp_doubles(l, r); |
| 727 | } |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 728 | case COMPUTE_WEIGHTED_DIFF: |
| 729 | { |
| 730 | s64 l = left->diff.wdiff; |
| 731 | s64 r = right->diff.wdiff; |
| 732 | |
| 733 | return r - l; |
| 734 | } |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 735 | default: |
| 736 | BUG_ON(1); |
| 737 | } |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 742 | static int64_t |
| 743 | hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right, |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 744 | int c, int sort_idx) |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 745 | { |
| 746 | bool pairs_left = hist_entry__has_pairs(left); |
| 747 | bool pairs_right = hist_entry__has_pairs(right); |
| 748 | struct hist_entry *p_right, *p_left; |
| 749 | |
| 750 | if (!pairs_left && !pairs_right) |
| 751 | return 0; |
| 752 | |
| 753 | if (!pairs_left || !pairs_right) |
| 754 | return pairs_left ? -1 : 1; |
| 755 | |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 756 | p_left = get_pair_data(left, &data__files[sort_idx]); |
| 757 | p_right = get_pair_data(right, &data__files[sort_idx]); |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 758 | |
| 759 | if (!p_left && !p_right) |
| 760 | return 0; |
| 761 | |
| 762 | if (!p_left || !p_right) |
| 763 | return p_left ? -1 : 1; |
| 764 | |
| 765 | /* |
| 766 | * We have 2 entries of same kind, let's |
| 767 | * make the data comparison. |
| 768 | */ |
| 769 | return __hist_entry__cmp_compute(p_left, p_right, c); |
| 770 | } |
| 771 | |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 772 | static int64_t |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 773 | hist_entry__cmp_compute_idx(struct hist_entry *left, struct hist_entry *right, |
| 774 | int c, int sort_idx) |
| 775 | { |
| 776 | struct hist_entry *p_right, *p_left; |
| 777 | |
| 778 | p_left = get_pair_data(left, &data__files[sort_idx]); |
| 779 | p_right = get_pair_data(right, &data__files[sort_idx]); |
| 780 | |
| 781 | if (!p_left && !p_right) |
| 782 | return 0; |
| 783 | |
| 784 | if (!p_left || !p_right) |
| 785 | return p_left ? -1 : 1; |
| 786 | |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 787 | if (c != COMPUTE_DELTA && c != COMPUTE_DELTA_ABS) { |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 788 | /* |
| 789 | * The delta can be computed without the baseline, but |
| 790 | * others are not. Put those entries which have no |
| 791 | * values below. |
| 792 | */ |
| 793 | if (left->dummy && right->dummy) |
| 794 | return 0; |
| 795 | |
| 796 | if (left->dummy || right->dummy) |
| 797 | return left->dummy ? 1 : -1; |
| 798 | } |
| 799 | |
| 800 | return __hist_entry__cmp_compute(p_left, p_right, c); |
| 801 | } |
| 802 | |
| 803 | static int64_t |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 804 | hist_entry__cmp_nop(struct perf_hpp_fmt *fmt __maybe_unused, |
| 805 | struct hist_entry *left __maybe_unused, |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 806 | struct hist_entry *right __maybe_unused) |
| 807 | { |
| 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | static int64_t |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 812 | hist_entry__cmp_baseline(struct perf_hpp_fmt *fmt __maybe_unused, |
| 813 | struct hist_entry *left, struct hist_entry *right) |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 814 | { |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 815 | if (left->stat.period == right->stat.period) |
| 816 | return 0; |
| 817 | return left->stat.period > right->stat.period ? 1 : -1; |
| 818 | } |
| 819 | |
| 820 | static int64_t |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 821 | hist_entry__cmp_delta(struct perf_hpp_fmt *fmt, |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 822 | struct hist_entry *left, struct hist_entry *right) |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 823 | { |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 824 | struct data__file *d = fmt_to_data_file(fmt); |
| 825 | |
| 826 | return hist_entry__cmp_compute(right, left, COMPUTE_DELTA, d->idx); |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | static int64_t |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 830 | hist_entry__cmp_delta_abs(struct perf_hpp_fmt *fmt, |
| 831 | struct hist_entry *left, struct hist_entry *right) |
| 832 | { |
| 833 | struct data__file *d = fmt_to_data_file(fmt); |
| 834 | |
| 835 | return hist_entry__cmp_compute(right, left, COMPUTE_DELTA_ABS, d->idx); |
| 836 | } |
| 837 | |
| 838 | static int64_t |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 839 | hist_entry__cmp_ratio(struct perf_hpp_fmt *fmt, |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 840 | struct hist_entry *left, struct hist_entry *right) |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 841 | { |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 842 | struct data__file *d = fmt_to_data_file(fmt); |
| 843 | |
| 844 | return hist_entry__cmp_compute(right, left, COMPUTE_RATIO, d->idx); |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | static int64_t |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 848 | hist_entry__cmp_wdiff(struct perf_hpp_fmt *fmt, |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 849 | struct hist_entry *left, struct hist_entry *right) |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 850 | { |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 851 | struct data__file *d = fmt_to_data_file(fmt); |
| 852 | |
| 853 | return hist_entry__cmp_compute(right, left, COMPUTE_WEIGHTED_DIFF, d->idx); |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 854 | } |
| 855 | |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 856 | static int64_t |
| 857 | hist_entry__cmp_delta_idx(struct perf_hpp_fmt *fmt __maybe_unused, |
| 858 | struct hist_entry *left, struct hist_entry *right) |
| 859 | { |
| 860 | return hist_entry__cmp_compute_idx(right, left, COMPUTE_DELTA, |
| 861 | sort_compute); |
| 862 | } |
| 863 | |
| 864 | static int64_t |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 865 | hist_entry__cmp_delta_abs_idx(struct perf_hpp_fmt *fmt __maybe_unused, |
| 866 | struct hist_entry *left, struct hist_entry *right) |
| 867 | { |
| 868 | return hist_entry__cmp_compute_idx(right, left, COMPUTE_DELTA_ABS, |
| 869 | sort_compute); |
| 870 | } |
| 871 | |
| 872 | static int64_t |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 873 | hist_entry__cmp_ratio_idx(struct perf_hpp_fmt *fmt __maybe_unused, |
| 874 | struct hist_entry *left, struct hist_entry *right) |
| 875 | { |
| 876 | return hist_entry__cmp_compute_idx(right, left, COMPUTE_RATIO, |
| 877 | sort_compute); |
| 878 | } |
| 879 | |
| 880 | static int64_t |
| 881 | hist_entry__cmp_wdiff_idx(struct perf_hpp_fmt *fmt __maybe_unused, |
| 882 | struct hist_entry *left, struct hist_entry *right) |
| 883 | { |
| 884 | return hist_entry__cmp_compute_idx(right, left, COMPUTE_WEIGHTED_DIFF, |
| 885 | sort_compute); |
| 886 | } |
| 887 | |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 888 | static void hists__process(struct hists *hists) |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 889 | { |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 890 | if (show_baseline_only) |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 891 | hists__baseline_only(hists); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 892 | |
Namhyung Kim | 56495a8 | 2015-01-08 09:45:47 +0900 | [diff] [blame] | 893 | hists__precompute(hists); |
Namhyung Kim | 38259a1 | 2014-12-27 14:06:30 +0900 | [diff] [blame] | 894 | hists__output_resort(hists, NULL); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 895 | |
Namhyung Kim | 63b42fc | 2017-02-17 17:17:40 +0900 | [diff] [blame] | 896 | hists__fprintf(hists, !quiet, 0, 0, 0, stdout, |
Arnaldo Carvalho de Melo | e9de7e2 | 2018-06-20 15:58:20 -0300 | [diff] [blame] | 897 | !symbol_conf.use_callchain); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 898 | } |
| 899 | |
Jiri Olsa | 1d81c7f | 2012-12-01 21:56:03 +0100 | [diff] [blame] | 900 | static void data__fprintf(void) |
| 901 | { |
| 902 | struct data__file *d; |
| 903 | int i; |
| 904 | |
| 905 | fprintf(stdout, "# Data files:\n"); |
| 906 | |
| 907 | data__for_each_file(i, d) |
| 908 | fprintf(stdout, "# [%d] %s %s\n", |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 909 | d->idx, d->data.path, |
Jiri Olsa | 1d81c7f | 2012-12-01 21:56:03 +0100 | [diff] [blame] | 910 | !d->idx ? "(Baseline)" : ""); |
| 911 | |
| 912 | fprintf(stdout, "#\n"); |
| 913 | } |
| 914 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 915 | static void data_process(void) |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 916 | { |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 917 | struct perf_evlist *evlist_base = data__files[0].session->evlist; |
| 918 | struct perf_evsel *evsel_base; |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 919 | bool first = true; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 920 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 921 | evlist__for_each_entry(evlist_base, evsel_base) { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 922 | struct hists *hists_base = evsel__hists(evsel_base); |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 923 | struct data__file *d; |
| 924 | int i; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 925 | |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 926 | data__for_each_file_new(i, d) { |
| 927 | struct perf_evlist *evlist = d->session->evlist; |
| 928 | struct perf_evsel *evsel; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 929 | struct hists *hists; |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 930 | |
| 931 | evsel = evsel_match(evsel_base, evlist); |
| 932 | if (!evsel) |
| 933 | continue; |
| 934 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 935 | hists = evsel__hists(evsel); |
| 936 | d->hists = hists; |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 937 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 938 | hists__match(hists_base, hists); |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 939 | |
| 940 | if (!show_baseline_only) |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 941 | hists__link(hists_base, hists); |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 942 | } |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 943 | |
Namhyung Kim | 63b42fc | 2017-02-17 17:17:40 +0900 | [diff] [blame] | 944 | if (!quiet) { |
| 945 | fprintf(stdout, "%s# Event '%s'\n#\n", first ? "" : "\n", |
| 946 | perf_evsel__name(evsel_base)); |
| 947 | } |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 948 | |
| 949 | first = false; |
| 950 | |
Namhyung Kim | 63b42fc | 2017-02-17 17:17:40 +0900 | [diff] [blame] | 951 | if (verbose > 0 || ((data__files_cnt > 2) && !quiet)) |
Jiri Olsa | 1d81c7f | 2012-12-01 21:56:03 +0100 | [diff] [blame] | 952 | data__fprintf(); |
| 953 | |
Kan Liang | f9db0d0 | 2015-08-11 06:30:48 -0400 | [diff] [blame] | 954 | /* Don't sort callchain for perf diff */ |
| 955 | perf_evsel__reset_sample_bit(evsel_base, CALLCHAIN); |
| 956 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 957 | hists__process(hists_base); |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 961 | static void data__free(struct data__file *d) |
| 962 | { |
| 963 | int col; |
| 964 | |
| 965 | for (col = 0; col < PERF_HPP_DIFF__MAX_INDEX; col++) { |
| 966 | struct diff_hpp_fmt *fmt = &d->fmt[col]; |
| 967 | |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 968 | zfree(&fmt->header); |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 972 | static int abstime_str_dup(char **pstr) |
| 973 | { |
| 974 | char *str = NULL; |
| 975 | |
| 976 | if (pdiff.time_str && strchr(pdiff.time_str, ':')) { |
| 977 | str = strdup(pdiff.time_str); |
| 978 | if (!str) |
| 979 | return -ENOMEM; |
| 980 | } |
| 981 | |
| 982 | *pstr = str; |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | static int parse_absolute_time(struct data__file *d, char **pstr) |
| 987 | { |
| 988 | char *p = *pstr; |
| 989 | int ret; |
| 990 | |
| 991 | /* |
| 992 | * Absolute timestamp for one file has the format: a.b,c.d |
| 993 | * For multiple files, the format is: a.b,c.d:a.b,c.d |
| 994 | */ |
| 995 | p = strchr(*pstr, ':'); |
| 996 | if (p) { |
| 997 | if (p == *pstr) { |
| 998 | pr_err("Invalid time string\n"); |
| 999 | return -EINVAL; |
| 1000 | } |
| 1001 | |
| 1002 | *p = 0; |
| 1003 | p++; |
| 1004 | if (*p == 0) { |
| 1005 | pr_err("Invalid time string\n"); |
| 1006 | return -EINVAL; |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | ret = perf_time__parse_for_ranges(*pstr, d->session, |
| 1011 | &pdiff.ptime_range, |
| 1012 | &pdiff.range_size, |
| 1013 | &pdiff.range_num); |
| 1014 | if (ret < 0) |
| 1015 | return ret; |
| 1016 | |
| 1017 | if (!p || *p == 0) |
| 1018 | *pstr = NULL; |
| 1019 | else |
| 1020 | *pstr = p; |
| 1021 | |
| 1022 | return ret; |
| 1023 | } |
| 1024 | |
| 1025 | static int parse_percent_time(struct data__file *d) |
| 1026 | { |
| 1027 | int ret; |
| 1028 | |
| 1029 | ret = perf_time__parse_for_ranges(pdiff.time_str, d->session, |
| 1030 | &pdiff.ptime_range, |
| 1031 | &pdiff.range_size, |
| 1032 | &pdiff.range_num); |
| 1033 | return ret; |
| 1034 | } |
| 1035 | |
| 1036 | static int parse_time_str(struct data__file *d, char *abstime_ostr, |
| 1037 | char **pabstime_tmp) |
| 1038 | { |
| 1039 | int ret = 0; |
| 1040 | |
| 1041 | if (abstime_ostr) |
| 1042 | ret = parse_absolute_time(d, pabstime_tmp); |
| 1043 | else if (pdiff.time_str) |
| 1044 | ret = parse_percent_time(d); |
| 1045 | |
| 1046 | return ret; |
| 1047 | } |
| 1048 | |
Jin Yao | 30d8155 | 2019-06-28 17:23:00 +0800 | [diff] [blame] | 1049 | static int check_file_brstack(void) |
| 1050 | { |
| 1051 | struct data__file *d; |
| 1052 | bool has_br_stack; |
| 1053 | int i; |
| 1054 | |
| 1055 | data__for_each_file(i, d) { |
| 1056 | d->session = perf_session__new(&d->data, false, &pdiff.tool); |
| 1057 | if (!d->session) { |
| 1058 | pr_err("Failed to open %s\n", d->data.path); |
| 1059 | return -1; |
| 1060 | } |
| 1061 | |
| 1062 | has_br_stack = perf_header__has_feat(&d->session->header, |
| 1063 | HEADER_BRANCH_STACK); |
| 1064 | perf_session__delete(d->session); |
| 1065 | if (!has_br_stack) |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
| 1069 | /* Set only all files having branch stacks */ |
| 1070 | pdiff.has_br_stack = true; |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1074 | static int __cmd_diff(void) |
| 1075 | { |
| 1076 | struct data__file *d; |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 1077 | int ret, i; |
| 1078 | char *abstime_ostr, *abstime_tmp; |
| 1079 | |
| 1080 | ret = abstime_str_dup(&abstime_ostr); |
| 1081 | if (ret) |
| 1082 | return ret; |
| 1083 | |
| 1084 | abstime_tmp = abstime_ostr; |
| 1085 | ret = -EINVAL; |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1086 | |
| 1087 | data__for_each_file(i, d) { |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 1088 | d->session = perf_session__new(&d->data, false, &pdiff.tool); |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1089 | if (!d->session) { |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 1090 | pr_err("Failed to open %s\n", d->data.path); |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 1091 | ret = -1; |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1092 | goto out_delete; |
| 1093 | } |
| 1094 | |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 1095 | if (pdiff.time_str) { |
| 1096 | ret = parse_time_str(d, abstime_ostr, &abstime_tmp); |
| 1097 | if (ret < 0) |
| 1098 | goto out_delete; |
| 1099 | } |
| 1100 | |
Jin Yao | daca23b | 2019-03-05 21:05:42 +0800 | [diff] [blame] | 1101 | if (cpu_list) { |
| 1102 | ret = perf_session__cpu_bitmap(d->session, cpu_list, |
| 1103 | cpu_bitmap); |
| 1104 | if (ret < 0) |
| 1105 | goto out_delete; |
| 1106 | } |
| 1107 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1108 | ret = perf_session__process_events(d->session); |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1109 | if (ret) { |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 1110 | pr_err("Failed to process %s\n", d->data.path); |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1111 | goto out_delete; |
| 1112 | } |
| 1113 | |
| 1114 | perf_evlist__collapse_resort(d->session->evlist); |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 1115 | |
| 1116 | if (pdiff.ptime_range) |
| 1117 | zfree(&pdiff.ptime_range); |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 1118 | } |
| 1119 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1120 | data_process(); |
| 1121 | |
| 1122 | out_delete: |
| 1123 | data__for_each_file(i, d) { |
Arnaldo Carvalho de Melo | e144655 | 2016-06-22 10:02:16 -0300 | [diff] [blame] | 1124 | perf_session__delete(d->session); |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1125 | data__free(d); |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | free(data__files); |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 1129 | |
| 1130 | if (pdiff.ptime_range) |
| 1131 | zfree(&pdiff.ptime_range); |
| 1132 | |
| 1133 | if (abstime_ostr) |
| 1134 | free(abstime_ostr); |
| 1135 | |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1136 | return ret; |
| 1137 | } |
| 1138 | |
Arnaldo Carvalho de Melo | 0422a4f | 2009-12-18 16:35:58 -0200 | [diff] [blame] | 1139 | static const char * const diff_usage[] = { |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1140 | "perf diff [<options>] [old_file] [new_file]", |
Arnaldo Carvalho de Melo | 0422a4f | 2009-12-18 16:35:58 -0200 | [diff] [blame] | 1141 | NULL, |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1142 | }; |
| 1143 | |
| 1144 | static const struct option options[] = { |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 1145 | OPT_INCR('v', "verbose", &verbose, |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1146 | "be more verbose (show symbol address, etc)"), |
Namhyung Kim | 63b42fc | 2017-02-17 17:17:40 +0900 | [diff] [blame] | 1147 | OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"), |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 1148 | OPT_BOOLEAN('b', "baseline-only", &show_baseline_only, |
| 1149 | "Show only items with match in baseline"), |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 1150 | OPT_CALLBACK('c', "compute", &compute, |
Namhyung Kim | be57b3f | 2017-02-11 01:18:56 +0900 | [diff] [blame] | 1151 | "delta,delta-abs,ratio,wdiff:w1,w2 (default delta-abs)", |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 1152 | "Entries differential computation selection", |
| 1153 | setup_compute), |
Jiri Olsa | 61949b2 | 2012-10-05 16:44:44 +0200 | [diff] [blame] | 1154 | OPT_BOOLEAN('p', "period", &show_period, |
| 1155 | "Show period values."), |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 1156 | OPT_BOOLEAN('F', "formula", &show_formula, |
| 1157 | "Show formula."), |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1158 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 1159 | "dump raw trace in ASCII"), |
| 1160 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
David Ahern | 6b1f342 | 2015-03-24 09:51:57 -0600 | [diff] [blame] | 1161 | OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, |
| 1162 | "file", "kallsyms pathname"), |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1163 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, |
| 1164 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 1165 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", |
| 1166 | "only consider symbols in these dsos"), |
| 1167 | OPT_STRING('C', "comms", &symbol_conf.comm_list_str, "comm[,comm...]", |
| 1168 | "only consider symbols in these comms"), |
| 1169 | OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", |
| 1170 | "only consider these symbols"), |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1171 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
Namhyung Kim | a2ce067 | 2014-03-04 09:06:42 +0900 | [diff] [blame] | 1172 | "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..." |
| 1173 | " Please refer the man page for the complete list."), |
Wang Nan | 8b8ca6e | 2015-03-20 02:57:52 +0000 | [diff] [blame] | 1174 | OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator", |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1175 | "separator for columns, no spaces will be added between " |
| 1176 | "columns '.' is reserved."), |
He Kuang | a706670 | 2016-05-19 11:47:37 +0000 | [diff] [blame] | 1177 | OPT_CALLBACK(0, "symfs", NULL, "directory", |
| 1178 | "Look for files with symbols relative to this directory", |
| 1179 | symbol__config_symfs), |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 1180 | OPT_UINTEGER('o', "order", &sort_compute, "Specify compute sorting."), |
Namhyung Kim | 8810f6c | 2014-02-07 12:06:07 +0900 | [diff] [blame] | 1181 | OPT_CALLBACK(0, "percentage", NULL, "relative|absolute", |
| 1182 | "How to display percentage of filtered entries", parse_filter_percentage), |
Jin Yao | 4802138 | 2019-03-05 21:05:41 +0800 | [diff] [blame] | 1183 | OPT_STRING(0, "time", &pdiff.time_str, "str", |
| 1184 | "Time span (time percent or absolute timestamp)"), |
Jin Yao | daca23b | 2019-03-05 21:05:42 +0800 | [diff] [blame] | 1185 | OPT_STRING(0, "cpu", &cpu_list, "cpu", "list of cpus to profile"), |
Jin Yao | c1d3e63 | 2019-03-05 21:05:43 +0800 | [diff] [blame] | 1186 | OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]", |
| 1187 | "only consider symbols in these pids"), |
| 1188 | OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]", |
| 1189 | "only consider symbols in these tids"), |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1190 | OPT_END() |
| 1191 | }; |
| 1192 | |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1193 | static double baseline_percent(struct hist_entry *he) |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 1194 | { |
Namhyung Kim | 8810f6c | 2014-02-07 12:06:07 +0900 | [diff] [blame] | 1195 | u64 total = hists__total_period(he->hists); |
| 1196 | |
| 1197 | return 100.0 * he->stat.period / total; |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1198 | } |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 1199 | |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1200 | static int hpp__color_baseline(struct perf_hpp_fmt *fmt, |
| 1201 | struct perf_hpp *hpp, struct hist_entry *he) |
| 1202 | { |
| 1203 | struct diff_hpp_fmt *dfmt = |
| 1204 | container_of(fmt, struct diff_hpp_fmt, fmt); |
| 1205 | double percent = baseline_percent(he); |
| 1206 | char pfmt[20] = " "; |
| 1207 | |
| 1208 | if (!he->dummy) { |
| 1209 | scnprintf(pfmt, 20, "%%%d.2f%%%%", dfmt->header_width - 1); |
| 1210 | return percent_color_snprintf(hpp->buf, hpp->size, |
| 1211 | pfmt, percent); |
| 1212 | } else |
| 1213 | return scnprintf(hpp->buf, hpp->size, "%*s", |
| 1214 | dfmt->header_width, pfmt); |
| 1215 | } |
| 1216 | |
| 1217 | static int hpp__entry_baseline(struct hist_entry *he, char *buf, size_t size) |
| 1218 | { |
| 1219 | double percent = baseline_percent(he); |
| 1220 | const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; |
| 1221 | int ret = 0; |
| 1222 | |
| 1223 | if (!he->dummy) |
| 1224 | ret = scnprintf(buf, size, fmt, percent); |
| 1225 | |
| 1226 | return ret; |
| 1227 | } |
| 1228 | |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1229 | static int __hpp__color_compare(struct perf_hpp_fmt *fmt, |
| 1230 | struct perf_hpp *hpp, struct hist_entry *he, |
| 1231 | int comparison_method) |
| 1232 | { |
| 1233 | struct diff_hpp_fmt *dfmt = |
| 1234 | container_of(fmt, struct diff_hpp_fmt, fmt); |
| 1235 | struct hist_entry *pair = get_pair_fmt(he, dfmt); |
| 1236 | double diff; |
Ramkumar Ramachandra | a5846e2 | 2013-12-30 13:32:35 +0530 | [diff] [blame] | 1237 | s64 wdiff; |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1238 | char pfmt[20] = " "; |
| 1239 | |
| 1240 | if (!pair) |
Namhyung Kim | ec3d07c | 2014-12-27 14:06:31 +0900 | [diff] [blame] | 1241 | goto no_print; |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1242 | |
| 1243 | switch (comparison_method) { |
| 1244 | case COMPUTE_DELTA: |
| 1245 | if (pair->diff.computed) |
| 1246 | diff = pair->diff.period_ratio_delta; |
| 1247 | else |
| 1248 | diff = compute_delta(he, pair); |
| 1249 | |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1250 | scnprintf(pfmt, 20, "%%%+d.2f%%%%", dfmt->header_width - 1); |
| 1251 | return percent_color_snprintf(hpp->buf, hpp->size, |
| 1252 | pfmt, diff); |
Ramkumar Ramachandra | 1f513b2 | 2013-12-30 13:04:20 +0530 | [diff] [blame] | 1253 | case COMPUTE_RATIO: |
| 1254 | if (he->dummy) |
| 1255 | goto dummy_print; |
| 1256 | if (pair->diff.computed) |
| 1257 | diff = pair->diff.period_ratio; |
| 1258 | else |
| 1259 | diff = compute_ratio(he, pair); |
| 1260 | |
| 1261 | scnprintf(pfmt, 20, "%%%d.6f", dfmt->header_width); |
| 1262 | return value_color_snprintf(hpp->buf, hpp->size, |
| 1263 | pfmt, diff); |
Ramkumar Ramachandra | a5846e2 | 2013-12-30 13:32:35 +0530 | [diff] [blame] | 1264 | case COMPUTE_WEIGHTED_DIFF: |
| 1265 | if (he->dummy) |
| 1266 | goto dummy_print; |
| 1267 | if (pair->diff.computed) |
| 1268 | wdiff = pair->diff.wdiff; |
| 1269 | else |
| 1270 | wdiff = compute_wdiff(he, pair); |
| 1271 | |
| 1272 | scnprintf(pfmt, 20, "%%14ld", dfmt->header_width); |
| 1273 | return color_snprintf(hpp->buf, hpp->size, |
| 1274 | get_percent_color(wdiff), |
| 1275 | pfmt, wdiff); |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1276 | default: |
| 1277 | BUG_ON(1); |
| 1278 | } |
| 1279 | dummy_print: |
| 1280 | return scnprintf(hpp->buf, hpp->size, "%*s", |
Namhyung Kim | ec3d07c | 2014-12-27 14:06:31 +0900 | [diff] [blame] | 1281 | dfmt->header_width, "N/A"); |
| 1282 | no_print: |
| 1283 | return scnprintf(hpp->buf, hpp->size, "%*s", |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1284 | dfmt->header_width, pfmt); |
| 1285 | } |
| 1286 | |
| 1287 | static int hpp__color_delta(struct perf_hpp_fmt *fmt, |
| 1288 | struct perf_hpp *hpp, struct hist_entry *he) |
| 1289 | { |
| 1290 | return __hpp__color_compare(fmt, hpp, he, COMPUTE_DELTA); |
| 1291 | } |
| 1292 | |
Ramkumar Ramachandra | 1f513b2 | 2013-12-30 13:04:20 +0530 | [diff] [blame] | 1293 | static int hpp__color_ratio(struct perf_hpp_fmt *fmt, |
| 1294 | struct perf_hpp *hpp, struct hist_entry *he) |
| 1295 | { |
| 1296 | return __hpp__color_compare(fmt, hpp, he, COMPUTE_RATIO); |
| 1297 | } |
| 1298 | |
Ramkumar Ramachandra | a5846e2 | 2013-12-30 13:32:35 +0530 | [diff] [blame] | 1299 | static int hpp__color_wdiff(struct perf_hpp_fmt *fmt, |
| 1300 | struct perf_hpp *hpp, struct hist_entry *he) |
| 1301 | { |
| 1302 | return __hpp__color_compare(fmt, hpp, he, COMPUTE_WEIGHTED_DIFF); |
| 1303 | } |
| 1304 | |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1305 | static void |
| 1306 | hpp__entry_unpair(struct hist_entry *he, int idx, char *buf, size_t size) |
| 1307 | { |
| 1308 | switch (idx) { |
| 1309 | case PERF_HPP_DIFF__PERIOD_BASELINE: |
| 1310 | scnprintf(buf, size, "%" PRIu64, he->stat.period); |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 1311 | break; |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1312 | |
| 1313 | default: |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 1314 | break; |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | static void |
| 1319 | hpp__entry_pair(struct hist_entry *he, struct hist_entry *pair, |
| 1320 | int idx, char *buf, size_t size) |
| 1321 | { |
| 1322 | double diff; |
| 1323 | double ratio; |
| 1324 | s64 wdiff; |
| 1325 | |
| 1326 | switch (idx) { |
| 1327 | case PERF_HPP_DIFF__DELTA: |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 1328 | case PERF_HPP_DIFF__DELTA_ABS: |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1329 | if (pair->diff.computed) |
| 1330 | diff = pair->diff.period_ratio_delta; |
| 1331 | else |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 1332 | diff = compute_delta(he, pair); |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1333 | |
Namhyung Kim | ec3d07c | 2014-12-27 14:06:31 +0900 | [diff] [blame] | 1334 | scnprintf(buf, size, "%+4.2F%%", diff); |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 1335 | break; |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1336 | |
| 1337 | case PERF_HPP_DIFF__RATIO: |
| 1338 | /* No point for ratio number if we are dummy.. */ |
Namhyung Kim | ec3d07c | 2014-12-27 14:06:31 +0900 | [diff] [blame] | 1339 | if (he->dummy) { |
| 1340 | scnprintf(buf, size, "N/A"); |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1341 | break; |
Namhyung Kim | ec3d07c | 2014-12-27 14:06:31 +0900 | [diff] [blame] | 1342 | } |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1343 | |
| 1344 | if (pair->diff.computed) |
| 1345 | ratio = pair->diff.period_ratio; |
| 1346 | else |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 1347 | ratio = compute_ratio(he, pair); |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1348 | |
| 1349 | if (ratio > 0.0) |
| 1350 | scnprintf(buf, size, "%14.6F", ratio); |
| 1351 | break; |
| 1352 | |
| 1353 | case PERF_HPP_DIFF__WEIGHTED_DIFF: |
| 1354 | /* No point for wdiff number if we are dummy.. */ |
Namhyung Kim | ec3d07c | 2014-12-27 14:06:31 +0900 | [diff] [blame] | 1355 | if (he->dummy) { |
| 1356 | scnprintf(buf, size, "N/A"); |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1357 | break; |
Namhyung Kim | ec3d07c | 2014-12-27 14:06:31 +0900 | [diff] [blame] | 1358 | } |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1359 | |
| 1360 | if (pair->diff.computed) |
| 1361 | wdiff = pair->diff.wdiff; |
| 1362 | else |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 1363 | wdiff = compute_wdiff(he, pair); |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1364 | |
| 1365 | if (wdiff != 0) |
| 1366 | scnprintf(buf, size, "%14ld", wdiff); |
| 1367 | break; |
| 1368 | |
| 1369 | case PERF_HPP_DIFF__FORMULA: |
Jiri Olsa | ef358e6 | 2012-10-21 23:31:51 +0200 | [diff] [blame] | 1370 | formula_fprintf(he, pair, buf, size); |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1371 | break; |
| 1372 | |
| 1373 | case PERF_HPP_DIFF__PERIOD: |
| 1374 | scnprintf(buf, size, "%" PRIu64, pair->stat.period); |
| 1375 | break; |
| 1376 | |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 1377 | default: |
| 1378 | BUG_ON(1); |
| 1379 | }; |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1380 | } |
| 1381 | |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 1382 | static void |
| 1383 | __hpp__entry_global(struct hist_entry *he, struct diff_hpp_fmt *dfmt, |
| 1384 | char *buf, size_t size) |
| 1385 | { |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 1386 | struct hist_entry *pair = get_pair_fmt(he, dfmt); |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 1387 | int idx = dfmt->idx; |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1388 | |
| 1389 | /* baseline is special */ |
| 1390 | if (idx == PERF_HPP_DIFF__BASELINE) |
| 1391 | hpp__entry_baseline(he, buf, size); |
| 1392 | else { |
| 1393 | if (pair) |
| 1394 | hpp__entry_pair(he, pair, idx, buf, size); |
| 1395 | else |
| 1396 | hpp__entry_unpair(he, idx, buf, size); |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | static int hpp__entry_global(struct perf_hpp_fmt *_fmt, struct perf_hpp *hpp, |
| 1401 | struct hist_entry *he) |
| 1402 | { |
| 1403 | struct diff_hpp_fmt *dfmt = |
| 1404 | container_of(_fmt, struct diff_hpp_fmt, fmt); |
| 1405 | char buf[MAX_COL_WIDTH] = " "; |
| 1406 | |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 1407 | __hpp__entry_global(he, dfmt, buf, MAX_COL_WIDTH); |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1408 | |
| 1409 | if (symbol_conf.field_sep) |
| 1410 | return scnprintf(hpp->buf, hpp->size, "%s", buf); |
| 1411 | else |
| 1412 | return scnprintf(hpp->buf, hpp->size, "%*s", |
| 1413 | dfmt->header_width, buf); |
| 1414 | } |
| 1415 | |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 1416 | static int hpp__header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
Jiri Olsa | 74bb43f | 2016-08-07 17:28:27 +0200 | [diff] [blame] | 1417 | struct hists *hists __maybe_unused, |
Jiri Olsa | 29659ab | 2016-08-07 17:28:30 +0200 | [diff] [blame] | 1418 | int line __maybe_unused, |
| 1419 | int *span __maybe_unused) |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1420 | { |
| 1421 | struct diff_hpp_fmt *dfmt = |
| 1422 | container_of(fmt, struct diff_hpp_fmt, fmt); |
| 1423 | |
| 1424 | BUG_ON(!dfmt->header); |
| 1425 | return scnprintf(hpp->buf, hpp->size, dfmt->header); |
| 1426 | } |
| 1427 | |
| 1428 | static int hpp__width(struct perf_hpp_fmt *fmt, |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 1429 | struct perf_hpp *hpp __maybe_unused, |
Jiri Olsa | da1b040 | 2016-06-14 20:19:20 +0200 | [diff] [blame] | 1430 | struct hists *hists __maybe_unused) |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1431 | { |
| 1432 | struct diff_hpp_fmt *dfmt = |
| 1433 | container_of(fmt, struct diff_hpp_fmt, fmt); |
| 1434 | |
| 1435 | BUG_ON(dfmt->header_width <= 0); |
| 1436 | return dfmt->header_width; |
| 1437 | } |
| 1438 | |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 1439 | static void init_header(struct data__file *d, struct diff_hpp_fmt *dfmt) |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1440 | { |
| 1441 | #define MAX_HEADER_NAME 100 |
| 1442 | char buf_indent[MAX_HEADER_NAME]; |
| 1443 | char buf[MAX_HEADER_NAME]; |
| 1444 | const char *header = NULL; |
| 1445 | int width = 0; |
| 1446 | |
| 1447 | BUG_ON(dfmt->idx >= PERF_HPP_DIFF__MAX_INDEX); |
| 1448 | header = columns[dfmt->idx].name; |
| 1449 | width = columns[dfmt->idx].width; |
| 1450 | |
| 1451 | /* Only our defined HPP fmts should appear here. */ |
| 1452 | BUG_ON(!header); |
| 1453 | |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 1454 | if (data__files_cnt > 2) |
| 1455 | scnprintf(buf, MAX_HEADER_NAME, "%s/%d", header, d->idx); |
| 1456 | |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1457 | #define NAME (data__files_cnt > 2 ? buf : header) |
| 1458 | dfmt->header_width = width; |
| 1459 | width = (int) strlen(NAME); |
| 1460 | if (dfmt->header_width < width) |
| 1461 | dfmt->header_width = width; |
| 1462 | |
| 1463 | scnprintf(buf_indent, MAX_HEADER_NAME, "%*s", |
| 1464 | dfmt->header_width, NAME); |
| 1465 | |
| 1466 | dfmt->header = strdup(buf_indent); |
| 1467 | #undef MAX_HEADER_NAME |
| 1468 | #undef NAME |
| 1469 | } |
| 1470 | |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1471 | static void data__hpp_register(struct data__file *d, int idx) |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1472 | { |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1473 | struct diff_hpp_fmt *dfmt = &d->fmt[idx]; |
| 1474 | struct perf_hpp_fmt *fmt = &dfmt->fmt; |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1475 | |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1476 | dfmt->idx = idx; |
| 1477 | |
| 1478 | fmt->header = hpp__header; |
| 1479 | fmt->width = hpp__width; |
| 1480 | fmt->entry = hpp__entry_global; |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 1481 | fmt->cmp = hist_entry__cmp_nop; |
| 1482 | fmt->collapse = hist_entry__cmp_nop; |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1483 | |
| 1484 | /* TODO more colors */ |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1485 | switch (idx) { |
| 1486 | case PERF_HPP_DIFF__BASELINE: |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1487 | fmt->color = hpp__color_baseline; |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 1488 | fmt->sort = hist_entry__cmp_baseline; |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1489 | break; |
| 1490 | case PERF_HPP_DIFF__DELTA: |
| 1491 | fmt->color = hpp__color_delta; |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 1492 | fmt->sort = hist_entry__cmp_delta; |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1493 | break; |
Ramkumar Ramachandra | 1f513b2 | 2013-12-30 13:04:20 +0530 | [diff] [blame] | 1494 | case PERF_HPP_DIFF__RATIO: |
| 1495 | fmt->color = hpp__color_ratio; |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 1496 | fmt->sort = hist_entry__cmp_ratio; |
Ramkumar Ramachandra | 1f513b2 | 2013-12-30 13:04:20 +0530 | [diff] [blame] | 1497 | break; |
Ramkumar Ramachandra | a5846e2 | 2013-12-30 13:32:35 +0530 | [diff] [blame] | 1498 | case PERF_HPP_DIFF__WEIGHTED_DIFF: |
| 1499 | fmt->color = hpp__color_wdiff; |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 1500 | fmt->sort = hist_entry__cmp_wdiff; |
Ramkumar Ramachandra | a5846e2 | 2013-12-30 13:32:35 +0530 | [diff] [blame] | 1501 | break; |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 1502 | case PERF_HPP_DIFF__DELTA_ABS: |
| 1503 | fmt->color = hpp__color_delta; |
| 1504 | fmt->sort = hist_entry__cmp_delta_abs; |
| 1505 | break; |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1506 | default: |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 1507 | fmt->sort = hist_entry__cmp_nop; |
Ramkumar Ramachandra | 01f10bc | 2013-12-30 13:04:19 +0530 | [diff] [blame] | 1508 | break; |
| 1509 | } |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1510 | |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 1511 | init_header(d, dfmt); |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1512 | perf_hpp__column_register(fmt); |
Namhyung Kim | e7024fc | 2014-12-27 14:06:29 +0900 | [diff] [blame] | 1513 | perf_hpp__register_sort_field(fmt); |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 1516 | static int ui_init(void) |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 1517 | { |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1518 | struct data__file *d; |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 1519 | struct perf_hpp_fmt *fmt; |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1520 | int i; |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 1521 | |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1522 | data__for_each_file(i, d) { |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 1523 | |
Jiri Olsa | c818b49 | 2012-12-01 21:57:04 +0100 | [diff] [blame] | 1524 | /* |
| 1525 | * Baseline or compute realted columns: |
| 1526 | * |
| 1527 | * PERF_HPP_DIFF__BASELINE |
| 1528 | * PERF_HPP_DIFF__DELTA |
| 1529 | * PERF_HPP_DIFF__RATIO |
| 1530 | * PERF_HPP_DIFF__WEIGHTED_DIFF |
| 1531 | */ |
| 1532 | data__hpp_register(d, i ? compute_2_hpp[compute] : |
| 1533 | PERF_HPP_DIFF__BASELINE); |
| 1534 | |
| 1535 | /* |
| 1536 | * And the rest: |
| 1537 | * |
| 1538 | * PERF_HPP_DIFF__FORMULA |
| 1539 | * PERF_HPP_DIFF__PERIOD |
| 1540 | * PERF_HPP_DIFF__PERIOD_BASELINE |
| 1541 | */ |
| 1542 | if (show_formula && i) |
| 1543 | data__hpp_register(d, PERF_HPP_DIFF__FORMULA); |
| 1544 | |
| 1545 | if (show_period) |
| 1546 | data__hpp_register(d, i ? PERF_HPP_DIFF__PERIOD : |
| 1547 | PERF_HPP_DIFF__PERIOD_BASELINE); |
Jiri Olsa | 61949b2 | 2012-10-05 16:44:44 +0200 | [diff] [blame] | 1548 | } |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 1549 | |
| 1550 | if (!sort_compute) |
| 1551 | return 0; |
| 1552 | |
| 1553 | /* |
| 1554 | * Prepend an fmt to sort on columns at 'sort_compute' first. |
| 1555 | * This fmt is added only to the sort list but not to the |
| 1556 | * output fields list. |
| 1557 | * |
| 1558 | * Note that this column (data) can be compared twice - one |
| 1559 | * for this 'sort_compute' fmt and another for the normal |
| 1560 | * diff_hpp_fmt. But it shouldn't a problem as most entries |
| 1561 | * will be sorted out by first try or baseline and comparing |
| 1562 | * is not a costly operation. |
| 1563 | */ |
| 1564 | fmt = zalloc(sizeof(*fmt)); |
| 1565 | if (fmt == NULL) { |
| 1566 | pr_err("Memory allocation failed\n"); |
| 1567 | return -1; |
| 1568 | } |
| 1569 | |
| 1570 | fmt->cmp = hist_entry__cmp_nop; |
| 1571 | fmt->collapse = hist_entry__cmp_nop; |
| 1572 | |
| 1573 | switch (compute) { |
| 1574 | case COMPUTE_DELTA: |
| 1575 | fmt->sort = hist_entry__cmp_delta_idx; |
| 1576 | break; |
| 1577 | case COMPUTE_RATIO: |
| 1578 | fmt->sort = hist_entry__cmp_ratio_idx; |
| 1579 | break; |
| 1580 | case COMPUTE_WEIGHTED_DIFF: |
| 1581 | fmt->sort = hist_entry__cmp_wdiff_idx; |
| 1582 | break; |
Namhyung Kim | a1668c2 | 2017-02-10 16:36:11 +0900 | [diff] [blame] | 1583 | case COMPUTE_DELTA_ABS: |
| 1584 | fmt->sort = hist_entry__cmp_delta_abs_idx; |
| 1585 | break; |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 1586 | case COMPUTE_CYCLES: |
| 1587 | /* |
| 1588 | * Should set since 'fmt->sort' is called without |
| 1589 | * checking valid during sorting |
| 1590 | */ |
| 1591 | fmt->sort = hist_entry__cmp_nop; |
| 1592 | break; |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 1593 | default: |
| 1594 | BUG_ON(1); |
| 1595 | } |
| 1596 | |
Namhyung Kim | a1c9f97 | 2017-01-18 14:14:57 +0900 | [diff] [blame] | 1597 | perf_hpp__prepend_sort_field(fmt); |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 1598 | return 0; |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 1599 | } |
| 1600 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1601 | static int data_init(int argc, const char **argv) |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1602 | { |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1603 | struct data__file *d; |
| 1604 | static const char *defaults[] = { |
| 1605 | "perf.data.old", |
| 1606 | "perf.data", |
| 1607 | }; |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 1608 | bool use_default = true; |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1609 | int i; |
| 1610 | |
| 1611 | data__files_cnt = 2; |
| 1612 | |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1613 | if (argc) { |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 1614 | if (argc == 1) |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1615 | defaults[1] = argv[0]; |
Jiri Olsa | 22aeb7f | 2012-12-01 22:00:00 +0100 | [diff] [blame] | 1616 | else { |
| 1617 | data__files_cnt = argc; |
| 1618 | use_default = false; |
| 1619 | } |
Dongsheng Yang | d8d9608 | 2013-12-06 17:25:52 -0500 | [diff] [blame] | 1620 | } else if (perf_guest) { |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1621 | defaults[0] = "perf.data.host"; |
| 1622 | defaults[1] = "perf.data.guest"; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1623 | } |
| 1624 | |
Jiri Olsa | 5f3f8d3 | 2012-11-25 23:10:20 +0100 | [diff] [blame] | 1625 | if (sort_compute >= (unsigned int) data__files_cnt) { |
| 1626 | pr_err("Order option out of limit.\n"); |
| 1627 | return -EINVAL; |
| 1628 | } |
| 1629 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1630 | data__files = zalloc(sizeof(*data__files) * data__files_cnt); |
| 1631 | if (!data__files) |
| 1632 | return -ENOMEM; |
| 1633 | |
| 1634 | data__for_each_file(i, d) { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1635 | struct perf_data *data = &d->data; |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1636 | |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 1637 | data->path = use_default ? defaults[i] : argv[i]; |
| 1638 | data->mode = PERF_DATA_MODE_READ, |
| 1639 | data->force = force, |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1640 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1641 | d->idx = i; |
| 1642 | } |
| 1643 | |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
Namhyung Kim | d49dd15 | 2017-02-10 16:36:12 +0900 | [diff] [blame] | 1647 | static int diff__config(const char *var, const char *value, |
| 1648 | void *cb __maybe_unused) |
| 1649 | { |
| 1650 | if (!strcmp(var, "diff.order")) { |
Arnaldo Carvalho de Melo | 25ce4bb | 2017-06-27 11:44:58 -0300 | [diff] [blame] | 1651 | int ret; |
| 1652 | if (perf_config_int(&ret, var, value) < 0) |
| 1653 | return -1; |
| 1654 | sort_compute = ret; |
Namhyung Kim | d49dd15 | 2017-02-10 16:36:12 +0900 | [diff] [blame] | 1655 | return 0; |
| 1656 | } |
Namhyung Kim | 4b35994 | 2017-02-10 16:36:13 +0900 | [diff] [blame] | 1657 | if (!strcmp(var, "diff.compute")) { |
| 1658 | if (!strcmp(value, "delta")) { |
| 1659 | compute = COMPUTE_DELTA; |
| 1660 | } else if (!strcmp(value, "delta-abs")) { |
| 1661 | compute = COMPUTE_DELTA_ABS; |
| 1662 | } else if (!strcmp(value, "ratio")) { |
| 1663 | compute = COMPUTE_RATIO; |
| 1664 | } else if (!strcmp(value, "wdiff")) { |
| 1665 | compute = COMPUTE_WEIGHTED_DIFF; |
| 1666 | } else { |
| 1667 | pr_err("Invalid compute method: %s\n", value); |
| 1668 | return -1; |
| 1669 | } |
| 1670 | } |
Namhyung Kim | d49dd15 | 2017-02-10 16:36:12 +0900 | [diff] [blame] | 1671 | |
| 1672 | return 0; |
| 1673 | } |
| 1674 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1675 | int cmd_diff(int argc, const char **argv) |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1676 | { |
Kan Liang | 9ab1f50 | 2014-10-22 15:02:41 -0400 | [diff] [blame] | 1677 | int ret = hists__init(); |
| 1678 | |
| 1679 | if (ret < 0) |
| 1680 | return ret; |
| 1681 | |
Namhyung Kim | d49dd15 | 2017-02-10 16:36:12 +0900 | [diff] [blame] | 1682 | perf_config(diff__config, NULL); |
| 1683 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1684 | argc = parse_options(argc, argv, options, diff_usage, 0); |
| 1685 | |
Namhyung Kim | 63b42fc | 2017-02-17 17:17:40 +0900 | [diff] [blame] | 1686 | if (quiet) |
| 1687 | perf_quiet_option(); |
| 1688 | |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 1689 | symbol__annotation_init(); |
| 1690 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 1691 | if (symbol__init(NULL) < 0) |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 1692 | return -1; |
| 1693 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 1694 | if (data_init(argc, argv) < 0) |
| 1695 | return -1; |
| 1696 | |
Jin Yao | 30d8155 | 2019-06-28 17:23:00 +0800 | [diff] [blame] | 1697 | if (check_file_brstack() < 0) |
| 1698 | return -1; |
| 1699 | |
Jin Yao | 99150a1 | 2019-06-28 17:23:01 +0800 | [diff] [blame^] | 1700 | if (compute == COMPUTE_CYCLES && !pdiff.has_br_stack) |
| 1701 | return -1; |
| 1702 | |
Namhyung Kim | 566b5cf | 2015-01-08 09:45:48 +0900 | [diff] [blame] | 1703 | if (ui_init() < 0) |
| 1704 | return -1; |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 1705 | |
Namhyung Kim | 512ae1b | 2014-03-18 11:31:39 +0900 | [diff] [blame] | 1706 | sort__mode = SORT_MODE__DIFF; |
| 1707 | |
Namhyung Kim | 40184c4 | 2015-12-23 02:07:01 +0900 | [diff] [blame] | 1708 | if (setup_sorting(NULL) < 0) |
Namhyung Kim | 5530998 | 2013-02-06 14:57:16 +0900 | [diff] [blame] | 1709 | usage_with_options(diff_usage, options); |
| 1710 | |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1711 | setup_pager(); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1712 | |
Namhyung Kim | 08e7154 | 2013-04-03 21:26:19 +0900 | [diff] [blame] | 1713 | sort__setup_elide(NULL); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1714 | |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1715 | return __cmd_diff(); |
| 1716 | } |