Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 1 | /* |
| 2 | * builtin-diff.c |
| 3 | * |
| 4 | * Builtin diff command: Analyze two perf.data input files, look up and read |
| 5 | * DSOs and symbol information, sort them and produce a diff. |
| 6 | */ |
| 7 | #include "builtin.h" |
| 8 | |
| 9 | #include "util/debug.h" |
| 10 | #include "util/event.h" |
| 11 | #include "util/hist.h" |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 12 | #include "util/evsel.h" |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 13 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 14 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 15 | #include "util/tool.h" |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 16 | #include "util/sort.h" |
| 17 | #include "util/symbol.h" |
| 18 | #include "util/util.h" |
| 19 | |
| 20 | #include <stdlib.h> |
| 21 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 22 | struct data__file { |
| 23 | struct perf_session *session; |
| 24 | const char *file; |
| 25 | int idx; |
| 26 | }; |
| 27 | |
| 28 | static struct data__file *data__files; |
| 29 | static int data__files_cnt; |
| 30 | |
| 31 | #define data__for_each_file_start(i, d, s) \ |
| 32 | for (i = s, d = &data__files[s]; \ |
| 33 | i < data__files_cnt; \ |
| 34 | i++, d = &data__files[i]) |
| 35 | |
| 36 | #define data__for_each_file(i, d) data__for_each_file_start(i, d, 0) |
| 37 | |
| 38 | static char diff__default_sort_order[] = "dso,symbol"; |
| 39 | static bool force; |
Jiri Olsa | 61949b2 | 2012-10-05 16:44:44 +0200 | [diff] [blame] | 40 | static bool show_period; |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 41 | static bool show_formula; |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 42 | static bool show_baseline_only; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 43 | static bool sort_compute; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 44 | |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 45 | static s64 compute_wdiff_w1; |
| 46 | static s64 compute_wdiff_w2; |
| 47 | |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 48 | enum { |
| 49 | COMPUTE_DELTA, |
| 50 | COMPUTE_RATIO, |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 51 | COMPUTE_WEIGHTED_DIFF, |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 52 | COMPUTE_MAX, |
| 53 | }; |
| 54 | |
| 55 | const char *compute_names[COMPUTE_MAX] = { |
| 56 | [COMPUTE_DELTA] = "delta", |
| 57 | [COMPUTE_RATIO] = "ratio", |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 58 | [COMPUTE_WEIGHTED_DIFF] = "wdiff", |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | static int compute; |
| 62 | |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 63 | static int setup_compute_opt_wdiff(char *opt) |
| 64 | { |
| 65 | char *w1_str = opt; |
| 66 | char *w2_str; |
| 67 | |
| 68 | int ret = -EINVAL; |
| 69 | |
| 70 | if (!opt) |
| 71 | goto out; |
| 72 | |
| 73 | w2_str = strchr(opt, ','); |
| 74 | if (!w2_str) |
| 75 | goto out; |
| 76 | |
| 77 | *w2_str++ = 0x0; |
| 78 | if (!*w2_str) |
| 79 | goto out; |
| 80 | |
| 81 | compute_wdiff_w1 = strtol(w1_str, NULL, 10); |
| 82 | compute_wdiff_w2 = strtol(w2_str, NULL, 10); |
| 83 | |
| 84 | if (!compute_wdiff_w1 || !compute_wdiff_w2) |
| 85 | goto out; |
| 86 | |
| 87 | pr_debug("compute wdiff w1(%" PRId64 ") w2(%" PRId64 ")\n", |
| 88 | compute_wdiff_w1, compute_wdiff_w2); |
| 89 | |
| 90 | ret = 0; |
| 91 | |
| 92 | out: |
| 93 | if (ret) |
| 94 | pr_err("Failed: wrong weight data, use 'wdiff:w1,w2'\n"); |
| 95 | |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | static int setup_compute_opt(char *opt) |
| 100 | { |
| 101 | if (compute == COMPUTE_WEIGHTED_DIFF) |
| 102 | return setup_compute_opt_wdiff(opt); |
| 103 | |
| 104 | if (opt) { |
| 105 | pr_err("Failed: extra option specified '%s'", opt); |
| 106 | return -EINVAL; |
| 107 | } |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 112 | static int setup_compute(const struct option *opt, const char *str, |
| 113 | int unset __maybe_unused) |
| 114 | { |
| 115 | int *cp = (int *) opt->value; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 116 | char *cstr = (char *) str; |
| 117 | char buf[50]; |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 118 | unsigned i; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 119 | char *option; |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 120 | |
| 121 | if (!str) { |
| 122 | *cp = COMPUTE_DELTA; |
| 123 | return 0; |
| 124 | } |
| 125 | |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 126 | if (*str == '+') { |
| 127 | sort_compute = true; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 128 | cstr = (char *) ++str; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 129 | if (!*str) |
| 130 | return 0; |
| 131 | } |
| 132 | |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 133 | option = strchr(str, ':'); |
| 134 | if (option) { |
| 135 | unsigned len = option++ - str; |
| 136 | |
| 137 | /* |
| 138 | * The str data are not writeable, so we need |
| 139 | * to use another buffer. |
| 140 | */ |
| 141 | |
| 142 | /* No option value is longer. */ |
| 143 | if (len >= sizeof(buf)) |
| 144 | return -EINVAL; |
| 145 | |
| 146 | strncpy(buf, str, len); |
| 147 | buf[len] = 0x0; |
| 148 | cstr = buf; |
| 149 | } |
| 150 | |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 151 | for (i = 0; i < COMPUTE_MAX; i++) |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 152 | if (!strcmp(cstr, compute_names[i])) { |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 153 | *cp = i; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 154 | return setup_compute_opt(option); |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | pr_err("Failed: '%s' is not computation method " |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 158 | "(use 'delta','ratio' or 'wdiff')\n", str); |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 159 | return -EINVAL; |
| 160 | } |
| 161 | |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 162 | double perf_diff__period_percent(struct hist_entry *he, u64 period) |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 163 | { |
| 164 | u64 total = he->hists->stats.total_period; |
| 165 | return (period * 100.0) / total; |
| 166 | } |
| 167 | |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 168 | double perf_diff__compute_delta(struct hist_entry *he, struct hist_entry *pair) |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 169 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 170 | double old_percent = perf_diff__period_percent(he, he->stat.period); |
| 171 | double new_percent = perf_diff__period_percent(pair, pair->stat.period); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 172 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 173 | pair->diff.period_ratio_delta = new_percent - old_percent; |
| 174 | pair->diff.computed = true; |
| 175 | return pair->diff.period_ratio_delta; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 178 | double perf_diff__compute_ratio(struct hist_entry *he, struct hist_entry *pair) |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 179 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 180 | double old_period = he->stat.period ?: 1; |
| 181 | double new_period = pair->stat.period; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 182 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 183 | pair->diff.computed = true; |
| 184 | pair->diff.period_ratio = new_period / old_period; |
| 185 | return pair->diff.period_ratio; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 188 | s64 perf_diff__compute_wdiff(struct hist_entry *he, struct hist_entry *pair) |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 189 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 190 | u64 old_period = he->stat.period; |
| 191 | u64 new_period = pair->stat.period; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 192 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 193 | pair->diff.computed = true; |
| 194 | pair->diff.wdiff = new_period * compute_wdiff_w2 - |
| 195 | old_period * compute_wdiff_w1; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 196 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 197 | return pair->diff.wdiff; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 200 | static int formula_delta(struct hist_entry *he, struct hist_entry *pair, |
| 201 | char *buf, size_t size) |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 202 | { |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 203 | return scnprintf(buf, size, |
| 204 | "(%" PRIu64 " * 100 / %" PRIu64 ") - " |
| 205 | "(%" PRIu64 " * 100 / %" PRIu64 ")", |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 206 | pair->stat.period, pair->hists->stats.total_period, |
| 207 | he->stat.period, he->hists->stats.total_period); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 210 | static int formula_ratio(struct hist_entry *he, struct hist_entry *pair, |
| 211 | char *buf, size_t size) |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 212 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 213 | double old_period = he->stat.period; |
| 214 | double new_period = pair->stat.period; |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 215 | |
| 216 | return scnprintf(buf, size, "%.0F / %.0F", new_period, old_period); |
| 217 | } |
| 218 | |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 219 | static int formula_wdiff(struct hist_entry *he, struct hist_entry *pair, |
| 220 | char *buf, size_t size) |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 221 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 222 | u64 old_period = he->stat.period; |
| 223 | u64 new_period = pair->stat.period; |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 224 | |
| 225 | return scnprintf(buf, size, |
| 226 | "(%" PRIu64 " * " "%" PRId64 ") - (%" PRIu64 " * " "%" PRId64 ")", |
| 227 | new_period, compute_wdiff_w2, old_period, compute_wdiff_w1); |
| 228 | } |
| 229 | |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 230 | int perf_diff__formula(struct hist_entry *he, struct hist_entry *pair, |
| 231 | char *buf, size_t size) |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 232 | { |
| 233 | switch (compute) { |
| 234 | case COMPUTE_DELTA: |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 235 | return formula_delta(he, pair, buf, size); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 236 | case COMPUTE_RATIO: |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 237 | return formula_ratio(he, pair, buf, size); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 238 | case COMPUTE_WEIGHTED_DIFF: |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 239 | return formula_wdiff(he, pair, buf, size); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 240 | default: |
| 241 | BUG_ON(1); |
| 242 | } |
| 243 | |
| 244 | return -1; |
| 245 | } |
| 246 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 247 | static int hists__add_entry(struct hists *self, |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 248 | struct addr_location *al, u64 period, |
| 249 | u64 weight) |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 250 | { |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 251 | if (__hists__add_entry(self, al, NULL, period, weight) != NULL) |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 252 | return 0; |
| 253 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 254 | } |
| 255 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 256 | static int diff__process_sample_event(struct perf_tool *tool __maybe_unused, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 257 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 258 | struct perf_sample *sample, |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 259 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 260 | struct machine *machine) |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 261 | { |
| 262 | struct addr_location al; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 263 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 264 | if (perf_event__preprocess_sample(event, machine, &al, sample, NULL) < 0) { |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 265 | pr_warning("problem processing %d event, skipping it.\n", |
| 266 | event->header.type); |
| 267 | return -1; |
| 268 | } |
| 269 | |
Jiri Olsa | d88c48f | 2012-10-05 16:44:46 +0200 | [diff] [blame] | 270 | if (al.filtered) |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 271 | return 0; |
| 272 | |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 273 | if (hists__add_entry(&evsel->hists, &al, sample->period, sample->weight)) { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 274 | pr_warning("problem incrementing symbol period, skipping event\n"); |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 275 | return -1; |
| 276 | } |
| 277 | |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 278 | evsel->hists.stats.total_period += sample->period; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 279 | return 0; |
| 280 | } |
| 281 | |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 282 | static struct perf_tool tool = { |
| 283 | .sample = diff__process_sample_event, |
| 284 | .mmap = perf_event__process_mmap, |
| 285 | .comm = perf_event__process_comm, |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 286 | .exit = perf_event__process_exit, |
| 287 | .fork = perf_event__process_fork, |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 288 | .lost = perf_event__process_lost, |
| 289 | .ordered_samples = true, |
| 290 | .ordering_requires_timestamps = true, |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 291 | }; |
| 292 | |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 293 | static struct perf_evsel *evsel_match(struct perf_evsel *evsel, |
| 294 | struct perf_evlist *evlist) |
| 295 | { |
| 296 | struct perf_evsel *e; |
| 297 | |
| 298 | list_for_each_entry(e, &evlist->entries, node) |
| 299 | if (perf_evsel__match2(evsel, e)) |
| 300 | return e; |
| 301 | |
| 302 | return NULL; |
| 303 | } |
| 304 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 305 | static void perf_evlist__collapse_resort(struct perf_evlist *evlist) |
Jiri Olsa | dd46434 | 2012-10-04 21:49:36 +0900 | [diff] [blame] | 306 | { |
| 307 | struct perf_evsel *evsel; |
| 308 | |
| 309 | list_for_each_entry(evsel, &evlist->entries, node) { |
| 310 | struct hists *hists = &evsel->hists; |
| 311 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 312 | hists__collapse_resort(hists); |
Jiri Olsa | dd46434 | 2012-10-04 21:49:36 +0900 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 316 | static void hists__baseline_only(struct hists *hists) |
| 317 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 318 | struct rb_root *root; |
| 319 | struct rb_node *next; |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 320 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 321 | if (sort__need_collapse) |
| 322 | root = &hists->entries_collapsed; |
| 323 | else |
| 324 | root = hists->entries_in; |
| 325 | |
| 326 | next = rb_first(root); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 327 | while (next != NULL) { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 328 | 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] | 329 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 330 | next = rb_next(&he->rb_node_in); |
Arnaldo Carvalho de Melo | b821c73 | 2012-10-25 14:42:45 -0200 | [diff] [blame] | 331 | if (!hist_entry__next_pair(he)) { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 332 | rb_erase(&he->rb_node_in, root); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 333 | hist_entry__free(he); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 338 | static void hists__precompute(struct hists *hists) |
| 339 | { |
Jiri Olsa | 367c53c | 2012-12-13 14:08:59 +0100 | [diff] [blame] | 340 | struct rb_root *root; |
| 341 | struct rb_node *next; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 342 | |
Jiri Olsa | 367c53c | 2012-12-13 14:08:59 +0100 | [diff] [blame] | 343 | if (sort__need_collapse) |
| 344 | root = &hists->entries_collapsed; |
| 345 | else |
| 346 | root = hists->entries_in; |
| 347 | |
| 348 | next = rb_first(root); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 349 | while (next != NULL) { |
Jiri Olsa | 367c53c | 2012-12-13 14:08:59 +0100 | [diff] [blame] | 350 | struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node_in); |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 351 | struct hist_entry *pair = hist_entry__next_pair(he); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 352 | |
Jiri Olsa | 367c53c | 2012-12-13 14:08:59 +0100 | [diff] [blame] | 353 | next = rb_next(&he->rb_node_in); |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 354 | if (!pair) |
| 355 | continue; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 356 | |
| 357 | switch (compute) { |
| 358 | case COMPUTE_DELTA: |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 359 | perf_diff__compute_delta(he, pair); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 360 | break; |
| 361 | case COMPUTE_RATIO: |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 362 | perf_diff__compute_ratio(he, pair); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 363 | break; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 364 | case COMPUTE_WEIGHTED_DIFF: |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 365 | perf_diff__compute_wdiff(he, pair); |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 366 | break; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 367 | default: |
| 368 | BUG_ON(1); |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | static int64_t cmp_doubles(double l, double r) |
| 374 | { |
| 375 | if (l > r) |
| 376 | return -1; |
| 377 | else if (l < r) |
| 378 | return 1; |
| 379 | else |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | static int64_t |
| 384 | hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right, |
| 385 | int c) |
| 386 | { |
| 387 | switch (c) { |
| 388 | case COMPUTE_DELTA: |
| 389 | { |
| 390 | double l = left->diff.period_ratio_delta; |
| 391 | double r = right->diff.period_ratio_delta; |
| 392 | |
| 393 | return cmp_doubles(l, r); |
| 394 | } |
| 395 | case COMPUTE_RATIO: |
| 396 | { |
| 397 | double l = left->diff.period_ratio; |
| 398 | double r = right->diff.period_ratio; |
| 399 | |
| 400 | return cmp_doubles(l, r); |
| 401 | } |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 402 | case COMPUTE_WEIGHTED_DIFF: |
| 403 | { |
| 404 | s64 l = left->diff.wdiff; |
| 405 | s64 r = right->diff.wdiff; |
| 406 | |
| 407 | return r - l; |
| 408 | } |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 409 | default: |
| 410 | BUG_ON(1); |
| 411 | } |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static void insert_hist_entry_by_compute(struct rb_root *root, |
| 417 | struct hist_entry *he, |
| 418 | int c) |
| 419 | { |
| 420 | struct rb_node **p = &root->rb_node; |
| 421 | struct rb_node *parent = NULL; |
| 422 | struct hist_entry *iter; |
| 423 | |
| 424 | while (*p != NULL) { |
| 425 | parent = *p; |
| 426 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 427 | if (hist_entry__cmp_compute(he, iter, c) < 0) |
| 428 | p = &(*p)->rb_left; |
| 429 | else |
| 430 | p = &(*p)->rb_right; |
| 431 | } |
| 432 | |
| 433 | rb_link_node(&he->rb_node, parent, p); |
| 434 | rb_insert_color(&he->rb_node, root); |
| 435 | } |
| 436 | |
| 437 | static void hists__compute_resort(struct hists *hists) |
| 438 | { |
Namhyung Kim | 66f97ed | 2012-12-10 17:29:56 +0900 | [diff] [blame] | 439 | struct rb_root *root; |
| 440 | struct rb_node *next; |
| 441 | |
| 442 | if (sort__need_collapse) |
| 443 | root = &hists->entries_collapsed; |
| 444 | else |
| 445 | root = hists->entries_in; |
| 446 | |
| 447 | hists->entries = RB_ROOT; |
| 448 | next = rb_first(root); |
| 449 | |
| 450 | hists->nr_entries = 0; |
| 451 | hists->stats.total_period = 0; |
| 452 | hists__reset_col_len(hists); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 453 | |
| 454 | while (next != NULL) { |
Namhyung Kim | 66f97ed | 2012-12-10 17:29:56 +0900 | [diff] [blame] | 455 | struct hist_entry *he; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 456 | |
Namhyung Kim | 66f97ed | 2012-12-10 17:29:56 +0900 | [diff] [blame] | 457 | he = rb_entry(next, struct hist_entry, rb_node_in); |
| 458 | next = rb_next(&he->rb_node_in); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 459 | |
Namhyung Kim | 66f97ed | 2012-12-10 17:29:56 +0900 | [diff] [blame] | 460 | insert_hist_entry_by_compute(&hists->entries, he, compute); |
| 461 | hists__inc_nr_entries(hists, he); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 462 | } |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 465 | static void hists__process(struct hists *base, struct hists *new) |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 466 | { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 467 | hists__match(base, new); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 468 | |
| 469 | if (show_baseline_only) |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 470 | hists__baseline_only(base); |
Arnaldo Carvalho de Melo | bfaef4b | 2012-11-08 18:08:26 -0300 | [diff] [blame] | 471 | else |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 472 | hists__link(base, new); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 473 | |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 474 | if (sort_compute) { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 475 | hists__precompute(base); |
| 476 | hists__compute_resort(base); |
Namhyung Kim | 66f97ed | 2012-12-10 17:29:56 +0900 | [diff] [blame] | 477 | } else { |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 478 | hists__output_resort(base); |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 479 | } |
| 480 | |
Jiri Olsa | 9af303e | 2012-12-01 21:15:40 +0100 | [diff] [blame^] | 481 | hists__fprintf(base, true, 0, 0, 0, stdout); |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 482 | } |
| 483 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 484 | static void data_process(void) |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 485 | { |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 486 | struct perf_evlist *evlist_old = data__files[0].session->evlist; |
| 487 | struct perf_evlist *evlist_new = data__files[1].session->evlist; |
| 488 | struct perf_evsel *evsel_old; |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 489 | bool first = true; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 490 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 491 | list_for_each_entry(evsel_old, &evlist_old->entries, node) { |
| 492 | struct perf_evsel *evsel_new; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 493 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 494 | evsel_new = evsel_match(evsel_old, evlist_new); |
| 495 | if (!evsel_new) |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 496 | continue; |
| 497 | |
| 498 | fprintf(stdout, "%s# Event '%s'\n#\n", first ? "" : "\n", |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 499 | perf_evsel__name(evsel_old)); |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 500 | |
| 501 | first = false; |
| 502 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 503 | hists__process(&evsel_old->hists, &evsel_new->hists); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | static int __cmd_diff(void) |
| 508 | { |
| 509 | struct data__file *d; |
| 510 | int ret = -EINVAL, i; |
| 511 | |
| 512 | data__for_each_file(i, d) { |
| 513 | d->session = perf_session__new(d->file, O_RDONLY, force, |
| 514 | false, &tool); |
| 515 | if (!d->session) { |
| 516 | pr_err("Failed to open %s\n", d->file); |
| 517 | ret = -ENOMEM; |
| 518 | goto out_delete; |
| 519 | } |
| 520 | |
| 521 | ret = perf_session__process_events(d->session, &tool); |
| 522 | if (ret) { |
| 523 | pr_err("Failed to process %s\n", d->file); |
| 524 | goto out_delete; |
| 525 | } |
| 526 | |
| 527 | perf_evlist__collapse_resort(d->session->evlist); |
Jiri Olsa | 863e451 | 2012-09-06 17:46:55 +0200 | [diff] [blame] | 528 | } |
| 529 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 530 | data_process(); |
| 531 | |
| 532 | out_delete: |
| 533 | data__for_each_file(i, d) { |
| 534 | if (d->session) |
| 535 | perf_session__delete(d->session); |
| 536 | } |
| 537 | |
| 538 | free(data__files); |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 539 | return ret; |
| 540 | } |
| 541 | |
Arnaldo Carvalho de Melo | 0422a4f | 2009-12-18 16:35:58 -0200 | [diff] [blame] | 542 | static const char * const diff_usage[] = { |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 543 | "perf diff [<options>] [old_file] [new_file]", |
Arnaldo Carvalho de Melo | 0422a4f | 2009-12-18 16:35:58 -0200 | [diff] [blame] | 544 | NULL, |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 545 | }; |
| 546 | |
| 547 | static const struct option options[] = { |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 548 | OPT_INCR('v', "verbose", &verbose, |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 549 | "be more verbose (show symbol address, etc)"), |
Jiri Olsa | a06d143 | 2012-10-05 16:44:40 +0200 | [diff] [blame] | 550 | OPT_BOOLEAN('b', "baseline-only", &show_baseline_only, |
| 551 | "Show only items with match in baseline"), |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 552 | OPT_CALLBACK('c', "compute", &compute, |
| 553 | "delta,ratio,wdiff:w1,w2 (default delta)", |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 554 | "Entries differential computation selection", |
| 555 | setup_compute), |
Jiri Olsa | 61949b2 | 2012-10-05 16:44:44 +0200 | [diff] [blame] | 556 | OPT_BOOLEAN('p', "period", &show_period, |
| 557 | "Show period values."), |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 558 | OPT_BOOLEAN('F', "formula", &show_formula, |
| 559 | "Show formula."), |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 560 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 561 | "dump raw trace in ASCII"), |
| 562 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
| 563 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, |
| 564 | "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] | 565 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", |
| 566 | "only consider symbols in these dsos"), |
| 567 | OPT_STRING('C', "comms", &symbol_conf.comm_list_str, "comm[,comm...]", |
| 568 | "only consider symbols in these comms"), |
| 569 | OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", |
| 570 | "only consider these symbols"), |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 571 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
| 572 | "sort by key(s): pid, comm, dso, symbol, parent"), |
| 573 | OPT_STRING('t', "field-separator", &symbol_conf.field_sep, "separator", |
| 574 | "separator for columns, no spaces will be added between " |
| 575 | "columns '.' is reserved."), |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 576 | OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory", |
| 577 | "Look for files with symbols relative to this directory"), |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 578 | OPT_END() |
| 579 | }; |
| 580 | |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 581 | static void ui_init(void) |
| 582 | { |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 583 | /* |
Jiri Olsa | db6d0bb | 2012-12-06 14:22:28 +0100 | [diff] [blame] | 584 | * Display baseline/delta/ratio |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 585 | * formula/periods columns. |
| 586 | */ |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 587 | perf_hpp__column_enable(PERF_HPP__BASELINE); |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 588 | |
| 589 | switch (compute) { |
| 590 | case COMPUTE_DELTA: |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 591 | perf_hpp__column_enable(PERF_HPP__DELTA); |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 592 | break; |
| 593 | case COMPUTE_RATIO: |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 594 | perf_hpp__column_enable(PERF_HPP__RATIO); |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 595 | break; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 596 | case COMPUTE_WEIGHTED_DIFF: |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 597 | perf_hpp__column_enable(PERF_HPP__WEIGHTED_DIFF); |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 598 | break; |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 599 | default: |
| 600 | BUG_ON(1); |
| 601 | }; |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 602 | |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 603 | if (show_formula) |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 604 | perf_hpp__column_enable(PERF_HPP__FORMULA); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 605 | |
Jiri Olsa | 61949b2 | 2012-10-05 16:44:44 +0200 | [diff] [blame] | 606 | if (show_period) { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 607 | perf_hpp__column_enable(PERF_HPP__PERIOD); |
| 608 | perf_hpp__column_enable(PERF_HPP__PERIOD_BASELINE); |
Jiri Olsa | 61949b2 | 2012-10-05 16:44:44 +0200 | [diff] [blame] | 609 | } |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 610 | } |
| 611 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 612 | static int data_init(int argc, const char **argv) |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 613 | { |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 614 | struct data__file *d; |
| 615 | static const char *defaults[] = { |
| 616 | "perf.data.old", |
| 617 | "perf.data", |
| 618 | }; |
| 619 | int i; |
| 620 | |
| 621 | data__files_cnt = 2; |
| 622 | |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 623 | if (argc) { |
| 624 | if (argc > 2) |
| 625 | usage_with_options(diff_usage, options); |
| 626 | if (argc == 2) { |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 627 | defaults[0] = argv[0]; |
| 628 | defaults[1] = argv[1]; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 629 | } else |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 630 | defaults[1] = argv[0]; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 631 | } else if (symbol_conf.default_guest_vmlinux_name || |
| 632 | symbol_conf.default_guest_kallsyms) { |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 633 | defaults[0] = "perf.data.host"; |
| 634 | defaults[1] = "perf.data.guest"; |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 635 | } |
| 636 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 637 | data__files = zalloc(sizeof(*data__files) * data__files_cnt); |
| 638 | if (!data__files) |
| 639 | return -ENOMEM; |
| 640 | |
| 641 | data__for_each_file(i, d) { |
| 642 | d->file = defaults[i]; |
| 643 | d->idx = i; |
| 644 | } |
| 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused) |
| 650 | { |
| 651 | sort_order = diff__default_sort_order; |
| 652 | argc = parse_options(argc, argv, options, diff_usage, 0); |
| 653 | |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 654 | if (symbol__init() < 0) |
| 655 | return -1; |
| 656 | |
Jiri Olsa | ec30842 | 2013-03-25 00:02:01 +0100 | [diff] [blame] | 657 | if (data_init(argc, argv) < 0) |
| 658 | return -1; |
| 659 | |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 660 | ui_init(); |
| 661 | |
Namhyung Kim | 5530998 | 2013-02-06 14:57:16 +0900 | [diff] [blame] | 662 | if (setup_sorting() < 0) |
| 663 | usage_with_options(diff_usage, options); |
| 664 | |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 665 | setup_pager(); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 666 | |
Namhyung Kim | 08e7154 | 2013-04-03 21:26:19 +0900 | [diff] [blame] | 667 | sort__setup_elide(NULL); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 668 | |
Arnaldo Carvalho de Melo | 86a9eee | 2009-12-14 20:09:31 -0200 | [diff] [blame] | 669 | return __cmd_diff(); |
| 670 | } |