Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jiri Olsa | 465f27a | 2016-08-26 10:36:12 +0200 | [diff] [blame] | 2 | /* |
| 3 | * This is rewrite of original c2c tool introduced in here: |
| 4 | * http://lwn.net/Articles/588866/ |
| 5 | * |
| 6 | * The original tool was changed to fit in current perf state. |
| 7 | * |
| 8 | * Original authors: |
| 9 | * Don Zickus <dzickus@redhat.com> |
| 10 | * Dick Fowles <fowles@inreach.com> |
| 11 | * Joe Mario <jmario@redhat.com> |
| 12 | */ |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 13 | #include <errno.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 14 | #include <inttypes.h> |
Jiri Olsa | 7aef3bf | 2016-09-22 17:36:38 +0200 | [diff] [blame] | 15 | #include <linux/compiler.h> |
| 16 | #include <linux/kernel.h> |
Jiri Olsa | cbb8850 | 2016-09-22 17:36:48 +0200 | [diff] [blame] | 17 | #include <linux/stringify.h> |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 18 | #include <asm/bug.h> |
Arnaldo Carvalho de Melo | 391e420 | 2017-04-19 18:51:14 -0300 | [diff] [blame] | 19 | #include <sys/param.h> |
Jiri Olsa | 7aef3bf | 2016-09-22 17:36:38 +0200 | [diff] [blame] | 20 | #include "util.h" |
| 21 | #include "debug.h" |
| 22 | #include "builtin.h" |
| 23 | #include <subcmd/parse-options.h> |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 24 | #include "mem-events.h" |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 25 | #include "session.h" |
| 26 | #include "hist.h" |
Jiri Olsa | cbb8850 | 2016-09-22 17:36:48 +0200 | [diff] [blame] | 27 | #include "sort.h" |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 28 | #include "tool.h" |
| 29 | #include "data.h" |
Arnaldo Carvalho de Melo | 5ab8c68 | 2017-04-25 15:30:47 -0300 | [diff] [blame] | 30 | #include "event.h" |
Jiri Olsa | 2709b97 | 2016-08-27 11:40:23 +0200 | [diff] [blame] | 31 | #include "evlist.h" |
| 32 | #include "evsel.h" |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 33 | #include "ui/browsers/hists.h" |
Arnaldo Carvalho de Melo | e7ff892 | 2017-04-19 21:34:35 -0300 | [diff] [blame] | 34 | #include "thread.h" |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 35 | |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 36 | struct c2c_hists { |
| 37 | struct hists hists; |
| 38 | struct perf_hpp_list list; |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 39 | struct c2c_stats stats; |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
Jiri Olsa | 92062d5 | 2016-06-05 13:40:53 +0200 | [diff] [blame] | 42 | struct compute_stats { |
| 43 | struct stats lcl_hitm; |
| 44 | struct stats rmt_hitm; |
| 45 | struct stats load; |
| 46 | }; |
| 47 | |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 48 | struct c2c_hist_entry { |
| 49 | struct c2c_hists *hists; |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 50 | struct c2c_stats stats; |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 51 | unsigned long *cpuset; |
| 52 | struct c2c_stats *node_stats; |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 53 | unsigned int cacheline_idx; |
Jiri Olsa | 92062d5 | 2016-06-05 13:40:53 +0200 | [diff] [blame] | 54 | |
| 55 | struct compute_stats cstats; |
| 56 | |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 57 | /* |
| 58 | * must be at the end, |
| 59 | * because of its callchain dynamic entry |
| 60 | */ |
| 61 | struct hist_entry he; |
| 62 | }; |
| 63 | |
Jiri Olsa | 190bacc | 2017-01-20 10:20:32 +0100 | [diff] [blame] | 64 | static char const *coalesce_default = "pid,iaddr"; |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 65 | |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 66 | struct perf_c2c { |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 67 | struct perf_tool tool; |
| 68 | struct c2c_hists hists; |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 69 | |
| 70 | unsigned long **nodes; |
| 71 | int nodes_cnt; |
| 72 | int cpus_cnt; |
| 73 | int *cpu2node; |
| 74 | int node_info; |
Jiri Olsa | 89d9ba8f | 2016-07-10 15:47:40 +0200 | [diff] [blame] | 75 | |
| 76 | bool show_src; |
Jiri Olsa | af09b2d | 2016-10-11 13:52:05 +0200 | [diff] [blame] | 77 | bool show_all; |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 78 | bool use_stdio; |
Jiri Olsa | 74c63a2 | 2016-05-02 20:01:59 +0200 | [diff] [blame] | 79 | bool stats_only; |
Jiri Olsa | 590b6a3 | 2016-07-10 16:25:15 +0200 | [diff] [blame] | 80 | bool symbol_full; |
Jiri Olsa | 7ef2efa | 2016-07-01 11:12:11 +0200 | [diff] [blame] | 81 | |
| 82 | /* HITM shared clines stats */ |
| 83 | struct c2c_stats hitm_stats; |
| 84 | int shared_clines; |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 85 | |
| 86 | int display; |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 87 | |
| 88 | const char *coalesce; |
| 89 | char *cl_sort; |
| 90 | char *cl_resort; |
| 91 | char *cl_output; |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | enum { |
| 95 | DISPLAY_LCL, |
| 96 | DISPLAY_RMT, |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 97 | DISPLAY_TOT, |
| 98 | DISPLAY_MAX, |
| 99 | }; |
| 100 | |
| 101 | static const char *display_str[DISPLAY_MAX] = { |
| 102 | [DISPLAY_LCL] = "Local", |
| 103 | [DISPLAY_RMT] = "Remote", |
| 104 | [DISPLAY_TOT] = "Total", |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 105 | }; |
| 106 | |
Jiri Olsa | 3a5bfab | 2016-11-21 22:33:31 +0100 | [diff] [blame] | 107 | static const struct option c2c_options[] = { |
| 108 | OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"), |
| 109 | OPT_END() |
| 110 | }; |
| 111 | |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 112 | static struct perf_c2c c2c; |
Jiri Olsa | 7aef3bf | 2016-09-22 17:36:38 +0200 | [diff] [blame] | 113 | |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 114 | static void *c2c_he_zalloc(size_t size) |
| 115 | { |
| 116 | struct c2c_hist_entry *c2c_he; |
| 117 | |
| 118 | c2c_he = zalloc(size + sizeof(*c2c_he)); |
| 119 | if (!c2c_he) |
| 120 | return NULL; |
| 121 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 122 | c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt); |
| 123 | if (!c2c_he->cpuset) |
| 124 | return NULL; |
| 125 | |
| 126 | c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats)); |
| 127 | if (!c2c_he->node_stats) |
| 128 | return NULL; |
| 129 | |
Jiri Olsa | 92062d5 | 2016-06-05 13:40:53 +0200 | [diff] [blame] | 130 | init_stats(&c2c_he->cstats.lcl_hitm); |
| 131 | init_stats(&c2c_he->cstats.rmt_hitm); |
| 132 | init_stats(&c2c_he->cstats.load); |
| 133 | |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 134 | return &c2c_he->he; |
| 135 | } |
| 136 | |
| 137 | static void c2c_he_free(void *he) |
| 138 | { |
| 139 | struct c2c_hist_entry *c2c_he; |
| 140 | |
| 141 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 142 | if (c2c_he->hists) { |
| 143 | hists__delete_entries(&c2c_he->hists->hists); |
| 144 | free(c2c_he->hists); |
| 145 | } |
| 146 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 147 | free(c2c_he->cpuset); |
| 148 | free(c2c_he->node_stats); |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 149 | free(c2c_he); |
| 150 | } |
| 151 | |
| 152 | static struct hist_entry_ops c2c_entry_ops = { |
| 153 | .new = c2c_he_zalloc, |
| 154 | .free = c2c_he_free, |
| 155 | }; |
| 156 | |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 157 | static int c2c_hists__init(struct c2c_hists *hists, |
Jiri Olsa | 1d62fcd | 2016-05-24 10:12:31 +0200 | [diff] [blame] | 158 | const char *sort, |
| 159 | int nr_header_lines); |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 160 | |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 161 | static struct c2c_hists* |
| 162 | he__get_c2c_hists(struct hist_entry *he, |
Jiri Olsa | 1d62fcd | 2016-05-24 10:12:31 +0200 | [diff] [blame] | 163 | const char *sort, |
| 164 | int nr_header_lines) |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 165 | { |
| 166 | struct c2c_hist_entry *c2c_he; |
| 167 | struct c2c_hists *hists; |
| 168 | int ret; |
| 169 | |
| 170 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 171 | if (c2c_he->hists) |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 172 | return c2c_he->hists; |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 173 | |
| 174 | hists = c2c_he->hists = zalloc(sizeof(*hists)); |
| 175 | if (!hists) |
| 176 | return NULL; |
| 177 | |
Jiri Olsa | 1d62fcd | 2016-05-24 10:12:31 +0200 | [diff] [blame] | 178 | ret = c2c_hists__init(hists, sort, nr_header_lines); |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 179 | if (ret) { |
| 180 | free(hists); |
| 181 | return NULL; |
| 182 | } |
| 183 | |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 184 | return hists; |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 187 | static void c2c_he__set_cpu(struct c2c_hist_entry *c2c_he, |
| 188 | struct perf_sample *sample) |
| 189 | { |
| 190 | if (WARN_ONCE(sample->cpu == (unsigned int) -1, |
| 191 | "WARNING: no sample cpu value")) |
| 192 | return; |
| 193 | |
| 194 | set_bit(sample->cpu, c2c_he->cpuset); |
| 195 | } |
| 196 | |
Jiri Olsa | 92062d5 | 2016-06-05 13:40:53 +0200 | [diff] [blame] | 197 | static void compute_stats(struct c2c_hist_entry *c2c_he, |
| 198 | struct c2c_stats *stats, |
| 199 | u64 weight) |
| 200 | { |
| 201 | struct compute_stats *cstats = &c2c_he->cstats; |
| 202 | |
| 203 | if (stats->rmt_hitm) |
| 204 | update_stats(&cstats->rmt_hitm, weight); |
| 205 | else if (stats->lcl_hitm) |
| 206 | update_stats(&cstats->lcl_hitm, weight); |
| 207 | else if (stats->load) |
| 208 | update_stats(&cstats->load, weight); |
| 209 | } |
| 210 | |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 211 | static int process_sample_event(struct perf_tool *tool __maybe_unused, |
| 212 | union perf_event *event, |
| 213 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 7e6a799 | 2016-12-12 10:52:10 -0300 | [diff] [blame] | 214 | struct perf_evsel *evsel, |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 215 | struct machine *machine) |
| 216 | { |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 217 | struct c2c_hists *c2c_hists = &c2c.hists; |
| 218 | struct c2c_hist_entry *c2c_he; |
| 219 | struct c2c_stats stats = { .nr_entries = 0, }; |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 220 | struct hist_entry *he; |
| 221 | struct addr_location al; |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 222 | struct mem_info *mi, *mi_dup; |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 223 | int ret; |
| 224 | |
| 225 | if (machine__resolve(machine, &al, sample) < 0) { |
| 226 | pr_debug("problem processing %d event, skipping it.\n", |
| 227 | event->header.type); |
| 228 | return -1; |
| 229 | } |
| 230 | |
Jiri Olsa | dd80576 | 2016-05-11 18:23:48 +0200 | [diff] [blame] | 231 | ret = sample__resolve_callchain(sample, &callchain_cursor, NULL, |
| 232 | evsel, &al, sysctl_perf_event_max_stack); |
| 233 | if (ret) |
| 234 | goto out; |
| 235 | |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 236 | mi = sample__resolve_mem(sample, &al); |
| 237 | if (mi == NULL) |
| 238 | return -ENOMEM; |
| 239 | |
Jiri Olsa | 5cedb41 | 2018-03-07 16:50:07 +0100 | [diff] [blame] | 240 | /* |
| 241 | * The mi object is released in hists__add_entry_ops, |
| 242 | * if it gets sorted out into existing data, so we need |
| 243 | * to take the copy now. |
| 244 | */ |
| 245 | mi_dup = mem_info__get(mi); |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 246 | |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 247 | c2c_decode_stats(&stats, mi); |
| 248 | |
| 249 | he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 250 | &al, NULL, NULL, mi, |
| 251 | sample, true); |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 252 | if (he == NULL) |
Jiri Olsa | 5cedb41 | 2018-03-07 16:50:07 +0100 | [diff] [blame] | 253 | goto free_mi; |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 254 | |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 255 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 256 | c2c_add_stats(&c2c_he->stats, &stats); |
| 257 | c2c_add_stats(&c2c_hists->stats, &stats); |
| 258 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 259 | c2c_he__set_cpu(c2c_he, sample); |
| 260 | |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 261 | hists__inc_nr_samples(&c2c_hists->hists, he->filtered); |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 262 | ret = hist_entry__append_callchain(he, sample); |
| 263 | |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 264 | if (!ret) { |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 265 | /* |
| 266 | * There's already been warning about missing |
| 267 | * sample's cpu value. Let's account all to |
| 268 | * node 0 in this case, without any further |
| 269 | * warning. |
| 270 | * |
| 271 | * Doing node stats only for single callchain data. |
| 272 | */ |
| 273 | int cpu = sample->cpu == (unsigned int) -1 ? 0 : sample->cpu; |
| 274 | int node = c2c.cpu2node[cpu]; |
| 275 | |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 276 | mi = mi_dup; |
| 277 | |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 278 | c2c_hists = he__get_c2c_hists(he, c2c.cl_sort, 2); |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 279 | if (!c2c_hists) |
Jiri Olsa | 5cedb41 | 2018-03-07 16:50:07 +0100 | [diff] [blame] | 280 | goto free_mi; |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 281 | |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 282 | he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 283 | &al, NULL, NULL, mi, |
| 284 | sample, true); |
| 285 | if (he == NULL) |
Jiri Olsa | 5cedb41 | 2018-03-07 16:50:07 +0100 | [diff] [blame] | 286 | goto free_mi; |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 287 | |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 288 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 289 | c2c_add_stats(&c2c_he->stats, &stats); |
| 290 | c2c_add_stats(&c2c_hists->stats, &stats); |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 291 | c2c_add_stats(&c2c_he->node_stats[node], &stats); |
| 292 | |
Jiri Olsa | 92062d5 | 2016-06-05 13:40:53 +0200 | [diff] [blame] | 293 | compute_stats(c2c_he, &stats, sample->weight); |
| 294 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 295 | c2c_he__set_cpu(c2c_he, sample); |
Jiri Olsa | b2252ae | 2016-09-22 17:36:46 +0200 | [diff] [blame] | 296 | |
| 297 | hists__inc_nr_samples(&c2c_hists->hists, he->filtered); |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 298 | ret = hist_entry__append_callchain(he, sample); |
| 299 | } |
| 300 | |
| 301 | out: |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 302 | addr_location__put(&al); |
| 303 | return ret; |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 304 | |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 305 | free_mi: |
Jiri Olsa | 5cedb41 | 2018-03-07 16:50:07 +0100 | [diff] [blame] | 306 | mem_info__put(mi_dup); |
| 307 | mem_info__put(mi); |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 308 | ret = -ENOMEM; |
| 309 | goto out; |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static struct perf_c2c c2c = { |
| 313 | .tool = { |
| 314 | .sample = process_sample_event, |
| 315 | .mmap = perf_event__process_mmap, |
| 316 | .mmap2 = perf_event__process_mmap2, |
| 317 | .comm = perf_event__process_comm, |
| 318 | .exit = perf_event__process_exit, |
| 319 | .fork = perf_event__process_fork, |
| 320 | .lost = perf_event__process_lost, |
| 321 | .ordered_events = true, |
| 322 | .ordering_requires_timestamps = true, |
| 323 | }, |
| 324 | }; |
| 325 | |
Jiri Olsa | 7aef3bf | 2016-09-22 17:36:38 +0200 | [diff] [blame] | 326 | static const char * const c2c_usage[] = { |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 327 | "perf c2c {record|report}", |
Jiri Olsa | 7aef3bf | 2016-09-22 17:36:38 +0200 | [diff] [blame] | 328 | NULL |
| 329 | }; |
| 330 | |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 331 | static const char * const __usage_report[] = { |
| 332 | "perf c2c report", |
| 333 | NULL |
| 334 | }; |
| 335 | |
| 336 | static const char * const *report_c2c_usage = __usage_report; |
| 337 | |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 338 | #define C2C_HEADER_MAX 2 |
| 339 | |
| 340 | struct c2c_header { |
| 341 | struct { |
| 342 | const char *text; |
| 343 | int span; |
| 344 | } line[C2C_HEADER_MAX]; |
| 345 | }; |
| 346 | |
| 347 | struct c2c_dimension { |
| 348 | struct c2c_header header; |
| 349 | const char *name; |
| 350 | int width; |
Jiri Olsa | 8d3f938 | 2016-09-22 17:36:42 +0200 | [diff] [blame] | 351 | struct sort_entry *se; |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 352 | |
| 353 | int64_t (*cmp)(struct perf_hpp_fmt *fmt, |
| 354 | struct hist_entry *, struct hist_entry *); |
| 355 | int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 356 | struct hist_entry *he); |
| 357 | int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 358 | struct hist_entry *he); |
| 359 | }; |
| 360 | |
| 361 | struct c2c_fmt { |
| 362 | struct perf_hpp_fmt fmt; |
| 363 | struct c2c_dimension *dim; |
| 364 | }; |
| 365 | |
Jiri Olsa | 590b6a3 | 2016-07-10 16:25:15 +0200 | [diff] [blame] | 366 | #define SYMBOL_WIDTH 30 |
| 367 | |
| 368 | static struct c2c_dimension dim_symbol; |
| 369 | static struct c2c_dimension dim_srcline; |
| 370 | |
| 371 | static int symbol_width(struct hists *hists, struct sort_entry *se) |
| 372 | { |
| 373 | int width = hists__col_len(hists, se->se_width_idx); |
| 374 | |
| 375 | if (!c2c.symbol_full) |
| 376 | width = MIN(width, SYMBOL_WIDTH); |
| 377 | |
| 378 | return width; |
| 379 | } |
| 380 | |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 381 | static int c2c_width(struct perf_hpp_fmt *fmt, |
| 382 | struct perf_hpp *hpp __maybe_unused, |
Arnaldo Carvalho de Melo | 7e6a799 | 2016-12-12 10:52:10 -0300 | [diff] [blame] | 383 | struct hists *hists) |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 384 | { |
| 385 | struct c2c_fmt *c2c_fmt; |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 386 | struct c2c_dimension *dim; |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 387 | |
| 388 | c2c_fmt = container_of(fmt, struct c2c_fmt, fmt); |
| 389 | dim = c2c_fmt->dim; |
| 390 | |
Jiri Olsa | 590b6a3 | 2016-07-10 16:25:15 +0200 | [diff] [blame] | 391 | if (dim == &dim_symbol || dim == &dim_srcline) |
| 392 | return symbol_width(hists, dim->se); |
| 393 | |
Jiri Olsa | 8d3f938 | 2016-09-22 17:36:42 +0200 | [diff] [blame] | 394 | return dim->se ? hists__col_len(hists, dim->se->se_width_idx) : |
| 395 | c2c_fmt->dim->width; |
| 396 | } |
| 397 | |
| 398 | static int c2c_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 399 | struct hists *hists, int line, int *span) |
| 400 | { |
| 401 | struct perf_hpp_list *hpp_list = hists->hpp_list; |
| 402 | struct c2c_fmt *c2c_fmt; |
| 403 | struct c2c_dimension *dim; |
| 404 | const char *text = NULL; |
| 405 | int width = c2c_width(fmt, hpp, hists); |
| 406 | |
| 407 | c2c_fmt = container_of(fmt, struct c2c_fmt, fmt); |
| 408 | dim = c2c_fmt->dim; |
| 409 | |
| 410 | if (dim->se) { |
| 411 | text = dim->header.line[line].text; |
| 412 | /* Use the last line from sort_entry if not defined. */ |
| 413 | if (!text && (line == hpp_list->nr_header_lines - 1)) |
| 414 | text = dim->se->se_header; |
| 415 | } else { |
| 416 | text = dim->header.line[line].text; |
| 417 | |
| 418 | if (*span) { |
| 419 | (*span)--; |
| 420 | return 0; |
| 421 | } else { |
| 422 | *span = dim->header.line[line].span; |
| 423 | } |
| 424 | } |
| 425 | |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 426 | if (text == NULL) |
| 427 | text = ""; |
| 428 | |
Jiri Olsa | 8d3f938 | 2016-09-22 17:36:42 +0200 | [diff] [blame] | 429 | return scnprintf(hpp->buf, hpp->size, "%*s", width, text); |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Jiri Olsa | cbb8850 | 2016-09-22 17:36:48 +0200 | [diff] [blame] | 432 | #define HEX_STR(__s, __v) \ |
| 433 | ({ \ |
| 434 | scnprintf(__s, sizeof(__s), "0x%" PRIx64, __v); \ |
| 435 | __s; \ |
| 436 | }) |
| 437 | |
| 438 | static int64_t |
| 439 | dcacheline_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 440 | struct hist_entry *left, struct hist_entry *right) |
| 441 | { |
| 442 | return sort__dcacheline_cmp(left, right); |
| 443 | } |
| 444 | |
| 445 | static int dcacheline_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 446 | struct hist_entry *he) |
| 447 | { |
| 448 | uint64_t addr = 0; |
| 449 | int width = c2c_width(fmt, hpp, he->hists); |
| 450 | char buf[20]; |
| 451 | |
| 452 | if (he->mem_info) |
| 453 | addr = cl_address(he->mem_info->daddr.addr); |
| 454 | |
| 455 | return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr)); |
| 456 | } |
| 457 | |
Jiri Olsa | 48acdeb | 2016-04-29 14:37:06 +0200 | [diff] [blame] | 458 | static int offset_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 459 | struct hist_entry *he) |
| 460 | { |
| 461 | uint64_t addr = 0; |
| 462 | int width = c2c_width(fmt, hpp, he->hists); |
| 463 | char buf[20]; |
| 464 | |
| 465 | if (he->mem_info) |
| 466 | addr = cl_offset(he->mem_info->daddr.al_addr); |
| 467 | |
| 468 | return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr)); |
| 469 | } |
| 470 | |
| 471 | static int64_t |
| 472 | offset_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 473 | struct hist_entry *left, struct hist_entry *right) |
| 474 | { |
| 475 | uint64_t l = 0, r = 0; |
| 476 | |
| 477 | if (left->mem_info) |
| 478 | l = cl_offset(left->mem_info->daddr.addr); |
| 479 | if (right->mem_info) |
| 480 | r = cl_offset(right->mem_info->daddr.addr); |
| 481 | |
| 482 | return (int64_t)(r - l); |
| 483 | } |
| 484 | |
Jiri Olsa | 43575a9 | 2016-05-03 21:48:56 +0200 | [diff] [blame] | 485 | static int |
| 486 | iaddr_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 487 | struct hist_entry *he) |
| 488 | { |
| 489 | uint64_t addr = 0; |
| 490 | int width = c2c_width(fmt, hpp, he->hists); |
| 491 | char buf[20]; |
| 492 | |
| 493 | if (he->mem_info) |
| 494 | addr = he->mem_info->iaddr.addr; |
| 495 | |
| 496 | return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr)); |
| 497 | } |
| 498 | |
| 499 | static int64_t |
| 500 | iaddr_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 501 | struct hist_entry *left, struct hist_entry *right) |
| 502 | { |
| 503 | return sort__iaddr_cmp(left, right); |
| 504 | } |
| 505 | |
Jiri Olsa | 97cb486 | 2016-05-23 16:20:14 +0200 | [diff] [blame] | 506 | static int |
| 507 | tot_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 508 | struct hist_entry *he) |
| 509 | { |
| 510 | struct c2c_hist_entry *c2c_he; |
| 511 | int width = c2c_width(fmt, hpp, he->hists); |
| 512 | unsigned int tot_hitm; |
| 513 | |
| 514 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 515 | tot_hitm = c2c_he->stats.lcl_hitm + c2c_he->stats.rmt_hitm; |
| 516 | |
| 517 | return scnprintf(hpp->buf, hpp->size, "%*u", width, tot_hitm); |
| 518 | } |
| 519 | |
| 520 | static int64_t |
| 521 | tot_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 522 | struct hist_entry *left, struct hist_entry *right) |
| 523 | { |
| 524 | struct c2c_hist_entry *c2c_left; |
| 525 | struct c2c_hist_entry *c2c_right; |
| 526 | unsigned int tot_hitm_left; |
| 527 | unsigned int tot_hitm_right; |
| 528 | |
| 529 | c2c_left = container_of(left, struct c2c_hist_entry, he); |
| 530 | c2c_right = container_of(right, struct c2c_hist_entry, he); |
| 531 | |
| 532 | tot_hitm_left = c2c_left->stats.lcl_hitm + c2c_left->stats.rmt_hitm; |
| 533 | tot_hitm_right = c2c_right->stats.lcl_hitm + c2c_right->stats.rmt_hitm; |
| 534 | |
| 535 | return tot_hitm_left - tot_hitm_right; |
| 536 | } |
| 537 | |
| 538 | #define STAT_FN_ENTRY(__f) \ |
| 539 | static int \ |
| 540 | __f ## _entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, \ |
| 541 | struct hist_entry *he) \ |
| 542 | { \ |
| 543 | struct c2c_hist_entry *c2c_he; \ |
| 544 | int width = c2c_width(fmt, hpp, he->hists); \ |
| 545 | \ |
| 546 | c2c_he = container_of(he, struct c2c_hist_entry, he); \ |
| 547 | return scnprintf(hpp->buf, hpp->size, "%*u", width, \ |
| 548 | c2c_he->stats.__f); \ |
| 549 | } |
| 550 | |
| 551 | #define STAT_FN_CMP(__f) \ |
| 552 | static int64_t \ |
| 553 | __f ## _cmp(struct perf_hpp_fmt *fmt __maybe_unused, \ |
| 554 | struct hist_entry *left, struct hist_entry *right) \ |
| 555 | { \ |
| 556 | struct c2c_hist_entry *c2c_left, *c2c_right; \ |
| 557 | \ |
| 558 | c2c_left = container_of(left, struct c2c_hist_entry, he); \ |
| 559 | c2c_right = container_of(right, struct c2c_hist_entry, he); \ |
| 560 | return c2c_left->stats.__f - c2c_right->stats.__f; \ |
| 561 | } |
| 562 | |
| 563 | #define STAT_FN(__f) \ |
| 564 | STAT_FN_ENTRY(__f) \ |
| 565 | STAT_FN_CMP(__f) |
| 566 | |
| 567 | STAT_FN(rmt_hitm) |
| 568 | STAT_FN(lcl_hitm) |
Jiri Olsa | 0f18896 | 2016-05-04 10:10:11 +0200 | [diff] [blame] | 569 | STAT_FN(store) |
| 570 | STAT_FN(st_l1hit) |
| 571 | STAT_FN(st_l1miss) |
Jiri Olsa | 1295f68 | 2016-05-04 10:18:24 +0200 | [diff] [blame] | 572 | STAT_FN(ld_fbhit) |
| 573 | STAT_FN(ld_l1hit) |
| 574 | STAT_FN(ld_l2hit) |
Jiri Olsa | 4d08910 | 2016-05-04 10:27:51 +0200 | [diff] [blame] | 575 | STAT_FN(ld_llchit) |
| 576 | STAT_FN(rmt_hit) |
Jiri Olsa | 97cb486 | 2016-05-23 16:20:14 +0200 | [diff] [blame] | 577 | |
Jiri Olsa | 04402d2 | 2016-05-19 10:10:51 +0200 | [diff] [blame] | 578 | static uint64_t llc_miss(struct c2c_stats *stats) |
| 579 | { |
| 580 | uint64_t llcmiss; |
| 581 | |
| 582 | llcmiss = stats->lcl_dram + |
| 583 | stats->rmt_dram + |
| 584 | stats->rmt_hitm + |
| 585 | stats->rmt_hit; |
| 586 | |
| 587 | return llcmiss; |
| 588 | } |
| 589 | |
| 590 | static int |
| 591 | ld_llcmiss_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 592 | struct hist_entry *he) |
| 593 | { |
| 594 | struct c2c_hist_entry *c2c_he; |
| 595 | int width = c2c_width(fmt, hpp, he->hists); |
| 596 | |
| 597 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 598 | |
| 599 | return scnprintf(hpp->buf, hpp->size, "%*lu", width, |
| 600 | llc_miss(&c2c_he->stats)); |
| 601 | } |
| 602 | |
| 603 | static int64_t |
| 604 | ld_llcmiss_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 605 | struct hist_entry *left, struct hist_entry *right) |
| 606 | { |
| 607 | struct c2c_hist_entry *c2c_left; |
| 608 | struct c2c_hist_entry *c2c_right; |
| 609 | |
| 610 | c2c_left = container_of(left, struct c2c_hist_entry, he); |
| 611 | c2c_right = container_of(right, struct c2c_hist_entry, he); |
| 612 | |
| 613 | return llc_miss(&c2c_left->stats) - llc_miss(&c2c_right->stats); |
| 614 | } |
| 615 | |
Jiri Olsa | 01b84d7 | 2016-05-04 10:35:29 +0200 | [diff] [blame] | 616 | static uint64_t total_records(struct c2c_stats *stats) |
| 617 | { |
| 618 | uint64_t lclmiss, ldcnt, total; |
| 619 | |
| 620 | lclmiss = stats->lcl_dram + |
| 621 | stats->rmt_dram + |
| 622 | stats->rmt_hitm + |
| 623 | stats->rmt_hit; |
| 624 | |
| 625 | ldcnt = lclmiss + |
| 626 | stats->ld_fbhit + |
| 627 | stats->ld_l1hit + |
| 628 | stats->ld_l2hit + |
| 629 | stats->ld_llchit + |
| 630 | stats->lcl_hitm; |
| 631 | |
| 632 | total = ldcnt + |
| 633 | stats->st_l1hit + |
| 634 | stats->st_l1miss; |
| 635 | |
| 636 | return total; |
| 637 | } |
| 638 | |
| 639 | static int |
| 640 | tot_recs_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 641 | struct hist_entry *he) |
| 642 | { |
| 643 | struct c2c_hist_entry *c2c_he; |
| 644 | int width = c2c_width(fmt, hpp, he->hists); |
| 645 | uint64_t tot_recs; |
| 646 | |
| 647 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 648 | tot_recs = total_records(&c2c_he->stats); |
| 649 | |
| 650 | return scnprintf(hpp->buf, hpp->size, "%*" PRIu64, width, tot_recs); |
| 651 | } |
| 652 | |
| 653 | static int64_t |
| 654 | tot_recs_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 655 | struct hist_entry *left, struct hist_entry *right) |
| 656 | { |
| 657 | struct c2c_hist_entry *c2c_left; |
| 658 | struct c2c_hist_entry *c2c_right; |
| 659 | uint64_t tot_recs_left; |
| 660 | uint64_t tot_recs_right; |
| 661 | |
| 662 | c2c_left = container_of(left, struct c2c_hist_entry, he); |
| 663 | c2c_right = container_of(right, struct c2c_hist_entry, he); |
| 664 | |
| 665 | tot_recs_left = total_records(&c2c_left->stats); |
| 666 | tot_recs_right = total_records(&c2c_right->stats); |
| 667 | |
| 668 | return tot_recs_left - tot_recs_right; |
| 669 | } |
| 670 | |
Jiri Olsa | 55177c4 | 2016-05-19 09:52:37 +0200 | [diff] [blame] | 671 | static uint64_t total_loads(struct c2c_stats *stats) |
| 672 | { |
| 673 | uint64_t lclmiss, ldcnt; |
| 674 | |
| 675 | lclmiss = stats->lcl_dram + |
| 676 | stats->rmt_dram + |
| 677 | stats->rmt_hitm + |
| 678 | stats->rmt_hit; |
| 679 | |
| 680 | ldcnt = lclmiss + |
| 681 | stats->ld_fbhit + |
| 682 | stats->ld_l1hit + |
| 683 | stats->ld_l2hit + |
| 684 | stats->ld_llchit + |
| 685 | stats->lcl_hitm; |
| 686 | |
| 687 | return ldcnt; |
| 688 | } |
| 689 | |
| 690 | static int |
| 691 | tot_loads_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 692 | struct hist_entry *he) |
| 693 | { |
| 694 | struct c2c_hist_entry *c2c_he; |
| 695 | int width = c2c_width(fmt, hpp, he->hists); |
| 696 | uint64_t tot_recs; |
| 697 | |
| 698 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 699 | tot_recs = total_loads(&c2c_he->stats); |
| 700 | |
| 701 | return scnprintf(hpp->buf, hpp->size, "%*" PRIu64, width, tot_recs); |
| 702 | } |
| 703 | |
| 704 | static int64_t |
| 705 | tot_loads_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 706 | struct hist_entry *left, struct hist_entry *right) |
| 707 | { |
| 708 | struct c2c_hist_entry *c2c_left; |
| 709 | struct c2c_hist_entry *c2c_right; |
| 710 | uint64_t tot_recs_left; |
| 711 | uint64_t tot_recs_right; |
| 712 | |
| 713 | c2c_left = container_of(left, struct c2c_hist_entry, he); |
| 714 | c2c_right = container_of(right, struct c2c_hist_entry, he); |
| 715 | |
| 716 | tot_recs_left = total_loads(&c2c_left->stats); |
| 717 | tot_recs_right = total_loads(&c2c_right->stats); |
| 718 | |
| 719 | return tot_recs_left - tot_recs_right; |
| 720 | } |
| 721 | |
Jiri Olsa | f0c50c1 | 2016-05-04 10:50:09 +0200 | [diff] [blame] | 722 | typedef double (get_percent_cb)(struct c2c_hist_entry *); |
| 723 | |
| 724 | static int |
| 725 | percent_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 726 | struct hist_entry *he, get_percent_cb get_percent) |
| 727 | { |
| 728 | struct c2c_hist_entry *c2c_he; |
| 729 | int width = c2c_width(fmt, hpp, he->hists); |
| 730 | double per; |
| 731 | |
| 732 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 733 | per = get_percent(c2c_he); |
| 734 | |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 735 | #ifdef HAVE_SLANG_SUPPORT |
| 736 | if (use_browser) |
| 737 | return __hpp__slsmg_color_printf(hpp, "%*.2f%%", width - 1, per); |
| 738 | #endif |
Jiri Olsa | f0c50c1 | 2016-05-04 10:50:09 +0200 | [diff] [blame] | 739 | return hpp_color_scnprintf(hpp, "%*.2f%%", width - 1, per); |
| 740 | } |
| 741 | |
| 742 | static double percent_hitm(struct c2c_hist_entry *c2c_he) |
| 743 | { |
| 744 | struct c2c_hists *hists; |
| 745 | struct c2c_stats *stats; |
| 746 | struct c2c_stats *total; |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 747 | int tot = 0, st = 0; |
Jiri Olsa | f0c50c1 | 2016-05-04 10:50:09 +0200 | [diff] [blame] | 748 | double p; |
| 749 | |
| 750 | hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); |
| 751 | stats = &c2c_he->stats; |
| 752 | total = &hists->stats; |
| 753 | |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 754 | switch (c2c.display) { |
| 755 | case DISPLAY_RMT: |
| 756 | st = stats->rmt_hitm; |
| 757 | tot = total->rmt_hitm; |
| 758 | break; |
| 759 | case DISPLAY_LCL: |
| 760 | st = stats->lcl_hitm; |
| 761 | tot = total->lcl_hitm; |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 762 | break; |
| 763 | case DISPLAY_TOT: |
| 764 | st = stats->tot_hitm; |
| 765 | tot = total->tot_hitm; |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 766 | default: |
| 767 | break; |
| 768 | } |
Jiri Olsa | f0c50c1 | 2016-05-04 10:50:09 +0200 | [diff] [blame] | 769 | |
| 770 | p = tot ? (double) st / tot : 0; |
| 771 | |
| 772 | return 100 * p; |
| 773 | } |
| 774 | |
| 775 | #define PERC_STR(__s, __v) \ |
| 776 | ({ \ |
| 777 | scnprintf(__s, sizeof(__s), "%.2F%%", __v); \ |
| 778 | __s; \ |
| 779 | }) |
| 780 | |
| 781 | static int |
| 782 | percent_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 783 | struct hist_entry *he) |
| 784 | { |
| 785 | struct c2c_hist_entry *c2c_he; |
| 786 | int width = c2c_width(fmt, hpp, he->hists); |
| 787 | char buf[10]; |
| 788 | double per; |
| 789 | |
| 790 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 791 | per = percent_hitm(c2c_he); |
| 792 | return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); |
| 793 | } |
| 794 | |
| 795 | static int |
| 796 | percent_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 797 | struct hist_entry *he) |
| 798 | { |
| 799 | return percent_color(fmt, hpp, he, percent_hitm); |
| 800 | } |
| 801 | |
| 802 | static int64_t |
| 803 | percent_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 804 | struct hist_entry *left, struct hist_entry *right) |
| 805 | { |
| 806 | struct c2c_hist_entry *c2c_left; |
| 807 | struct c2c_hist_entry *c2c_right; |
| 808 | double per_left; |
| 809 | double per_right; |
| 810 | |
| 811 | c2c_left = container_of(left, struct c2c_hist_entry, he); |
| 812 | c2c_right = container_of(right, struct c2c_hist_entry, he); |
| 813 | |
| 814 | per_left = percent_hitm(c2c_left); |
| 815 | per_right = percent_hitm(c2c_right); |
| 816 | |
| 817 | return per_left - per_right; |
| 818 | } |
| 819 | |
Jiri Olsa | 9cb3500 | 2016-05-04 12:16:50 +0200 | [diff] [blame] | 820 | static struct c2c_stats *he_stats(struct hist_entry *he) |
| 821 | { |
| 822 | struct c2c_hist_entry *c2c_he; |
| 823 | |
| 824 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 825 | return &c2c_he->stats; |
| 826 | } |
| 827 | |
| 828 | static struct c2c_stats *total_stats(struct hist_entry *he) |
| 829 | { |
| 830 | struct c2c_hists *hists; |
| 831 | |
| 832 | hists = container_of(he->hists, struct c2c_hists, hists); |
| 833 | return &hists->stats; |
| 834 | } |
| 835 | |
| 836 | static double percent(int st, int tot) |
| 837 | { |
| 838 | return tot ? 100. * (double) st / (double) tot : 0; |
| 839 | } |
| 840 | |
| 841 | #define PERCENT(__h, __f) percent(he_stats(__h)->__f, total_stats(__h)->__f) |
| 842 | |
| 843 | #define PERCENT_FN(__f) \ |
| 844 | static double percent_ ## __f(struct c2c_hist_entry *c2c_he) \ |
| 845 | { \ |
| 846 | struct c2c_hists *hists; \ |
| 847 | \ |
| 848 | hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); \ |
| 849 | return percent(c2c_he->stats.__f, hists->stats.__f); \ |
| 850 | } |
| 851 | |
| 852 | PERCENT_FN(rmt_hitm) |
| 853 | PERCENT_FN(lcl_hitm) |
| 854 | PERCENT_FN(st_l1hit) |
| 855 | PERCENT_FN(st_l1miss) |
| 856 | |
| 857 | static int |
| 858 | percent_rmt_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 859 | struct hist_entry *he) |
| 860 | { |
| 861 | int width = c2c_width(fmt, hpp, he->hists); |
| 862 | double per = PERCENT(he, rmt_hitm); |
| 863 | char buf[10]; |
| 864 | |
| 865 | return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); |
| 866 | } |
| 867 | |
| 868 | static int |
| 869 | percent_rmt_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 870 | struct hist_entry *he) |
| 871 | { |
| 872 | return percent_color(fmt, hpp, he, percent_rmt_hitm); |
| 873 | } |
| 874 | |
| 875 | static int64_t |
| 876 | percent_rmt_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 877 | struct hist_entry *left, struct hist_entry *right) |
| 878 | { |
| 879 | double per_left; |
| 880 | double per_right; |
| 881 | |
| 882 | per_left = PERCENT(left, lcl_hitm); |
| 883 | per_right = PERCENT(right, lcl_hitm); |
| 884 | |
| 885 | return per_left - per_right; |
| 886 | } |
| 887 | |
| 888 | static int |
| 889 | percent_lcl_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 890 | struct hist_entry *he) |
| 891 | { |
| 892 | int width = c2c_width(fmt, hpp, he->hists); |
| 893 | double per = PERCENT(he, lcl_hitm); |
| 894 | char buf[10]; |
| 895 | |
| 896 | return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); |
| 897 | } |
| 898 | |
| 899 | static int |
| 900 | percent_lcl_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 901 | struct hist_entry *he) |
| 902 | { |
| 903 | return percent_color(fmt, hpp, he, percent_lcl_hitm); |
| 904 | } |
| 905 | |
| 906 | static int64_t |
| 907 | percent_lcl_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 908 | struct hist_entry *left, struct hist_entry *right) |
| 909 | { |
| 910 | double per_left; |
| 911 | double per_right; |
| 912 | |
| 913 | per_left = PERCENT(left, lcl_hitm); |
| 914 | per_right = PERCENT(right, lcl_hitm); |
| 915 | |
| 916 | return per_left - per_right; |
| 917 | } |
| 918 | |
| 919 | static int |
| 920 | percent_stores_l1hit_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 921 | struct hist_entry *he) |
| 922 | { |
| 923 | int width = c2c_width(fmt, hpp, he->hists); |
| 924 | double per = PERCENT(he, st_l1hit); |
| 925 | char buf[10]; |
| 926 | |
| 927 | return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); |
| 928 | } |
| 929 | |
| 930 | static int |
| 931 | percent_stores_l1hit_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 932 | struct hist_entry *he) |
| 933 | { |
| 934 | return percent_color(fmt, hpp, he, percent_st_l1hit); |
| 935 | } |
| 936 | |
| 937 | static int64_t |
| 938 | percent_stores_l1hit_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 939 | struct hist_entry *left, struct hist_entry *right) |
| 940 | { |
| 941 | double per_left; |
| 942 | double per_right; |
| 943 | |
| 944 | per_left = PERCENT(left, st_l1hit); |
| 945 | per_right = PERCENT(right, st_l1hit); |
| 946 | |
| 947 | return per_left - per_right; |
| 948 | } |
| 949 | |
| 950 | static int |
| 951 | percent_stores_l1miss_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 952 | struct hist_entry *he) |
| 953 | { |
| 954 | int width = c2c_width(fmt, hpp, he->hists); |
| 955 | double per = PERCENT(he, st_l1miss); |
| 956 | char buf[10]; |
| 957 | |
| 958 | return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); |
| 959 | } |
| 960 | |
| 961 | static int |
| 962 | percent_stores_l1miss_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 963 | struct hist_entry *he) |
| 964 | { |
| 965 | return percent_color(fmt, hpp, he, percent_st_l1miss); |
| 966 | } |
| 967 | |
| 968 | static int64_t |
| 969 | percent_stores_l1miss_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 970 | struct hist_entry *left, struct hist_entry *right) |
| 971 | { |
| 972 | double per_left; |
| 973 | double per_right; |
| 974 | |
| 975 | per_left = PERCENT(left, st_l1miss); |
| 976 | per_right = PERCENT(right, st_l1miss); |
| 977 | |
| 978 | return per_left - per_right; |
| 979 | } |
| 980 | |
Jiri Olsa | 6c70f54 | 2016-05-28 12:30:13 +0200 | [diff] [blame] | 981 | STAT_FN(lcl_dram) |
| 982 | STAT_FN(rmt_dram) |
| 983 | |
Jiri Olsa | 36d3deb | 2016-05-24 13:09:47 +0200 | [diff] [blame] | 984 | static int |
| 985 | pid_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 986 | struct hist_entry *he) |
| 987 | { |
| 988 | int width = c2c_width(fmt, hpp, he->hists); |
| 989 | |
| 990 | return scnprintf(hpp->buf, hpp->size, "%*d", width, he->thread->pid_); |
| 991 | } |
| 992 | |
| 993 | static int64_t |
| 994 | pid_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 995 | struct hist_entry *left, struct hist_entry *right) |
| 996 | { |
| 997 | return left->thread->pid_ - right->thread->pid_; |
| 998 | } |
| 999 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 1000 | static int64_t |
| 1001 | empty_cmp(struct perf_hpp_fmt *fmt __maybe_unused, |
| 1002 | struct hist_entry *left __maybe_unused, |
| 1003 | struct hist_entry *right __maybe_unused) |
| 1004 | { |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
| 1008 | static int |
| 1009 | node_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp, |
| 1010 | struct hist_entry *he) |
| 1011 | { |
| 1012 | struct c2c_hist_entry *c2c_he; |
| 1013 | bool first = true; |
| 1014 | int node; |
| 1015 | int ret = 0; |
| 1016 | |
| 1017 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 1018 | |
| 1019 | for (node = 0; node < c2c.nodes_cnt; node++) { |
| 1020 | DECLARE_BITMAP(set, c2c.cpus_cnt); |
| 1021 | |
| 1022 | bitmap_zero(set, c2c.cpus_cnt); |
| 1023 | bitmap_and(set, c2c_he->cpuset, c2c.nodes[node], c2c.cpus_cnt); |
| 1024 | |
| 1025 | if (!bitmap_weight(set, c2c.cpus_cnt)) { |
| 1026 | if (c2c.node_info == 1) { |
| 1027 | ret = scnprintf(hpp->buf, hpp->size, "%21s", " "); |
| 1028 | advance_hpp(hpp, ret); |
| 1029 | } |
| 1030 | continue; |
| 1031 | } |
| 1032 | |
| 1033 | if (!first) { |
| 1034 | ret = scnprintf(hpp->buf, hpp->size, " "); |
| 1035 | advance_hpp(hpp, ret); |
| 1036 | } |
| 1037 | |
| 1038 | switch (c2c.node_info) { |
| 1039 | case 0: |
| 1040 | ret = scnprintf(hpp->buf, hpp->size, "%2d", node); |
| 1041 | advance_hpp(hpp, ret); |
| 1042 | break; |
| 1043 | case 1: |
| 1044 | { |
| 1045 | int num = bitmap_weight(c2c_he->cpuset, c2c.cpus_cnt); |
| 1046 | struct c2c_stats *stats = &c2c_he->node_stats[node]; |
| 1047 | |
| 1048 | ret = scnprintf(hpp->buf, hpp->size, "%2d{%2d ", node, num); |
| 1049 | advance_hpp(hpp, ret); |
| 1050 | |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1051 | #define DISPLAY_HITM(__h) \ |
| 1052 | if (c2c_he->stats.__h> 0) { \ |
| 1053 | ret = scnprintf(hpp->buf, hpp->size, "%5.1f%% ", \ |
| 1054 | percent(stats->__h, c2c_he->stats.__h));\ |
| 1055 | } else { \ |
| 1056 | ret = scnprintf(hpp->buf, hpp->size, "%6s ", "n/a"); \ |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 1057 | } |
| 1058 | |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1059 | switch (c2c.display) { |
| 1060 | case DISPLAY_RMT: |
| 1061 | DISPLAY_HITM(rmt_hitm); |
| 1062 | break; |
| 1063 | case DISPLAY_LCL: |
| 1064 | DISPLAY_HITM(lcl_hitm); |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 1065 | break; |
| 1066 | case DISPLAY_TOT: |
| 1067 | DISPLAY_HITM(tot_hitm); |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1068 | default: |
| 1069 | break; |
| 1070 | } |
| 1071 | |
| 1072 | #undef DISPLAY_HITM |
| 1073 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 1074 | advance_hpp(hpp, ret); |
| 1075 | |
| 1076 | if (c2c_he->stats.store > 0) { |
| 1077 | ret = scnprintf(hpp->buf, hpp->size, "%5.1f%%}", |
| 1078 | percent(stats->store, c2c_he->stats.store)); |
| 1079 | } else { |
| 1080 | ret = scnprintf(hpp->buf, hpp->size, "%6s}", "n/a"); |
| 1081 | } |
| 1082 | |
| 1083 | advance_hpp(hpp, ret); |
| 1084 | break; |
| 1085 | } |
| 1086 | case 2: |
| 1087 | ret = scnprintf(hpp->buf, hpp->size, "%2d{", node); |
| 1088 | advance_hpp(hpp, ret); |
| 1089 | |
| 1090 | ret = bitmap_scnprintf(set, c2c.cpus_cnt, hpp->buf, hpp->size); |
| 1091 | advance_hpp(hpp, ret); |
| 1092 | |
| 1093 | ret = scnprintf(hpp->buf, hpp->size, "}"); |
| 1094 | advance_hpp(hpp, ret); |
| 1095 | break; |
| 1096 | default: |
| 1097 | break; |
| 1098 | } |
| 1099 | |
| 1100 | first = false; |
| 1101 | } |
| 1102 | |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
Jiri Olsa | 92062d5 | 2016-06-05 13:40:53 +0200 | [diff] [blame] | 1106 | static int |
| 1107 | mean_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 1108 | struct hist_entry *he, double mean) |
| 1109 | { |
| 1110 | int width = c2c_width(fmt, hpp, he->hists); |
| 1111 | char buf[10]; |
| 1112 | |
| 1113 | scnprintf(buf, 10, "%6.0f", mean); |
| 1114 | return scnprintf(hpp->buf, hpp->size, "%*s", width, buf); |
| 1115 | } |
| 1116 | |
| 1117 | #define MEAN_ENTRY(__func, __val) \ |
| 1118 | static int \ |
| 1119 | __func(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, struct hist_entry *he) \ |
| 1120 | { \ |
| 1121 | struct c2c_hist_entry *c2c_he; \ |
| 1122 | c2c_he = container_of(he, struct c2c_hist_entry, he); \ |
| 1123 | return mean_entry(fmt, hpp, he, avg_stats(&c2c_he->cstats.__val)); \ |
| 1124 | } |
| 1125 | |
| 1126 | MEAN_ENTRY(mean_rmt_entry, rmt_hitm); |
| 1127 | MEAN_ENTRY(mean_lcl_entry, lcl_hitm); |
| 1128 | MEAN_ENTRY(mean_load_entry, load); |
| 1129 | |
Jiri Olsa | b6fe2bb | 2016-06-23 23:05:52 +0200 | [diff] [blame] | 1130 | static int |
Arnaldo Carvalho de Melo | 7e6a799 | 2016-12-12 10:52:10 -0300 | [diff] [blame] | 1131 | cpucnt_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
Jiri Olsa | b6fe2bb | 2016-06-23 23:05:52 +0200 | [diff] [blame] | 1132 | struct hist_entry *he) |
| 1133 | { |
| 1134 | struct c2c_hist_entry *c2c_he; |
| 1135 | int width = c2c_width(fmt, hpp, he->hists); |
| 1136 | char buf[10]; |
| 1137 | |
| 1138 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 1139 | |
| 1140 | scnprintf(buf, 10, "%d", bitmap_weight(c2c_he->cpuset, c2c.cpus_cnt)); |
| 1141 | return scnprintf(hpp->buf, hpp->size, "%*s", width, buf); |
| 1142 | } |
| 1143 | |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 1144 | static int |
Arnaldo Carvalho de Melo | 7e6a799 | 2016-12-12 10:52:10 -0300 | [diff] [blame] | 1145 | cl_idx_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 1146 | struct hist_entry *he) |
| 1147 | { |
| 1148 | struct c2c_hist_entry *c2c_he; |
| 1149 | int width = c2c_width(fmt, hpp, he->hists); |
| 1150 | char buf[10]; |
| 1151 | |
| 1152 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 1153 | |
| 1154 | scnprintf(buf, 10, "%u", c2c_he->cacheline_idx); |
| 1155 | return scnprintf(hpp->buf, hpp->size, "%*s", width, buf); |
| 1156 | } |
| 1157 | |
| 1158 | static int |
Arnaldo Carvalho de Melo | 7e6a799 | 2016-12-12 10:52:10 -0300 | [diff] [blame] | 1159 | cl_idx_empty_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 1160 | struct hist_entry *he) |
| 1161 | { |
| 1162 | int width = c2c_width(fmt, hpp, he->hists); |
| 1163 | |
| 1164 | return scnprintf(hpp->buf, hpp->size, "%*s", width, ""); |
| 1165 | } |
| 1166 | |
Jiri Olsa | 600a8cf | 2016-09-22 17:36:47 +0200 | [diff] [blame] | 1167 | #define HEADER_LOW(__h) \ |
| 1168 | { \ |
| 1169 | .line[1] = { \ |
| 1170 | .text = __h, \ |
| 1171 | }, \ |
| 1172 | } |
| 1173 | |
| 1174 | #define HEADER_BOTH(__h0, __h1) \ |
| 1175 | { \ |
| 1176 | .line[0] = { \ |
| 1177 | .text = __h0, \ |
| 1178 | }, \ |
| 1179 | .line[1] = { \ |
| 1180 | .text = __h1, \ |
| 1181 | }, \ |
| 1182 | } |
| 1183 | |
| 1184 | #define HEADER_SPAN(__h0, __h1, __s) \ |
| 1185 | { \ |
| 1186 | .line[0] = { \ |
| 1187 | .text = __h0, \ |
| 1188 | .span = __s, \ |
| 1189 | }, \ |
| 1190 | .line[1] = { \ |
| 1191 | .text = __h1, \ |
| 1192 | }, \ |
| 1193 | } |
| 1194 | |
| 1195 | #define HEADER_SPAN_LOW(__h) \ |
| 1196 | { \ |
| 1197 | .line[1] = { \ |
| 1198 | .text = __h, \ |
| 1199 | }, \ |
| 1200 | } |
| 1201 | |
Jiri Olsa | cbb8850 | 2016-09-22 17:36:48 +0200 | [diff] [blame] | 1202 | static struct c2c_dimension dim_dcacheline = { |
| 1203 | .header = HEADER_LOW("Cacheline"), |
| 1204 | .name = "dcacheline", |
| 1205 | .cmp = dcacheline_cmp, |
| 1206 | .entry = dcacheline_entry, |
| 1207 | .width = 18, |
| 1208 | }; |
| 1209 | |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 1210 | static struct c2c_header header_offset_tui = HEADER_LOW("Off"); |
| 1211 | |
Jiri Olsa | 48acdeb | 2016-04-29 14:37:06 +0200 | [diff] [blame] | 1212 | static struct c2c_dimension dim_offset = { |
| 1213 | .header = HEADER_BOTH("Data address", "Offset"), |
| 1214 | .name = "offset", |
| 1215 | .cmp = offset_cmp, |
| 1216 | .entry = offset_entry, |
| 1217 | .width = 18, |
| 1218 | }; |
| 1219 | |
Jiri Olsa | 43575a9 | 2016-05-03 21:48:56 +0200 | [diff] [blame] | 1220 | static struct c2c_dimension dim_iaddr = { |
| 1221 | .header = HEADER_LOW("Code address"), |
| 1222 | .name = "iaddr", |
| 1223 | .cmp = iaddr_cmp, |
| 1224 | .entry = iaddr_entry, |
| 1225 | .width = 18, |
| 1226 | }; |
| 1227 | |
Jiri Olsa | 97cb486 | 2016-05-23 16:20:14 +0200 | [diff] [blame] | 1228 | static struct c2c_dimension dim_tot_hitm = { |
| 1229 | .header = HEADER_SPAN("----- LLC Load Hitm -----", "Total", 2), |
| 1230 | .name = "tot_hitm", |
| 1231 | .cmp = tot_hitm_cmp, |
| 1232 | .entry = tot_hitm_entry, |
| 1233 | .width = 7, |
| 1234 | }; |
| 1235 | |
| 1236 | static struct c2c_dimension dim_lcl_hitm = { |
| 1237 | .header = HEADER_SPAN_LOW("Lcl"), |
| 1238 | .name = "lcl_hitm", |
| 1239 | .cmp = lcl_hitm_cmp, |
| 1240 | .entry = lcl_hitm_entry, |
| 1241 | .width = 7, |
| 1242 | }; |
| 1243 | |
| 1244 | static struct c2c_dimension dim_rmt_hitm = { |
| 1245 | .header = HEADER_SPAN_LOW("Rmt"), |
| 1246 | .name = "rmt_hitm", |
| 1247 | .cmp = rmt_hitm_cmp, |
| 1248 | .entry = rmt_hitm_entry, |
| 1249 | .width = 7, |
| 1250 | }; |
| 1251 | |
| 1252 | static struct c2c_dimension dim_cl_rmt_hitm = { |
| 1253 | .header = HEADER_SPAN("----- HITM -----", "Rmt", 1), |
| 1254 | .name = "cl_rmt_hitm", |
| 1255 | .cmp = rmt_hitm_cmp, |
| 1256 | .entry = rmt_hitm_entry, |
| 1257 | .width = 7, |
| 1258 | }; |
| 1259 | |
| 1260 | static struct c2c_dimension dim_cl_lcl_hitm = { |
| 1261 | .header = HEADER_SPAN_LOW("Lcl"), |
| 1262 | .name = "cl_lcl_hitm", |
| 1263 | .cmp = lcl_hitm_cmp, |
| 1264 | .entry = lcl_hitm_entry, |
| 1265 | .width = 7, |
| 1266 | }; |
| 1267 | |
Jiri Olsa | 0f18896 | 2016-05-04 10:10:11 +0200 | [diff] [blame] | 1268 | static struct c2c_dimension dim_stores = { |
| 1269 | .header = HEADER_SPAN("---- Store Reference ----", "Total", 2), |
| 1270 | .name = "stores", |
| 1271 | .cmp = store_cmp, |
| 1272 | .entry = store_entry, |
| 1273 | .width = 7, |
| 1274 | }; |
| 1275 | |
| 1276 | static struct c2c_dimension dim_stores_l1hit = { |
| 1277 | .header = HEADER_SPAN_LOW("L1Hit"), |
| 1278 | .name = "stores_l1hit", |
| 1279 | .cmp = st_l1hit_cmp, |
| 1280 | .entry = st_l1hit_entry, |
| 1281 | .width = 7, |
| 1282 | }; |
| 1283 | |
| 1284 | static struct c2c_dimension dim_stores_l1miss = { |
| 1285 | .header = HEADER_SPAN_LOW("L1Miss"), |
| 1286 | .name = "stores_l1miss", |
| 1287 | .cmp = st_l1miss_cmp, |
| 1288 | .entry = st_l1miss_entry, |
| 1289 | .width = 7, |
| 1290 | }; |
| 1291 | |
| 1292 | static struct c2c_dimension dim_cl_stores_l1hit = { |
| 1293 | .header = HEADER_SPAN("-- Store Refs --", "L1 Hit", 1), |
| 1294 | .name = "cl_stores_l1hit", |
| 1295 | .cmp = st_l1hit_cmp, |
| 1296 | .entry = st_l1hit_entry, |
| 1297 | .width = 7, |
| 1298 | }; |
| 1299 | |
| 1300 | static struct c2c_dimension dim_cl_stores_l1miss = { |
| 1301 | .header = HEADER_SPAN_LOW("L1 Miss"), |
| 1302 | .name = "cl_stores_l1miss", |
| 1303 | .cmp = st_l1miss_cmp, |
| 1304 | .entry = st_l1miss_entry, |
| 1305 | .width = 7, |
| 1306 | }; |
| 1307 | |
Jiri Olsa | 1295f68 | 2016-05-04 10:18:24 +0200 | [diff] [blame] | 1308 | static struct c2c_dimension dim_ld_fbhit = { |
| 1309 | .header = HEADER_SPAN("----- Core Load Hit -----", "FB", 2), |
| 1310 | .name = "ld_fbhit", |
| 1311 | .cmp = ld_fbhit_cmp, |
| 1312 | .entry = ld_fbhit_entry, |
| 1313 | .width = 7, |
| 1314 | }; |
| 1315 | |
| 1316 | static struct c2c_dimension dim_ld_l1hit = { |
| 1317 | .header = HEADER_SPAN_LOW("L1"), |
| 1318 | .name = "ld_l1hit", |
| 1319 | .cmp = ld_l1hit_cmp, |
| 1320 | .entry = ld_l1hit_entry, |
| 1321 | .width = 7, |
| 1322 | }; |
| 1323 | |
| 1324 | static struct c2c_dimension dim_ld_l2hit = { |
| 1325 | .header = HEADER_SPAN_LOW("L2"), |
| 1326 | .name = "ld_l2hit", |
| 1327 | .cmp = ld_l2hit_cmp, |
| 1328 | .entry = ld_l2hit_entry, |
| 1329 | .width = 7, |
| 1330 | }; |
| 1331 | |
Jiri Olsa | 4d08910 | 2016-05-04 10:27:51 +0200 | [diff] [blame] | 1332 | static struct c2c_dimension dim_ld_llchit = { |
| 1333 | .header = HEADER_SPAN("-- LLC Load Hit --", "Llc", 1), |
| 1334 | .name = "ld_lclhit", |
| 1335 | .cmp = ld_llchit_cmp, |
| 1336 | .entry = ld_llchit_entry, |
| 1337 | .width = 8, |
| 1338 | }; |
| 1339 | |
| 1340 | static struct c2c_dimension dim_ld_rmthit = { |
| 1341 | .header = HEADER_SPAN_LOW("Rmt"), |
| 1342 | .name = "ld_rmthit", |
| 1343 | .cmp = rmt_hit_cmp, |
| 1344 | .entry = rmt_hit_entry, |
| 1345 | .width = 8, |
| 1346 | }; |
| 1347 | |
Jiri Olsa | 04402d2 | 2016-05-19 10:10:51 +0200 | [diff] [blame] | 1348 | static struct c2c_dimension dim_ld_llcmiss = { |
| 1349 | .header = HEADER_BOTH("LLC", "Ld Miss"), |
| 1350 | .name = "ld_llcmiss", |
| 1351 | .cmp = ld_llcmiss_cmp, |
| 1352 | .entry = ld_llcmiss_entry, |
| 1353 | .width = 7, |
| 1354 | }; |
| 1355 | |
Jiri Olsa | 01b84d7 | 2016-05-04 10:35:29 +0200 | [diff] [blame] | 1356 | static struct c2c_dimension dim_tot_recs = { |
| 1357 | .header = HEADER_BOTH("Total", "records"), |
| 1358 | .name = "tot_recs", |
| 1359 | .cmp = tot_recs_cmp, |
| 1360 | .entry = tot_recs_entry, |
| 1361 | .width = 7, |
| 1362 | }; |
| 1363 | |
Jiri Olsa | 55177c4 | 2016-05-19 09:52:37 +0200 | [diff] [blame] | 1364 | static struct c2c_dimension dim_tot_loads = { |
| 1365 | .header = HEADER_BOTH("Total", "Loads"), |
| 1366 | .name = "tot_loads", |
| 1367 | .cmp = tot_loads_cmp, |
| 1368 | .entry = tot_loads_entry, |
| 1369 | .width = 7, |
| 1370 | }; |
| 1371 | |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1372 | static struct c2c_header percent_hitm_header[] = { |
| 1373 | [DISPLAY_LCL] = HEADER_BOTH("Lcl", "Hitm"), |
| 1374 | [DISPLAY_RMT] = HEADER_BOTH("Rmt", "Hitm"), |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 1375 | [DISPLAY_TOT] = HEADER_BOTH("Tot", "Hitm"), |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1376 | }; |
| 1377 | |
Jiri Olsa | f0c50c1 | 2016-05-04 10:50:09 +0200 | [diff] [blame] | 1378 | static struct c2c_dimension dim_percent_hitm = { |
Jiri Olsa | f0c50c1 | 2016-05-04 10:50:09 +0200 | [diff] [blame] | 1379 | .name = "percent_hitm", |
| 1380 | .cmp = percent_hitm_cmp, |
| 1381 | .entry = percent_hitm_entry, |
| 1382 | .color = percent_hitm_color, |
| 1383 | .width = 7, |
| 1384 | }; |
| 1385 | |
Jiri Olsa | 9cb3500 | 2016-05-04 12:16:50 +0200 | [diff] [blame] | 1386 | static struct c2c_dimension dim_percent_rmt_hitm = { |
| 1387 | .header = HEADER_SPAN("----- HITM -----", "Rmt", 1), |
| 1388 | .name = "percent_rmt_hitm", |
| 1389 | .cmp = percent_rmt_hitm_cmp, |
| 1390 | .entry = percent_rmt_hitm_entry, |
| 1391 | .color = percent_rmt_hitm_color, |
| 1392 | .width = 7, |
| 1393 | }; |
| 1394 | |
| 1395 | static struct c2c_dimension dim_percent_lcl_hitm = { |
| 1396 | .header = HEADER_SPAN_LOW("Lcl"), |
| 1397 | .name = "percent_lcl_hitm", |
| 1398 | .cmp = percent_lcl_hitm_cmp, |
| 1399 | .entry = percent_lcl_hitm_entry, |
| 1400 | .color = percent_lcl_hitm_color, |
| 1401 | .width = 7, |
| 1402 | }; |
| 1403 | |
| 1404 | static struct c2c_dimension dim_percent_stores_l1hit = { |
| 1405 | .header = HEADER_SPAN("-- Store Refs --", "L1 Hit", 1), |
| 1406 | .name = "percent_stores_l1hit", |
| 1407 | .cmp = percent_stores_l1hit_cmp, |
| 1408 | .entry = percent_stores_l1hit_entry, |
| 1409 | .color = percent_stores_l1hit_color, |
| 1410 | .width = 7, |
| 1411 | }; |
| 1412 | |
| 1413 | static struct c2c_dimension dim_percent_stores_l1miss = { |
| 1414 | .header = HEADER_SPAN_LOW("L1 Miss"), |
| 1415 | .name = "percent_stores_l1miss", |
| 1416 | .cmp = percent_stores_l1miss_cmp, |
| 1417 | .entry = percent_stores_l1miss_entry, |
| 1418 | .color = percent_stores_l1miss_color, |
| 1419 | .width = 7, |
| 1420 | }; |
| 1421 | |
Jiri Olsa | 6c70f54 | 2016-05-28 12:30:13 +0200 | [diff] [blame] | 1422 | static struct c2c_dimension dim_dram_lcl = { |
| 1423 | .header = HEADER_SPAN("--- Load Dram ----", "Lcl", 1), |
| 1424 | .name = "dram_lcl", |
| 1425 | .cmp = lcl_dram_cmp, |
| 1426 | .entry = lcl_dram_entry, |
| 1427 | .width = 8, |
| 1428 | }; |
| 1429 | |
| 1430 | static struct c2c_dimension dim_dram_rmt = { |
| 1431 | .header = HEADER_SPAN_LOW("Rmt"), |
| 1432 | .name = "dram_rmt", |
| 1433 | .cmp = rmt_dram_cmp, |
| 1434 | .entry = rmt_dram_entry, |
| 1435 | .width = 8, |
| 1436 | }; |
| 1437 | |
Jiri Olsa | 36d3deb | 2016-05-24 13:09:47 +0200 | [diff] [blame] | 1438 | static struct c2c_dimension dim_pid = { |
| 1439 | .header = HEADER_LOW("Pid"), |
| 1440 | .name = "pid", |
| 1441 | .cmp = pid_cmp, |
| 1442 | .entry = pid_entry, |
| 1443 | .width = 7, |
| 1444 | }; |
| 1445 | |
Jiri Olsa | e87019c | 2016-05-25 08:50:10 +0200 | [diff] [blame] | 1446 | static struct c2c_dimension dim_tid = { |
| 1447 | .header = HEADER_LOW("Tid"), |
| 1448 | .name = "tid", |
| 1449 | .se = &sort_thread, |
| 1450 | }; |
| 1451 | |
Jiri Olsa | 51dedaa | 2016-05-24 23:41:52 +0200 | [diff] [blame] | 1452 | static struct c2c_dimension dim_symbol = { |
| 1453 | .name = "symbol", |
| 1454 | .se = &sort_sym, |
| 1455 | }; |
| 1456 | |
| 1457 | static struct c2c_dimension dim_dso = { |
| 1458 | .header = HEADER_BOTH("Shared", "Object"), |
| 1459 | .name = "dso", |
| 1460 | .se = &sort_dso, |
| 1461 | }; |
| 1462 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 1463 | static struct c2c_header header_node[3] = { |
| 1464 | HEADER_LOW("Node"), |
| 1465 | HEADER_LOW("Node{cpus %hitms %stores}"), |
| 1466 | HEADER_LOW("Node{cpu list}"), |
| 1467 | }; |
| 1468 | |
| 1469 | static struct c2c_dimension dim_node = { |
| 1470 | .name = "node", |
| 1471 | .cmp = empty_cmp, |
| 1472 | .entry = node_entry, |
| 1473 | .width = 4, |
| 1474 | }; |
| 1475 | |
Jiri Olsa | 92062d5 | 2016-06-05 13:40:53 +0200 | [diff] [blame] | 1476 | static struct c2c_dimension dim_mean_rmt = { |
| 1477 | .header = HEADER_SPAN("---------- cycles ----------", "rmt hitm", 2), |
| 1478 | .name = "mean_rmt", |
| 1479 | .cmp = empty_cmp, |
| 1480 | .entry = mean_rmt_entry, |
| 1481 | .width = 8, |
| 1482 | }; |
| 1483 | |
| 1484 | static struct c2c_dimension dim_mean_lcl = { |
| 1485 | .header = HEADER_SPAN_LOW("lcl hitm"), |
| 1486 | .name = "mean_lcl", |
| 1487 | .cmp = empty_cmp, |
| 1488 | .entry = mean_lcl_entry, |
| 1489 | .width = 8, |
| 1490 | }; |
| 1491 | |
| 1492 | static struct c2c_dimension dim_mean_load = { |
| 1493 | .header = HEADER_SPAN_LOW("load"), |
| 1494 | .name = "mean_load", |
| 1495 | .cmp = empty_cmp, |
| 1496 | .entry = mean_load_entry, |
| 1497 | .width = 8, |
| 1498 | }; |
| 1499 | |
Jiri Olsa | b6fe2bb | 2016-06-23 23:05:52 +0200 | [diff] [blame] | 1500 | static struct c2c_dimension dim_cpucnt = { |
| 1501 | .header = HEADER_BOTH("cpu", "cnt"), |
| 1502 | .name = "cpucnt", |
| 1503 | .cmp = empty_cmp, |
| 1504 | .entry = cpucnt_entry, |
| 1505 | .width = 8, |
| 1506 | }; |
| 1507 | |
Jiri Olsa | 89d9ba8f | 2016-07-10 15:47:40 +0200 | [diff] [blame] | 1508 | static struct c2c_dimension dim_srcline = { |
| 1509 | .name = "cl_srcline", |
| 1510 | .se = &sort_srcline, |
| 1511 | }; |
| 1512 | |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 1513 | static struct c2c_dimension dim_dcacheline_idx = { |
| 1514 | .header = HEADER_LOW("Index"), |
| 1515 | .name = "cl_idx", |
| 1516 | .cmp = empty_cmp, |
| 1517 | .entry = cl_idx_entry, |
| 1518 | .width = 5, |
| 1519 | }; |
| 1520 | |
| 1521 | static struct c2c_dimension dim_dcacheline_num = { |
| 1522 | .header = HEADER_LOW("Num"), |
| 1523 | .name = "cl_num", |
| 1524 | .cmp = empty_cmp, |
| 1525 | .entry = cl_idx_entry, |
| 1526 | .width = 5, |
| 1527 | }; |
| 1528 | |
| 1529 | static struct c2c_dimension dim_dcacheline_num_empty = { |
| 1530 | .header = HEADER_LOW("Num"), |
| 1531 | .name = "cl_num_empty", |
| 1532 | .cmp = empty_cmp, |
| 1533 | .entry = cl_idx_empty_entry, |
| 1534 | .width = 5, |
| 1535 | }; |
| 1536 | |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1537 | static struct c2c_dimension *dimensions[] = { |
Jiri Olsa | cbb8850 | 2016-09-22 17:36:48 +0200 | [diff] [blame] | 1538 | &dim_dcacheline, |
Jiri Olsa | 48acdeb | 2016-04-29 14:37:06 +0200 | [diff] [blame] | 1539 | &dim_offset, |
Jiri Olsa | 43575a9 | 2016-05-03 21:48:56 +0200 | [diff] [blame] | 1540 | &dim_iaddr, |
Jiri Olsa | 97cb486 | 2016-05-23 16:20:14 +0200 | [diff] [blame] | 1541 | &dim_tot_hitm, |
| 1542 | &dim_lcl_hitm, |
| 1543 | &dim_rmt_hitm, |
| 1544 | &dim_cl_lcl_hitm, |
| 1545 | &dim_cl_rmt_hitm, |
Jiri Olsa | 0f18896 | 2016-05-04 10:10:11 +0200 | [diff] [blame] | 1546 | &dim_stores, |
| 1547 | &dim_stores_l1hit, |
| 1548 | &dim_stores_l1miss, |
| 1549 | &dim_cl_stores_l1hit, |
| 1550 | &dim_cl_stores_l1miss, |
Jiri Olsa | 1295f68 | 2016-05-04 10:18:24 +0200 | [diff] [blame] | 1551 | &dim_ld_fbhit, |
| 1552 | &dim_ld_l1hit, |
| 1553 | &dim_ld_l2hit, |
Jiri Olsa | 4d08910 | 2016-05-04 10:27:51 +0200 | [diff] [blame] | 1554 | &dim_ld_llchit, |
| 1555 | &dim_ld_rmthit, |
Jiri Olsa | 04402d2 | 2016-05-19 10:10:51 +0200 | [diff] [blame] | 1556 | &dim_ld_llcmiss, |
Jiri Olsa | 01b84d7 | 2016-05-04 10:35:29 +0200 | [diff] [blame] | 1557 | &dim_tot_recs, |
Jiri Olsa | 55177c4 | 2016-05-19 09:52:37 +0200 | [diff] [blame] | 1558 | &dim_tot_loads, |
Jiri Olsa | f0c50c1 | 2016-05-04 10:50:09 +0200 | [diff] [blame] | 1559 | &dim_percent_hitm, |
Jiri Olsa | 9cb3500 | 2016-05-04 12:16:50 +0200 | [diff] [blame] | 1560 | &dim_percent_rmt_hitm, |
| 1561 | &dim_percent_lcl_hitm, |
| 1562 | &dim_percent_stores_l1hit, |
| 1563 | &dim_percent_stores_l1miss, |
Jiri Olsa | 6c70f54 | 2016-05-28 12:30:13 +0200 | [diff] [blame] | 1564 | &dim_dram_lcl, |
| 1565 | &dim_dram_rmt, |
Jiri Olsa | 36d3deb | 2016-05-24 13:09:47 +0200 | [diff] [blame] | 1566 | &dim_pid, |
Jiri Olsa | e87019c | 2016-05-25 08:50:10 +0200 | [diff] [blame] | 1567 | &dim_tid, |
Jiri Olsa | 51dedaa | 2016-05-24 23:41:52 +0200 | [diff] [blame] | 1568 | &dim_symbol, |
| 1569 | &dim_dso, |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 1570 | &dim_node, |
Jiri Olsa | 92062d5 | 2016-06-05 13:40:53 +0200 | [diff] [blame] | 1571 | &dim_mean_rmt, |
| 1572 | &dim_mean_lcl, |
| 1573 | &dim_mean_load, |
Jiri Olsa | b6fe2bb | 2016-06-23 23:05:52 +0200 | [diff] [blame] | 1574 | &dim_cpucnt, |
Jiri Olsa | 89d9ba8f | 2016-07-10 15:47:40 +0200 | [diff] [blame] | 1575 | &dim_srcline, |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 1576 | &dim_dcacheline_idx, |
| 1577 | &dim_dcacheline_num, |
| 1578 | &dim_dcacheline_num_empty, |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1579 | NULL, |
| 1580 | }; |
| 1581 | |
| 1582 | static void fmt_free(struct perf_hpp_fmt *fmt) |
| 1583 | { |
| 1584 | struct c2c_fmt *c2c_fmt; |
| 1585 | |
| 1586 | c2c_fmt = container_of(fmt, struct c2c_fmt, fmt); |
| 1587 | free(c2c_fmt); |
| 1588 | } |
| 1589 | |
| 1590 | static bool fmt_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b) |
| 1591 | { |
| 1592 | struct c2c_fmt *c2c_a = container_of(a, struct c2c_fmt, fmt); |
| 1593 | struct c2c_fmt *c2c_b = container_of(b, struct c2c_fmt, fmt); |
| 1594 | |
| 1595 | return c2c_a->dim == c2c_b->dim; |
| 1596 | } |
| 1597 | |
| 1598 | static struct c2c_dimension *get_dimension(const char *name) |
| 1599 | { |
| 1600 | unsigned int i; |
| 1601 | |
| 1602 | for (i = 0; dimensions[i]; i++) { |
| 1603 | struct c2c_dimension *dim = dimensions[i]; |
| 1604 | |
| 1605 | if (!strcmp(dim->name, name)) |
| 1606 | return dim; |
| 1607 | }; |
| 1608 | |
| 1609 | return NULL; |
| 1610 | } |
| 1611 | |
Jiri Olsa | 8d3f938 | 2016-09-22 17:36:42 +0200 | [diff] [blame] | 1612 | static int c2c_se_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 1613 | struct hist_entry *he) |
| 1614 | { |
| 1615 | struct c2c_fmt *c2c_fmt = container_of(fmt, struct c2c_fmt, fmt); |
| 1616 | struct c2c_dimension *dim = c2c_fmt->dim; |
| 1617 | size_t len = fmt->user_len; |
| 1618 | |
Jiri Olsa | 590b6a3 | 2016-07-10 16:25:15 +0200 | [diff] [blame] | 1619 | if (!len) { |
Jiri Olsa | 8d3f938 | 2016-09-22 17:36:42 +0200 | [diff] [blame] | 1620 | len = hists__col_len(he->hists, dim->se->se_width_idx); |
| 1621 | |
Jiri Olsa | 590b6a3 | 2016-07-10 16:25:15 +0200 | [diff] [blame] | 1622 | if (dim == &dim_symbol || dim == &dim_srcline) |
| 1623 | len = symbol_width(he->hists, dim->se); |
| 1624 | } |
| 1625 | |
Jiri Olsa | 8d3f938 | 2016-09-22 17:36:42 +0200 | [diff] [blame] | 1626 | return dim->se->se_snprintf(he, hpp->buf, hpp->size, len); |
| 1627 | } |
| 1628 | |
| 1629 | static int64_t c2c_se_cmp(struct perf_hpp_fmt *fmt, |
| 1630 | struct hist_entry *a, struct hist_entry *b) |
| 1631 | { |
| 1632 | struct c2c_fmt *c2c_fmt = container_of(fmt, struct c2c_fmt, fmt); |
| 1633 | struct c2c_dimension *dim = c2c_fmt->dim; |
| 1634 | |
| 1635 | return dim->se->se_cmp(a, b); |
| 1636 | } |
| 1637 | |
| 1638 | static int64_t c2c_se_collapse(struct perf_hpp_fmt *fmt, |
| 1639 | struct hist_entry *a, struct hist_entry *b) |
| 1640 | { |
| 1641 | struct c2c_fmt *c2c_fmt = container_of(fmt, struct c2c_fmt, fmt); |
| 1642 | struct c2c_dimension *dim = c2c_fmt->dim; |
| 1643 | int64_t (*collapse_fn)(struct hist_entry *, struct hist_entry *); |
| 1644 | |
| 1645 | collapse_fn = dim->se->se_collapse ?: dim->se->se_cmp; |
| 1646 | return collapse_fn(a, b); |
| 1647 | } |
| 1648 | |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1649 | static struct c2c_fmt *get_format(const char *name) |
| 1650 | { |
| 1651 | struct c2c_dimension *dim = get_dimension(name); |
| 1652 | struct c2c_fmt *c2c_fmt; |
| 1653 | struct perf_hpp_fmt *fmt; |
| 1654 | |
| 1655 | if (!dim) |
| 1656 | return NULL; |
| 1657 | |
| 1658 | c2c_fmt = zalloc(sizeof(*c2c_fmt)); |
| 1659 | if (!c2c_fmt) |
| 1660 | return NULL; |
| 1661 | |
| 1662 | c2c_fmt->dim = dim; |
| 1663 | |
| 1664 | fmt = &c2c_fmt->fmt; |
| 1665 | INIT_LIST_HEAD(&fmt->list); |
| 1666 | INIT_LIST_HEAD(&fmt->sort_list); |
| 1667 | |
Jiri Olsa | 8d3f938 | 2016-09-22 17:36:42 +0200 | [diff] [blame] | 1668 | fmt->cmp = dim->se ? c2c_se_cmp : dim->cmp; |
| 1669 | fmt->sort = dim->se ? c2c_se_cmp : dim->cmp; |
Jiri Olsa | 9cb3500 | 2016-05-04 12:16:50 +0200 | [diff] [blame] | 1670 | fmt->color = dim->se ? NULL : dim->color; |
Jiri Olsa | 8d3f938 | 2016-09-22 17:36:42 +0200 | [diff] [blame] | 1671 | fmt->entry = dim->se ? c2c_se_entry : dim->entry; |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1672 | fmt->header = c2c_header; |
| 1673 | fmt->width = c2c_width; |
Jiri Olsa | 8d3f938 | 2016-09-22 17:36:42 +0200 | [diff] [blame] | 1674 | fmt->collapse = dim->se ? c2c_se_collapse : dim->cmp; |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1675 | fmt->equal = fmt_equal; |
| 1676 | fmt->free = fmt_free; |
| 1677 | |
| 1678 | return c2c_fmt; |
| 1679 | } |
| 1680 | |
| 1681 | static int c2c_hists__init_output(struct perf_hpp_list *hpp_list, char *name) |
| 1682 | { |
| 1683 | struct c2c_fmt *c2c_fmt = get_format(name); |
| 1684 | |
Jiri Olsa | 5f2eca8 | 2016-09-22 17:36:43 +0200 | [diff] [blame] | 1685 | if (!c2c_fmt) { |
| 1686 | reset_dimensions(); |
| 1687 | return output_field_add(hpp_list, name); |
| 1688 | } |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1689 | |
| 1690 | perf_hpp_list__column_register(hpp_list, &c2c_fmt->fmt); |
| 1691 | return 0; |
| 1692 | } |
| 1693 | |
| 1694 | static int c2c_hists__init_sort(struct perf_hpp_list *hpp_list, char *name) |
| 1695 | { |
| 1696 | struct c2c_fmt *c2c_fmt = get_format(name); |
Jiri Olsa | 51dedaa | 2016-05-24 23:41:52 +0200 | [diff] [blame] | 1697 | struct c2c_dimension *dim; |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1698 | |
Jiri Olsa | 5f2eca8 | 2016-09-22 17:36:43 +0200 | [diff] [blame] | 1699 | if (!c2c_fmt) { |
| 1700 | reset_dimensions(); |
| 1701 | return sort_dimension__add(hpp_list, name, NULL, 0); |
| 1702 | } |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1703 | |
Jiri Olsa | 51dedaa | 2016-05-24 23:41:52 +0200 | [diff] [blame] | 1704 | dim = c2c_fmt->dim; |
| 1705 | if (dim == &dim_dso) |
| 1706 | hpp_list->dso = 1; |
| 1707 | |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1708 | perf_hpp_list__register_sort_field(hpp_list, &c2c_fmt->fmt); |
| 1709 | return 0; |
| 1710 | } |
| 1711 | |
| 1712 | #define PARSE_LIST(_list, _fn) \ |
| 1713 | do { \ |
| 1714 | char *tmp, *tok; \ |
| 1715 | ret = 0; \ |
| 1716 | \ |
| 1717 | if (!_list) \ |
| 1718 | break; \ |
| 1719 | \ |
| 1720 | for (tok = strtok_r((char *)_list, ", ", &tmp); \ |
| 1721 | tok; tok = strtok_r(NULL, ", ", &tmp)) { \ |
| 1722 | ret = _fn(hpp_list, tok); \ |
| 1723 | if (ret == -EINVAL) { \ |
Arnaldo Carvalho de Melo | 62d94b0 | 2017-06-27 11:22:31 -0300 | [diff] [blame] | 1724 | pr_err("Invalid --fields key: `%s'", tok); \ |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1725 | break; \ |
| 1726 | } else if (ret == -ESRCH) { \ |
Arnaldo Carvalho de Melo | 62d94b0 | 2017-06-27 11:22:31 -0300 | [diff] [blame] | 1727 | pr_err("Unknown --fields key: `%s'", tok); \ |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1728 | break; \ |
| 1729 | } \ |
| 1730 | } \ |
| 1731 | } while (0) |
| 1732 | |
| 1733 | static int hpp_list__parse(struct perf_hpp_list *hpp_list, |
| 1734 | const char *output_, |
| 1735 | const char *sort_) |
| 1736 | { |
| 1737 | char *output = output_ ? strdup(output_) : NULL; |
| 1738 | char *sort = sort_ ? strdup(sort_) : NULL; |
| 1739 | int ret; |
| 1740 | |
| 1741 | PARSE_LIST(output, c2c_hists__init_output); |
| 1742 | PARSE_LIST(sort, c2c_hists__init_sort); |
| 1743 | |
| 1744 | /* copy sort keys to output fields */ |
| 1745 | perf_hpp__setup_output_field(hpp_list); |
| 1746 | |
| 1747 | /* |
| 1748 | * We dont need other sorting keys other than those |
| 1749 | * we already specified. It also really slows down |
| 1750 | * the processing a lot with big number of output |
| 1751 | * fields, so switching this off for c2c. |
| 1752 | */ |
| 1753 | |
| 1754 | #if 0 |
| 1755 | /* and then copy output fields to sort keys */ |
| 1756 | perf_hpp__append_sort_keys(&hists->list); |
| 1757 | #endif |
| 1758 | |
| 1759 | free(output); |
| 1760 | free(sort); |
| 1761 | return ret; |
| 1762 | } |
| 1763 | |
| 1764 | static int c2c_hists__init(struct c2c_hists *hists, |
Jiri Olsa | 1d62fcd | 2016-05-24 10:12:31 +0200 | [diff] [blame] | 1765 | const char *sort, |
| 1766 | int nr_header_lines) |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1767 | { |
| 1768 | __hists__init(&hists->hists, &hists->list); |
| 1769 | |
| 1770 | /* |
| 1771 | * Initialize only with sort fields, we need to resort |
| 1772 | * later anyway, and that's where we add output fields |
| 1773 | * as well. |
| 1774 | */ |
| 1775 | perf_hpp_list__init(&hists->list); |
| 1776 | |
Jiri Olsa | 1d62fcd | 2016-05-24 10:12:31 +0200 | [diff] [blame] | 1777 | /* Overload number of header lines.*/ |
| 1778 | hists->list.nr_header_lines = nr_header_lines; |
| 1779 | |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1780 | return hpp_list__parse(&hists->list, NULL, sort); |
| 1781 | } |
| 1782 | |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 1783 | static int c2c_hists__reinit(struct c2c_hists *c2c_hists, |
| 1784 | const char *output, |
| 1785 | const char *sort) |
| 1786 | { |
| 1787 | perf_hpp__reset_output_field(&c2c_hists->list); |
| 1788 | return hpp_list__parse(&c2c_hists->list, output, sort); |
| 1789 | } |
| 1790 | |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1791 | #define DISPLAY_LINE_LIMIT 0.0005 |
| 1792 | |
| 1793 | static bool he__display(struct hist_entry *he, struct c2c_stats *stats) |
| 1794 | { |
| 1795 | struct c2c_hist_entry *c2c_he; |
| 1796 | double ld_dist; |
| 1797 | |
Jiri Olsa | af09b2d | 2016-10-11 13:52:05 +0200 | [diff] [blame] | 1798 | if (c2c.show_all) |
| 1799 | return true; |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1800 | |
| 1801 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 1802 | |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1803 | #define FILTER_HITM(__h) \ |
| 1804 | if (stats->__h) { \ |
| 1805 | ld_dist = ((double)c2c_he->stats.__h / stats->__h); \ |
| 1806 | if (ld_dist < DISPLAY_LINE_LIMIT) \ |
| 1807 | he->filtered = HIST_FILTER__C2C; \ |
| 1808 | } else { \ |
| 1809 | he->filtered = HIST_FILTER__C2C; \ |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1810 | } |
| 1811 | |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1812 | switch (c2c.display) { |
| 1813 | case DISPLAY_LCL: |
| 1814 | FILTER_HITM(lcl_hitm); |
| 1815 | break; |
| 1816 | case DISPLAY_RMT: |
| 1817 | FILTER_HITM(rmt_hitm); |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 1818 | break; |
| 1819 | case DISPLAY_TOT: |
| 1820 | FILTER_HITM(tot_hitm); |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1821 | default: |
| 1822 | break; |
| 1823 | }; |
| 1824 | |
| 1825 | #undef FILTER_HITM |
| 1826 | |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1827 | return he->filtered == 0; |
| 1828 | } |
| 1829 | |
| 1830 | static inline int valid_hitm_or_store(struct hist_entry *he) |
| 1831 | { |
| 1832 | struct c2c_hist_entry *c2c_he; |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1833 | bool has_hitm; |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1834 | |
| 1835 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 1836 | has_hitm = c2c.display == DISPLAY_TOT ? c2c_he->stats.tot_hitm : |
| 1837 | c2c.display == DISPLAY_LCL ? c2c_he->stats.lcl_hitm : |
| 1838 | c2c_he->stats.rmt_hitm; |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 1839 | return has_hitm || c2c_he->stats.store; |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
Jiri Olsa | 3773138 | 2018-03-09 11:14:38 +0100 | [diff] [blame^] | 1842 | static void calc_width(struct c2c_hist_entry *c2c_he) |
Jiri Olsa | 25aa84e | 2016-06-07 19:02:43 +0200 | [diff] [blame] | 1843 | { |
| 1844 | struct c2c_hists *c2c_hists; |
| 1845 | |
Jiri Olsa | 3773138 | 2018-03-09 11:14:38 +0100 | [diff] [blame^] | 1846 | c2c_hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); |
| 1847 | hists__calc_col_len(&c2c_hists->hists, &c2c_he->he); |
Jiri Olsa | 25aa84e | 2016-06-07 19:02:43 +0200 | [diff] [blame] | 1848 | } |
| 1849 | |
Jiri Olsa | 89d9ba8f | 2016-07-10 15:47:40 +0200 | [diff] [blame] | 1850 | static int filter_cb(struct hist_entry *he) |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 1851 | { |
Jiri Olsa | 3773138 | 2018-03-09 11:14:38 +0100 | [diff] [blame^] | 1852 | struct c2c_hist_entry *c2c_he; |
| 1853 | |
| 1854 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 1855 | |
Jiri Olsa | 89d9ba8f | 2016-07-10 15:47:40 +0200 | [diff] [blame] | 1856 | if (c2c.show_src && !he->srcline) |
| 1857 | he->srcline = hist_entry__get_srcline(he); |
| 1858 | |
Jiri Olsa | 3773138 | 2018-03-09 11:14:38 +0100 | [diff] [blame^] | 1859 | calc_width(c2c_he); |
Jiri Olsa | 25aa84e | 2016-06-07 19:02:43 +0200 | [diff] [blame] | 1860 | |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1861 | if (!valid_hitm_or_store(he)) |
| 1862 | he->filtered = HIST_FILTER__C2C; |
| 1863 | |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 1864 | return 0; |
| 1865 | } |
| 1866 | |
| 1867 | static int resort_cl_cb(struct hist_entry *he) |
| 1868 | { |
| 1869 | struct c2c_hist_entry *c2c_he; |
| 1870 | struct c2c_hists *c2c_hists; |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1871 | bool display = he__display(he, &c2c.hitm_stats); |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 1872 | |
| 1873 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 1874 | c2c_hists = c2c_he->hists; |
| 1875 | |
Jiri Olsa | 3773138 | 2018-03-09 11:14:38 +0100 | [diff] [blame^] | 1876 | calc_width(c2c_he); |
Jiri Olsa | 25aa84e | 2016-06-07 19:02:43 +0200 | [diff] [blame] | 1877 | |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1878 | if (display && c2c_hists) { |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 1879 | static unsigned int idx; |
| 1880 | |
| 1881 | c2c_he->cacheline_idx = idx++; |
| 1882 | |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 1883 | c2c_hists__reinit(c2c_hists, c2c.cl_output, c2c.cl_resort); |
Jiri Olsa | 22dd59d | 2016-05-10 14:08:29 +0200 | [diff] [blame] | 1884 | |
Jiri Olsa | ec06f9b | 2016-09-22 17:36:45 +0200 | [diff] [blame] | 1885 | hists__collapse_resort(&c2c_hists->hists, NULL); |
| 1886 | hists__output_resort_cb(&c2c_hists->hists, NULL, filter_cb); |
| 1887 | } |
| 1888 | |
| 1889 | return 0; |
| 1890 | } |
| 1891 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 1892 | static void setup_nodes_header(void) |
| 1893 | { |
| 1894 | dim_node.header = header_node[c2c.node_info]; |
| 1895 | } |
| 1896 | |
| 1897 | static int setup_nodes(struct perf_session *session) |
| 1898 | { |
| 1899 | struct numa_node *n; |
| 1900 | unsigned long **nodes; |
| 1901 | int node, cpu; |
| 1902 | int *cpu2node; |
| 1903 | |
| 1904 | if (c2c.node_info > 2) |
| 1905 | c2c.node_info = 2; |
| 1906 | |
| 1907 | c2c.nodes_cnt = session->header.env.nr_numa_nodes; |
| 1908 | c2c.cpus_cnt = session->header.env.nr_cpus_online; |
| 1909 | |
| 1910 | n = session->header.env.numa_nodes; |
| 1911 | if (!n) |
| 1912 | return -EINVAL; |
| 1913 | |
| 1914 | nodes = zalloc(sizeof(unsigned long *) * c2c.nodes_cnt); |
| 1915 | if (!nodes) |
| 1916 | return -ENOMEM; |
| 1917 | |
| 1918 | c2c.nodes = nodes; |
| 1919 | |
| 1920 | cpu2node = zalloc(sizeof(int) * c2c.cpus_cnt); |
| 1921 | if (!cpu2node) |
| 1922 | return -ENOMEM; |
| 1923 | |
| 1924 | for (cpu = 0; cpu < c2c.cpus_cnt; cpu++) |
| 1925 | cpu2node[cpu] = -1; |
| 1926 | |
| 1927 | c2c.cpu2node = cpu2node; |
| 1928 | |
| 1929 | for (node = 0; node < c2c.nodes_cnt; node++) { |
| 1930 | struct cpu_map *map = n[node].map; |
| 1931 | unsigned long *set; |
| 1932 | |
| 1933 | set = bitmap_alloc(c2c.cpus_cnt); |
| 1934 | if (!set) |
| 1935 | return -ENOMEM; |
| 1936 | |
| 1937 | for (cpu = 0; cpu < map->nr; cpu++) { |
| 1938 | set_bit(map->map[cpu], set); |
| 1939 | |
| 1940 | if (WARN_ONCE(cpu2node[map->map[cpu]] != -1, "node/cpu topology bug")) |
| 1941 | return -EINVAL; |
| 1942 | |
| 1943 | cpu2node[map->map[cpu]] = node; |
| 1944 | } |
| 1945 | |
| 1946 | nodes[node] = set; |
| 1947 | } |
| 1948 | |
| 1949 | setup_nodes_header(); |
| 1950 | return 0; |
| 1951 | } |
| 1952 | |
Jiri Olsa | 7ef2efa | 2016-07-01 11:12:11 +0200 | [diff] [blame] | 1953 | #define HAS_HITMS(__h) ((__h)->stats.lcl_hitm || (__h)->stats.rmt_hitm) |
| 1954 | |
| 1955 | static int resort_hitm_cb(struct hist_entry *he) |
| 1956 | { |
| 1957 | struct c2c_hist_entry *c2c_he; |
| 1958 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 1959 | |
| 1960 | if (HAS_HITMS(c2c_he)) { |
| 1961 | c2c.shared_clines++; |
| 1962 | c2c_add_stats(&c2c.hitm_stats, &c2c_he->stats); |
| 1963 | } |
| 1964 | |
| 1965 | return 0; |
| 1966 | } |
| 1967 | |
| 1968 | static int hists__iterate_cb(struct hists *hists, hists__resort_cb_t cb) |
| 1969 | { |
| 1970 | struct rb_node *next = rb_first(&hists->entries); |
| 1971 | int ret = 0; |
| 1972 | |
| 1973 | while (next) { |
| 1974 | struct hist_entry *he; |
| 1975 | |
| 1976 | he = rb_entry(next, struct hist_entry, rb_node); |
| 1977 | ret = cb(he); |
| 1978 | if (ret) |
| 1979 | break; |
| 1980 | next = rb_next(&he->rb_node); |
| 1981 | } |
| 1982 | |
| 1983 | return ret; |
| 1984 | } |
| 1985 | |
Jiri Olsa | 74c63a2 | 2016-05-02 20:01:59 +0200 | [diff] [blame] | 1986 | static void print_c2c__display_stats(FILE *out) |
| 1987 | { |
| 1988 | int llc_misses; |
| 1989 | struct c2c_stats *stats = &c2c.hists.stats; |
| 1990 | |
| 1991 | llc_misses = stats->lcl_dram + |
| 1992 | stats->rmt_dram + |
| 1993 | stats->rmt_hit + |
| 1994 | stats->rmt_hitm; |
| 1995 | |
| 1996 | fprintf(out, "=================================================\n"); |
| 1997 | fprintf(out, " Trace Event Information \n"); |
| 1998 | fprintf(out, "=================================================\n"); |
| 1999 | fprintf(out, " Total records : %10d\n", stats->nr_entries); |
| 2000 | fprintf(out, " Locked Load/Store Operations : %10d\n", stats->locks); |
| 2001 | fprintf(out, " Load Operations : %10d\n", stats->load); |
| 2002 | fprintf(out, " Loads - uncacheable : %10d\n", stats->ld_uncache); |
| 2003 | fprintf(out, " Loads - IO : %10d\n", stats->ld_io); |
| 2004 | fprintf(out, " Loads - Miss : %10d\n", stats->ld_miss); |
| 2005 | fprintf(out, " Loads - no mapping : %10d\n", stats->ld_noadrs); |
| 2006 | fprintf(out, " Load Fill Buffer Hit : %10d\n", stats->ld_fbhit); |
| 2007 | fprintf(out, " Load L1D hit : %10d\n", stats->ld_l1hit); |
| 2008 | fprintf(out, " Load L2D hit : %10d\n", stats->ld_l2hit); |
| 2009 | fprintf(out, " Load LLC hit : %10d\n", stats->ld_llchit + stats->lcl_hitm); |
| 2010 | fprintf(out, " Load Local HITM : %10d\n", stats->lcl_hitm); |
| 2011 | fprintf(out, " Load Remote HITM : %10d\n", stats->rmt_hitm); |
| 2012 | fprintf(out, " Load Remote HIT : %10d\n", stats->rmt_hit); |
| 2013 | fprintf(out, " Load Local DRAM : %10d\n", stats->lcl_dram); |
| 2014 | fprintf(out, " Load Remote DRAM : %10d\n", stats->rmt_dram); |
| 2015 | fprintf(out, " Load MESI State Exclusive : %10d\n", stats->ld_excl); |
| 2016 | fprintf(out, " Load MESI State Shared : %10d\n", stats->ld_shared); |
| 2017 | fprintf(out, " Load LLC Misses : %10d\n", llc_misses); |
| 2018 | fprintf(out, " LLC Misses to Local DRAM : %10.1f%%\n", ((double)stats->lcl_dram/(double)llc_misses) * 100.); |
| 2019 | fprintf(out, " LLC Misses to Remote DRAM : %10.1f%%\n", ((double)stats->rmt_dram/(double)llc_misses) * 100.); |
| 2020 | fprintf(out, " LLC Misses to Remote cache (HIT) : %10.1f%%\n", ((double)stats->rmt_hit /(double)llc_misses) * 100.); |
| 2021 | fprintf(out, " LLC Misses to Remote cache (HITM) : %10.1f%%\n", ((double)stats->rmt_hitm/(double)llc_misses) * 100.); |
| 2022 | fprintf(out, " Store Operations : %10d\n", stats->store); |
| 2023 | fprintf(out, " Store - uncacheable : %10d\n", stats->st_uncache); |
| 2024 | fprintf(out, " Store - no mapping : %10d\n", stats->st_noadrs); |
| 2025 | fprintf(out, " Store L1D Hit : %10d\n", stats->st_l1hit); |
| 2026 | fprintf(out, " Store L1D Miss : %10d\n", stats->st_l1miss); |
| 2027 | fprintf(out, " No Page Map Rejects : %10d\n", stats->nomap); |
| 2028 | fprintf(out, " Unable to parse data source : %10d\n", stats->noparse); |
| 2029 | } |
| 2030 | |
Jiri Olsa | 7ef2efa | 2016-07-01 11:12:11 +0200 | [diff] [blame] | 2031 | static void print_shared_cacheline_info(FILE *out) |
| 2032 | { |
| 2033 | struct c2c_stats *stats = &c2c.hitm_stats; |
| 2034 | int hitm_cnt = stats->lcl_hitm + stats->rmt_hitm; |
| 2035 | |
| 2036 | fprintf(out, "=================================================\n"); |
| 2037 | fprintf(out, " Global Shared Cache Line Event Information \n"); |
| 2038 | fprintf(out, "=================================================\n"); |
| 2039 | fprintf(out, " Total Shared Cache Lines : %10d\n", c2c.shared_clines); |
| 2040 | fprintf(out, " Load HITs on shared lines : %10d\n", stats->load); |
| 2041 | fprintf(out, " Fill Buffer Hits on shared lines : %10d\n", stats->ld_fbhit); |
| 2042 | fprintf(out, " L1D hits on shared lines : %10d\n", stats->ld_l1hit); |
| 2043 | fprintf(out, " L2D hits on shared lines : %10d\n", stats->ld_l2hit); |
| 2044 | fprintf(out, " LLC hits on shared lines : %10d\n", stats->ld_llchit + stats->lcl_hitm); |
| 2045 | fprintf(out, " Locked Access on shared lines : %10d\n", stats->locks); |
| 2046 | fprintf(out, " Store HITs on shared lines : %10d\n", stats->store); |
| 2047 | fprintf(out, " Store L1D hits on shared lines : %10d\n", stats->st_l1hit); |
| 2048 | fprintf(out, " Total Merged records : %10d\n", hitm_cnt + stats->store); |
| 2049 | } |
| 2050 | |
Jiri Olsa | 2d388bd | 2016-05-03 14:32:56 +0200 | [diff] [blame] | 2051 | static void print_cacheline(struct c2c_hists *c2c_hists, |
| 2052 | struct hist_entry *he_cl, |
| 2053 | struct perf_hpp_list *hpp_list, |
| 2054 | FILE *out) |
| 2055 | { |
| 2056 | char bf[1000]; |
| 2057 | struct perf_hpp hpp = { |
| 2058 | .buf = bf, |
| 2059 | .size = 1000, |
| 2060 | }; |
| 2061 | static bool once; |
| 2062 | |
| 2063 | if (!once) { |
| 2064 | hists__fprintf_headers(&c2c_hists->hists, out); |
| 2065 | once = true; |
| 2066 | } else { |
| 2067 | fprintf(out, "\n"); |
| 2068 | } |
| 2069 | |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 2070 | fprintf(out, " -------------------------------------------------------------\n"); |
Jiri Olsa | 2d388bd | 2016-05-03 14:32:56 +0200 | [diff] [blame] | 2071 | __hist_entry__snprintf(he_cl, &hpp, hpp_list); |
| 2072 | fprintf(out, "%s\n", bf); |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 2073 | fprintf(out, " -------------------------------------------------------------\n"); |
Jiri Olsa | 2d388bd | 2016-05-03 14:32:56 +0200 | [diff] [blame] | 2074 | |
| 2075 | hists__fprintf(&c2c_hists->hists, false, 0, 0, 0, out, true); |
| 2076 | } |
| 2077 | |
| 2078 | static void print_pareto(FILE *out) |
| 2079 | { |
| 2080 | struct perf_hpp_list hpp_list; |
| 2081 | struct rb_node *nd; |
| 2082 | int ret; |
| 2083 | |
| 2084 | perf_hpp_list__init(&hpp_list); |
| 2085 | ret = hpp_list__parse(&hpp_list, |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 2086 | "cl_num," |
Jiri Olsa | 2d388bd | 2016-05-03 14:32:56 +0200 | [diff] [blame] | 2087 | "cl_rmt_hitm," |
| 2088 | "cl_lcl_hitm," |
| 2089 | "cl_stores_l1hit," |
| 2090 | "cl_stores_l1miss," |
| 2091 | "dcacheline", |
| 2092 | NULL); |
| 2093 | |
| 2094 | if (WARN_ONCE(ret, "failed to setup sort entries\n")) |
| 2095 | return; |
| 2096 | |
| 2097 | nd = rb_first(&c2c.hists.hists.entries); |
| 2098 | |
| 2099 | for (; nd; nd = rb_next(nd)) { |
| 2100 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
| 2101 | struct c2c_hist_entry *c2c_he; |
| 2102 | |
| 2103 | if (he->filtered) |
| 2104 | continue; |
| 2105 | |
| 2106 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 2107 | print_cacheline(c2c_he->hists, he, &hpp_list, out); |
| 2108 | } |
| 2109 | } |
| 2110 | |
Jiri Olsa | 2709b97 | 2016-08-27 11:40:23 +0200 | [diff] [blame] | 2111 | static void print_c2c_info(FILE *out, struct perf_session *session) |
| 2112 | { |
| 2113 | struct perf_evlist *evlist = session->evlist; |
| 2114 | struct perf_evsel *evsel; |
| 2115 | bool first = true; |
| 2116 | |
| 2117 | fprintf(out, "=================================================\n"); |
| 2118 | fprintf(out, " c2c details \n"); |
| 2119 | fprintf(out, "=================================================\n"); |
| 2120 | |
| 2121 | evlist__for_each_entry(evlist, evsel) { |
| 2122 | fprintf(out, "%-36s: %s\n", first ? " Events" : "", |
| 2123 | perf_evsel__name(evsel)); |
| 2124 | first = false; |
| 2125 | } |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 2126 | fprintf(out, " Cachelines sort on : %s HITMs\n", |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 2127 | display_str[c2c.display]); |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2128 | fprintf(out, " Cacheline data grouping : %s\n", c2c.cl_sort); |
Jiri Olsa | 2709b97 | 2016-08-27 11:40:23 +0200 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | static void perf_c2c__hists_fprintf(FILE *out, struct perf_session *session) |
Jiri Olsa | 2d388bd | 2016-05-03 14:32:56 +0200 | [diff] [blame] | 2132 | { |
| 2133 | setup_pager(); |
| 2134 | |
Jiri Olsa | 74c63a2 | 2016-05-02 20:01:59 +0200 | [diff] [blame] | 2135 | print_c2c__display_stats(out); |
Jiri Olsa | 7ef2efa | 2016-07-01 11:12:11 +0200 | [diff] [blame] | 2136 | fprintf(out, "\n"); |
| 2137 | print_shared_cacheline_info(out); |
Jiri Olsa | 2709b97 | 2016-08-27 11:40:23 +0200 | [diff] [blame] | 2138 | fprintf(out, "\n"); |
| 2139 | print_c2c_info(out, session); |
Jiri Olsa | 74c63a2 | 2016-05-02 20:01:59 +0200 | [diff] [blame] | 2140 | |
| 2141 | if (c2c.stats_only) |
| 2142 | return; |
| 2143 | |
Jiri Olsa | 2d388bd | 2016-05-03 14:32:56 +0200 | [diff] [blame] | 2144 | fprintf(out, "\n"); |
| 2145 | fprintf(out, "=================================================\n"); |
| 2146 | fprintf(out, " Shared Data Cache Line Table \n"); |
| 2147 | fprintf(out, "=================================================\n"); |
| 2148 | fprintf(out, "#\n"); |
| 2149 | |
| 2150 | hists__fprintf(&c2c.hists.hists, true, 0, 0, 0, stdout, false); |
| 2151 | |
| 2152 | fprintf(out, "\n"); |
| 2153 | fprintf(out, "=================================================\n"); |
| 2154 | fprintf(out, " Shared Cache Line Distribution Pareto \n"); |
| 2155 | fprintf(out, "=================================================\n"); |
| 2156 | fprintf(out, "#\n"); |
| 2157 | |
| 2158 | print_pareto(out); |
| 2159 | } |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 2160 | |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2161 | #ifdef HAVE_SLANG_SUPPORT |
| 2162 | static void c2c_browser__update_nr_entries(struct hist_browser *hb) |
| 2163 | { |
| 2164 | u64 nr_entries = 0; |
| 2165 | struct rb_node *nd = rb_first(&hb->hists->entries); |
| 2166 | |
| 2167 | while (nd) { |
| 2168 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
| 2169 | |
| 2170 | if (!he->filtered) |
| 2171 | nr_entries++; |
| 2172 | |
| 2173 | nd = rb_next(nd); |
| 2174 | } |
| 2175 | |
| 2176 | hb->nr_non_filtered_entries = nr_entries; |
| 2177 | } |
| 2178 | |
Jiri Olsa | f1c5fd4 | 2016-05-02 18:30:44 +0200 | [diff] [blame] | 2179 | struct c2c_cacheline_browser { |
| 2180 | struct hist_browser hb; |
| 2181 | struct hist_entry *he; |
| 2182 | }; |
| 2183 | |
| 2184 | static int |
| 2185 | perf_c2c_cacheline_browser__title(struct hist_browser *browser, |
| 2186 | char *bf, size_t size) |
| 2187 | { |
| 2188 | struct c2c_cacheline_browser *cl_browser; |
| 2189 | struct hist_entry *he; |
| 2190 | uint64_t addr = 0; |
| 2191 | |
| 2192 | cl_browser = container_of(browser, struct c2c_cacheline_browser, hb); |
| 2193 | he = cl_browser->he; |
| 2194 | |
| 2195 | if (he->mem_info) |
| 2196 | addr = cl_address(he->mem_info->daddr.addr); |
| 2197 | |
| 2198 | scnprintf(bf, size, "Cacheline 0x%lx", addr); |
| 2199 | return 0; |
| 2200 | } |
| 2201 | |
| 2202 | static struct c2c_cacheline_browser* |
| 2203 | c2c_cacheline_browser__new(struct hists *hists, struct hist_entry *he) |
| 2204 | { |
| 2205 | struct c2c_cacheline_browser *browser; |
| 2206 | |
| 2207 | browser = zalloc(sizeof(*browser)); |
| 2208 | if (browser) { |
| 2209 | hist_browser__init(&browser->hb, hists); |
| 2210 | browser->hb.c2c_filter = true; |
| 2211 | browser->hb.title = perf_c2c_cacheline_browser__title; |
| 2212 | browser->he = he; |
| 2213 | } |
| 2214 | |
| 2215 | return browser; |
| 2216 | } |
| 2217 | |
| 2218 | static int perf_c2c__browse_cacheline(struct hist_entry *he) |
| 2219 | { |
| 2220 | struct c2c_hist_entry *c2c_he; |
| 2221 | struct c2c_hists *c2c_hists; |
| 2222 | struct c2c_cacheline_browser *cl_browser; |
| 2223 | struct hist_browser *browser; |
| 2224 | int key = -1; |
Jiri Olsa | 9a406eb | 2016-08-17 15:54:58 +0200 | [diff] [blame] | 2225 | const char help[] = |
Kim Phillips | 239fb4f | 2017-11-14 15:04:47 -0600 | [diff] [blame] | 2226 | " ENTER Toggle callchains (if present) \n" |
| 2227 | " n Toggle Node details info \n" |
| 2228 | " s Toggle full length of symbol and source line columns \n" |
Jiri Olsa | 9a406eb | 2016-08-17 15:54:58 +0200 | [diff] [blame] | 2229 | " q Return back to cacheline list \n"; |
Jiri Olsa | f1c5fd4 | 2016-05-02 18:30:44 +0200 | [diff] [blame] | 2230 | |
Jiri Olsa | 590b6a3 | 2016-07-10 16:25:15 +0200 | [diff] [blame] | 2231 | /* Display compact version first. */ |
| 2232 | c2c.symbol_full = false; |
| 2233 | |
Jiri Olsa | f1c5fd4 | 2016-05-02 18:30:44 +0200 | [diff] [blame] | 2234 | c2c_he = container_of(he, struct c2c_hist_entry, he); |
| 2235 | c2c_hists = c2c_he->hists; |
| 2236 | |
| 2237 | cl_browser = c2c_cacheline_browser__new(&c2c_hists->hists, he); |
| 2238 | if (cl_browser == NULL) |
| 2239 | return -1; |
| 2240 | |
| 2241 | browser = &cl_browser->hb; |
| 2242 | |
| 2243 | /* reset abort key so that it can get Ctrl-C as a key */ |
| 2244 | SLang_reset_tty(); |
| 2245 | SLang_init_tty(0, 0, 0); |
| 2246 | |
| 2247 | c2c_browser__update_nr_entries(browser); |
| 2248 | |
| 2249 | while (1) { |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame] | 2250 | key = hist_browser__run(browser, "? - help", true); |
Jiri Olsa | f1c5fd4 | 2016-05-02 18:30:44 +0200 | [diff] [blame] | 2251 | |
| 2252 | switch (key) { |
Jiri Olsa | 590b6a3 | 2016-07-10 16:25:15 +0200 | [diff] [blame] | 2253 | case 's': |
| 2254 | c2c.symbol_full = !c2c.symbol_full; |
| 2255 | break; |
Jiri Olsa | 1a56a42 | 2016-07-10 16:30:27 +0200 | [diff] [blame] | 2256 | case 'n': |
| 2257 | c2c.node_info = (c2c.node_info + 1) % 3; |
| 2258 | setup_nodes_header(); |
| 2259 | break; |
Jiri Olsa | f1c5fd4 | 2016-05-02 18:30:44 +0200 | [diff] [blame] | 2260 | case 'q': |
| 2261 | goto out; |
Jiri Olsa | 9a406eb | 2016-08-17 15:54:58 +0200 | [diff] [blame] | 2262 | case '?': |
| 2263 | ui_browser__help_window(&browser->b, help); |
| 2264 | break; |
Jiri Olsa | f1c5fd4 | 2016-05-02 18:30:44 +0200 | [diff] [blame] | 2265 | default: |
| 2266 | break; |
| 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | out: |
| 2271 | free(cl_browser); |
| 2272 | return 0; |
| 2273 | } |
| 2274 | |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2275 | static int perf_c2c_browser__title(struct hist_browser *browser, |
| 2276 | char *bf, size_t size) |
| 2277 | { |
| 2278 | scnprintf(bf, size, |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 2279 | "Shared Data Cache Line Table " |
| 2280 | "(%lu entries, sorted on %s HITMs)", |
| 2281 | browser->nr_non_filtered_entries, |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 2282 | display_str[c2c.display]); |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2283 | return 0; |
| 2284 | } |
| 2285 | |
| 2286 | static struct hist_browser* |
| 2287 | perf_c2c_browser__new(struct hists *hists) |
| 2288 | { |
| 2289 | struct hist_browser *browser = hist_browser__new(hists); |
| 2290 | |
| 2291 | if (browser) { |
| 2292 | browser->title = perf_c2c_browser__title; |
| 2293 | browser->c2c_filter = true; |
| 2294 | } |
| 2295 | |
| 2296 | return browser; |
| 2297 | } |
| 2298 | |
| 2299 | static int perf_c2c__hists_browse(struct hists *hists) |
| 2300 | { |
| 2301 | struct hist_browser *browser; |
| 2302 | int key = -1; |
Jiri Olsa | 9a406eb | 2016-08-17 15:54:58 +0200 | [diff] [blame] | 2303 | const char help[] = |
| 2304 | " d Display cacheline details \n" |
Kim Phillips | 239fb4f | 2017-11-14 15:04:47 -0600 | [diff] [blame] | 2305 | " ENTER Toggle callchains (if present) \n" |
Jiri Olsa | 9a406eb | 2016-08-17 15:54:58 +0200 | [diff] [blame] | 2306 | " q Quit \n"; |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2307 | |
| 2308 | browser = perf_c2c_browser__new(hists); |
| 2309 | if (browser == NULL) |
| 2310 | return -1; |
| 2311 | |
| 2312 | /* reset abort key so that it can get Ctrl-C as a key */ |
| 2313 | SLang_reset_tty(); |
| 2314 | SLang_init_tty(0, 0, 0); |
| 2315 | |
| 2316 | c2c_browser__update_nr_entries(browser); |
| 2317 | |
| 2318 | while (1) { |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame] | 2319 | key = hist_browser__run(browser, "? - help", true); |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2320 | |
| 2321 | switch (key) { |
| 2322 | case 'q': |
| 2323 | goto out; |
Jiri Olsa | f1c5fd4 | 2016-05-02 18:30:44 +0200 | [diff] [blame] | 2324 | case 'd': |
| 2325 | perf_c2c__browse_cacheline(browser->he_selection); |
| 2326 | break; |
Jiri Olsa | 9a406eb | 2016-08-17 15:54:58 +0200 | [diff] [blame] | 2327 | case '?': |
| 2328 | ui_browser__help_window(&browser->b, help); |
| 2329 | break; |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2330 | default: |
| 2331 | break; |
| 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | out: |
| 2336 | hist_browser__delete(browser); |
| 2337 | return 0; |
| 2338 | } |
| 2339 | |
Jiri Olsa | 2709b97 | 2016-08-27 11:40:23 +0200 | [diff] [blame] | 2340 | static void perf_c2c_display(struct perf_session *session) |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2341 | { |
Namhyung Kim | 1936fea | 2017-03-08 00:08:33 +0900 | [diff] [blame] | 2342 | if (use_browser == 0) |
Jiri Olsa | 2709b97 | 2016-08-27 11:40:23 +0200 | [diff] [blame] | 2343 | perf_c2c__hists_fprintf(stdout, session); |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2344 | else |
| 2345 | perf_c2c__hists_browse(&c2c.hists.hists); |
| 2346 | } |
| 2347 | #else |
Jiri Olsa | 2709b97 | 2016-08-27 11:40:23 +0200 | [diff] [blame] | 2348 | static void perf_c2c_display(struct perf_session *session) |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2349 | { |
| 2350 | use_browser = 0; |
Jiri Olsa | 2709b97 | 2016-08-27 11:40:23 +0200 | [diff] [blame] | 2351 | perf_c2c__hists_fprintf(stdout, session); |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2352 | } |
| 2353 | #endif /* HAVE_SLANG_SUPPORT */ |
| 2354 | |
| 2355 | static void ui_quirks(void) |
| 2356 | { |
| 2357 | if (!c2c.use_stdio) { |
| 2358 | dim_offset.width = 5; |
| 2359 | dim_offset.header = header_offset_tui; |
| 2360 | } |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 2361 | |
| 2362 | dim_percent_hitm.header = percent_hitm_header[c2c.display]; |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2363 | } |
| 2364 | |
Jiri Olsa | dd80576 | 2016-05-11 18:23:48 +0200 | [diff] [blame] | 2365 | #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent" |
| 2366 | |
| 2367 | const char callchain_help[] = "Display call graph (stack chain/backtrace):\n\n" |
| 2368 | CALLCHAIN_REPORT_HELP |
| 2369 | "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT; |
| 2370 | |
| 2371 | static int |
| 2372 | parse_callchain_opt(const struct option *opt, const char *arg, int unset) |
| 2373 | { |
| 2374 | struct callchain_param *callchain = opt->value; |
| 2375 | |
| 2376 | callchain->enabled = !unset; |
| 2377 | /* |
| 2378 | * --no-call-graph |
| 2379 | */ |
| 2380 | if (unset) { |
| 2381 | symbol_conf.use_callchain = false; |
| 2382 | callchain->mode = CHAIN_NONE; |
| 2383 | return 0; |
| 2384 | } |
| 2385 | |
| 2386 | return parse_callchain_report_opt(arg); |
| 2387 | } |
| 2388 | |
| 2389 | static int setup_callchain(struct perf_evlist *evlist) |
| 2390 | { |
| 2391 | u64 sample_type = perf_evlist__combined_sample_type(evlist); |
| 2392 | enum perf_call_graph_mode mode = CALLCHAIN_NONE; |
| 2393 | |
| 2394 | if ((sample_type & PERF_SAMPLE_REGS_USER) && |
Arnaldo Carvalho de Melo | eabad8c | 2018-01-15 16:48:46 -0300 | [diff] [blame] | 2395 | (sample_type & PERF_SAMPLE_STACK_USER)) { |
Jiri Olsa | dd80576 | 2016-05-11 18:23:48 +0200 | [diff] [blame] | 2396 | mode = CALLCHAIN_DWARF; |
Arnaldo Carvalho de Melo | eabad8c | 2018-01-15 16:48:46 -0300 | [diff] [blame] | 2397 | dwarf_callchain_users = true; |
| 2398 | } else if (sample_type & PERF_SAMPLE_BRANCH_STACK) |
Jiri Olsa | dd80576 | 2016-05-11 18:23:48 +0200 | [diff] [blame] | 2399 | mode = CALLCHAIN_LBR; |
| 2400 | else if (sample_type & PERF_SAMPLE_CALLCHAIN) |
| 2401 | mode = CALLCHAIN_FP; |
| 2402 | |
| 2403 | if (!callchain_param.enabled && |
| 2404 | callchain_param.mode != CHAIN_NONE && |
| 2405 | mode != CALLCHAIN_NONE) { |
| 2406 | symbol_conf.use_callchain = true; |
| 2407 | if (callchain_register_param(&callchain_param) < 0) { |
| 2408 | ui__error("Can't register callchain params.\n"); |
| 2409 | return -EINVAL; |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | callchain_param.record_mode = mode; |
| 2414 | callchain_param.min_percent = 0; |
| 2415 | return 0; |
| 2416 | } |
| 2417 | |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 2418 | static int setup_display(const char *str) |
| 2419 | { |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 2420 | const char *display = str ?: "tot"; |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 2421 | |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 2422 | if (!strcmp(display, "tot")) |
| 2423 | c2c.display = DISPLAY_TOT; |
| 2424 | else if (!strcmp(display, "rmt")) |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 2425 | c2c.display = DISPLAY_RMT; |
| 2426 | else if (!strcmp(display, "lcl")) |
| 2427 | c2c.display = DISPLAY_LCL; |
| 2428 | else { |
| 2429 | pr_err("failed: unknown display type: %s\n", str); |
| 2430 | return -1; |
| 2431 | } |
| 2432 | |
| 2433 | return 0; |
| 2434 | } |
| 2435 | |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2436 | #define for_each_token(__tok, __buf, __sep, __tmp) \ |
| 2437 | for (__tok = strtok_r(__buf, __sep, &__tmp); __tok; \ |
| 2438 | __tok = strtok_r(NULL, __sep, &__tmp)) |
| 2439 | |
Jiri Olsa | 18f278d | 2016-10-11 13:39:47 +0200 | [diff] [blame] | 2440 | static int build_cl_output(char *cl_sort, bool no_source) |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2441 | { |
| 2442 | char *tok, *tmp, *buf = strdup(cl_sort); |
| 2443 | bool add_pid = false; |
| 2444 | bool add_tid = false; |
| 2445 | bool add_iaddr = false; |
| 2446 | bool add_sym = false; |
| 2447 | bool add_dso = false; |
| 2448 | bool add_src = false; |
| 2449 | |
| 2450 | if (!buf) |
| 2451 | return -ENOMEM; |
| 2452 | |
| 2453 | for_each_token(tok, buf, ",", tmp) { |
| 2454 | if (!strcmp(tok, "tid")) { |
| 2455 | add_tid = true; |
| 2456 | } else if (!strcmp(tok, "pid")) { |
| 2457 | add_pid = true; |
| 2458 | } else if (!strcmp(tok, "iaddr")) { |
| 2459 | add_iaddr = true; |
| 2460 | add_sym = true; |
| 2461 | add_dso = true; |
Jiri Olsa | 18f278d | 2016-10-11 13:39:47 +0200 | [diff] [blame] | 2462 | add_src = no_source ? false : true; |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2463 | } else if (!strcmp(tok, "dso")) { |
| 2464 | add_dso = true; |
| 2465 | } else if (strcmp(tok, "offset")) { |
| 2466 | pr_err("unrecognized sort token: %s\n", tok); |
| 2467 | return -EINVAL; |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | if (asprintf(&c2c.cl_output, |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 2472 | "%s%s%s%s%s%s%s%s%s%s", |
| 2473 | c2c.use_stdio ? "cl_num_empty," : "", |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2474 | "percent_rmt_hitm," |
| 2475 | "percent_lcl_hitm," |
| 2476 | "percent_stores_l1hit," |
| 2477 | "percent_stores_l1miss," |
| 2478 | "offset,", |
| 2479 | add_pid ? "pid," : "", |
| 2480 | add_tid ? "tid," : "", |
| 2481 | add_iaddr ? "iaddr," : "", |
| 2482 | "mean_rmt," |
| 2483 | "mean_lcl," |
| 2484 | "mean_load," |
Jiri Olsa | 8763e6a | 2017-01-20 10:20:31 +0100 | [diff] [blame] | 2485 | "tot_recs," |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2486 | "cpucnt,", |
| 2487 | add_sym ? "symbol," : "", |
| 2488 | add_dso ? "dso," : "", |
| 2489 | add_src ? "cl_srcline," : "", |
| 2490 | "node") < 0) |
| 2491 | return -ENOMEM; |
| 2492 | |
| 2493 | c2c.show_src = add_src; |
| 2494 | |
| 2495 | free(buf); |
| 2496 | return 0; |
| 2497 | } |
| 2498 | |
Jiri Olsa | 18f278d | 2016-10-11 13:39:47 +0200 | [diff] [blame] | 2499 | static int setup_coalesce(const char *coalesce, bool no_source) |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2500 | { |
| 2501 | const char *c = coalesce ?: coalesce_default; |
| 2502 | |
| 2503 | if (asprintf(&c2c.cl_sort, "offset,%s", c) < 0) |
| 2504 | return -ENOMEM; |
| 2505 | |
Jiri Olsa | 18f278d | 2016-10-11 13:39:47 +0200 | [diff] [blame] | 2506 | if (build_cl_output(c2c.cl_sort, no_source)) |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2507 | return -1; |
| 2508 | |
| 2509 | if (asprintf(&c2c.cl_resort, "offset,%s", |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 2510 | c2c.display == DISPLAY_TOT ? |
| 2511 | "tot_hitm" : |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2512 | c2c.display == DISPLAY_RMT ? |
| 2513 | "rmt_hitm,lcl_hitm" : |
| 2514 | "lcl_hitm,rmt_hitm") < 0) |
| 2515 | return -ENOMEM; |
| 2516 | |
| 2517 | pr_debug("coalesce sort fields: %s\n", c2c.cl_sort); |
| 2518 | pr_debug("coalesce resort fields: %s\n", c2c.cl_resort); |
| 2519 | pr_debug("coalesce output fields: %s\n", c2c.cl_output); |
| 2520 | return 0; |
| 2521 | } |
| 2522 | |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2523 | static int perf_c2c__report(int argc, const char **argv) |
| 2524 | { |
| 2525 | struct perf_session *session; |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 2526 | struct ui_progress prog; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2527 | struct perf_data data = { |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2528 | .mode = PERF_DATA_MODE_READ, |
| 2529 | }; |
Jiri Olsa | dd80576 | 2016-05-11 18:23:48 +0200 | [diff] [blame] | 2530 | char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT; |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 2531 | const char *display = NULL; |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2532 | const char *coalesce = NULL; |
Jiri Olsa | 18f278d | 2016-10-11 13:39:47 +0200 | [diff] [blame] | 2533 | bool no_source = false; |
Jiri Olsa | 3a5bfab | 2016-11-21 22:33:31 +0100 | [diff] [blame] | 2534 | const struct option options[] = { |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2535 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
| 2536 | "file", "vmlinux pathname"), |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2537 | OPT_STRING('i', "input", &input_name, "file", |
| 2538 | "the input file to process"), |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 2539 | OPT_INCR('N', "node-info", &c2c.node_info, |
| 2540 | "show extra node info in report (repeat for more info)"), |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2541 | #ifdef HAVE_SLANG_SUPPORT |
| 2542 | OPT_BOOLEAN(0, "stdio", &c2c.use_stdio, "Use the stdio interface"), |
| 2543 | #endif |
Jiri Olsa | 74c63a2 | 2016-05-02 20:01:59 +0200 | [diff] [blame] | 2544 | OPT_BOOLEAN(0, "stats", &c2c.stats_only, |
Namhyung Kim | f75d289 | 2017-03-08 00:08:32 +0900 | [diff] [blame] | 2545 | "Display only statistic tables (implies --stdio)"), |
Jiri Olsa | 590b6a3 | 2016-07-10 16:25:15 +0200 | [diff] [blame] | 2546 | OPT_BOOLEAN(0, "full-symbols", &c2c.symbol_full, |
| 2547 | "Display full length of symbols"), |
Jiri Olsa | 18f278d | 2016-10-11 13:39:47 +0200 | [diff] [blame] | 2548 | OPT_BOOLEAN(0, "no-source", &no_source, |
| 2549 | "Do not display Source Line column"), |
Jiri Olsa | af09b2d | 2016-10-11 13:52:05 +0200 | [diff] [blame] | 2550 | OPT_BOOLEAN(0, "show-all", &c2c.show_all, |
| 2551 | "Show all captured HITM lines."), |
Jiri Olsa | dd80576 | 2016-05-11 18:23:48 +0200 | [diff] [blame] | 2552 | OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param, |
| 2553 | "print_type,threshold[,print_limit],order,sort_key[,branch],value", |
| 2554 | callchain_help, &parse_callchain_opt, |
| 2555 | callchain_default_opt), |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 2556 | OPT_STRING('d', "display", &display, "Switch HITM output type", "lcl,rmt"), |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2557 | OPT_STRING('c', "coalesce", &coalesce, "coalesce fields", |
| 2558 | "coalesce fields: pid,tid,iaddr,dso"), |
Jiri Olsa | b7ac4f9 | 2016-11-21 22:33:28 +0100 | [diff] [blame] | 2559 | OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), |
Jiri Olsa | 3a5bfab | 2016-11-21 22:33:31 +0100 | [diff] [blame] | 2560 | OPT_PARENT(c2c_options), |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2561 | OPT_END() |
| 2562 | }; |
| 2563 | int err = 0; |
| 2564 | |
Jiri Olsa | 3a5bfab | 2016-11-21 22:33:31 +0100 | [diff] [blame] | 2565 | argc = parse_options(argc, argv, options, report_c2c_usage, |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2566 | PARSE_OPT_STOP_AT_NON_OPTION); |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 2567 | if (argc) |
Jiri Olsa | 3a5bfab | 2016-11-21 22:33:31 +0100 | [diff] [blame] | 2568 | usage_with_options(report_c2c_usage, options); |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2569 | |
Jiri Olsa | 74c63a2 | 2016-05-02 20:01:59 +0200 | [diff] [blame] | 2570 | if (c2c.stats_only) |
| 2571 | c2c.use_stdio = true; |
| 2572 | |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 2573 | if (!input_name || !strlen(input_name)) |
| 2574 | input_name = "perf.data"; |
| 2575 | |
Jiri Olsa | eae8ad8 | 2017-01-23 22:25:41 +0100 | [diff] [blame] | 2576 | data.file.path = input_name; |
| 2577 | data.force = symbol_conf.force; |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2578 | |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 2579 | err = setup_display(display); |
| 2580 | if (err) |
| 2581 | goto out; |
| 2582 | |
Jiri Olsa | 18f278d | 2016-10-11 13:39:47 +0200 | [diff] [blame] | 2583 | err = setup_coalesce(coalesce, no_source); |
Jiri Olsa | fc9c630 | 2016-05-24 14:14:38 +0200 | [diff] [blame] | 2584 | if (err) { |
| 2585 | pr_debug("Failed to initialize hists\n"); |
| 2586 | goto out; |
| 2587 | } |
| 2588 | |
Jiri Olsa | 1d62fcd | 2016-05-24 10:12:31 +0200 | [diff] [blame] | 2589 | err = c2c_hists__init(&c2c.hists, "dcacheline", 2); |
Jiri Olsa | c75540e | 2016-09-22 17:36:41 +0200 | [diff] [blame] | 2590 | if (err) { |
| 2591 | pr_debug("Failed to initialize hists\n"); |
| 2592 | goto out; |
| 2593 | } |
| 2594 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2595 | session = perf_session__new(&data, 0, &c2c.tool); |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2596 | if (session == NULL) { |
| 2597 | pr_debug("No memory for session\n"); |
| 2598 | goto out; |
| 2599 | } |
Jiri Olsa | e8c5fe1 | 2016-11-21 22:33:27 +0100 | [diff] [blame] | 2600 | |
Jiri Olsa | 1e181b9 | 2016-06-03 15:40:28 +0200 | [diff] [blame] | 2601 | err = setup_nodes(session); |
| 2602 | if (err) { |
| 2603 | pr_err("Failed setup nodes\n"); |
| 2604 | goto out; |
| 2605 | } |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2606 | |
Jiri Olsa | dd80576 | 2016-05-11 18:23:48 +0200 | [diff] [blame] | 2607 | err = setup_callchain(session->evlist); |
| 2608 | if (err) |
| 2609 | goto out_session; |
| 2610 | |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2611 | if (symbol__init(&session->header.env) < 0) |
| 2612 | goto out_session; |
| 2613 | |
| 2614 | /* No pipe support at the moment. */ |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2615 | if (perf_data__is_pipe(session->data)) { |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2616 | pr_debug("No pipe support at the moment.\n"); |
| 2617 | goto out_session; |
| 2618 | } |
| 2619 | |
Jiri Olsa | e8c5fe1 | 2016-11-21 22:33:27 +0100 | [diff] [blame] | 2620 | if (c2c.use_stdio) |
| 2621 | use_browser = 0; |
| 2622 | else |
| 2623 | use_browser = 1; |
| 2624 | |
| 2625 | setup_browser(false); |
| 2626 | |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 2627 | err = perf_session__process_events(session); |
| 2628 | if (err) { |
| 2629 | pr_err("failed to process sample\n"); |
| 2630 | goto out_session; |
| 2631 | } |
| 2632 | |
Jiri Olsa | 22dd59d | 2016-05-10 14:08:29 +0200 | [diff] [blame] | 2633 | c2c_hists__reinit(&c2c.hists, |
Jiri Olsa | bb342dae | 2016-07-06 15:40:09 +0200 | [diff] [blame] | 2634 | "cl_idx," |
Jiri Olsa | 22dd59d | 2016-05-10 14:08:29 +0200 | [diff] [blame] | 2635 | "dcacheline," |
| 2636 | "tot_recs," |
| 2637 | "percent_hitm," |
| 2638 | "tot_hitm,lcl_hitm,rmt_hitm," |
| 2639 | "stores,stores_l1hit,stores_l1miss," |
| 2640 | "dram_lcl,dram_rmt," |
| 2641 | "ld_llcmiss," |
| 2642 | "tot_loads," |
| 2643 | "ld_fbhit,ld_l1hit,ld_l2hit," |
| 2644 | "ld_lclhit,ld_rmthit", |
Jiri Olsa | d940bac | 2016-11-21 22:33:30 +0100 | [diff] [blame] | 2645 | c2c.display == DISPLAY_TOT ? "tot_hitm" : |
Jiri Olsa | 55b9577 | 2016-05-29 10:21:45 +0200 | [diff] [blame] | 2646 | c2c.display == DISPLAY_LCL ? "lcl_hitm" : "rmt_hitm" |
Jiri Olsa | 22dd59d | 2016-05-10 14:08:29 +0200 | [diff] [blame] | 2647 | ); |
| 2648 | |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 2649 | ui_progress__init(&prog, c2c.hists.hists.nr_entries, "Sorting..."); |
| 2650 | |
| 2651 | hists__collapse_resort(&c2c.hists.hists, NULL); |
Jiri Olsa | 7ef2efa | 2016-07-01 11:12:11 +0200 | [diff] [blame] | 2652 | hists__output_resort_cb(&c2c.hists.hists, &prog, resort_hitm_cb); |
| 2653 | hists__iterate_cb(&c2c.hists.hists, resort_cl_cb); |
Jiri Olsa | 78b2754 | 2016-09-22 17:36:44 +0200 | [diff] [blame] | 2654 | |
| 2655 | ui_progress__finish(); |
| 2656 | |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 2657 | ui_quirks(); |
| 2658 | |
Jiri Olsa | 2709b97 | 2016-08-27 11:40:23 +0200 | [diff] [blame] | 2659 | perf_c2c_display(session); |
Jiri Olsa | 2d388bd | 2016-05-03 14:32:56 +0200 | [diff] [blame] | 2660 | |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2661 | out_session: |
| 2662 | perf_session__delete(session); |
| 2663 | out: |
| 2664 | return err; |
| 2665 | } |
| 2666 | |
Arnaldo Carvalho de Melo | 7e6a799 | 2016-12-12 10:52:10 -0300 | [diff] [blame] | 2667 | static int parse_record_events(const struct option *opt, |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 2668 | const char *str, int unset __maybe_unused) |
| 2669 | { |
| 2670 | bool *event_set = (bool *) opt->value; |
| 2671 | |
| 2672 | *event_set = true; |
| 2673 | return perf_mem_events__parse(str); |
| 2674 | } |
| 2675 | |
| 2676 | |
| 2677 | static const char * const __usage_record[] = { |
| 2678 | "perf c2c record [<options>] [<command>]", |
| 2679 | "perf c2c record [<options>] -- <command> [<options>]", |
| 2680 | NULL |
| 2681 | }; |
| 2682 | |
| 2683 | static const char * const *record_mem_usage = __usage_record; |
| 2684 | |
| 2685 | static int perf_c2c__record(int argc, const char **argv) |
| 2686 | { |
| 2687 | int rec_argc, i = 0, j; |
| 2688 | const char **rec_argv; |
| 2689 | int ret; |
| 2690 | bool all_user = false, all_kernel = false; |
| 2691 | bool event_set = false; |
| 2692 | struct option options[] = { |
| 2693 | OPT_CALLBACK('e', "event", &event_set, "event", |
| 2694 | "event selector. Use 'perf mem record -e list' to list available events", |
| 2695 | parse_record_events), |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 2696 | OPT_BOOLEAN('u', "all-user", &all_user, "collect only user level data"), |
| 2697 | OPT_BOOLEAN('k', "all-kernel", &all_kernel, "collect only kernel level data"), |
| 2698 | OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat, "setup mem-loads latency"), |
Jiri Olsa | 3a5bfab | 2016-11-21 22:33:31 +0100 | [diff] [blame] | 2699 | OPT_PARENT(c2c_options), |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 2700 | OPT_END() |
| 2701 | }; |
| 2702 | |
| 2703 | if (perf_mem_events__init()) { |
| 2704 | pr_err("failed: memory events not supported\n"); |
| 2705 | return -1; |
| 2706 | } |
| 2707 | |
| 2708 | argc = parse_options(argc, argv, options, record_mem_usage, |
| 2709 | PARSE_OPT_KEEP_UNKNOWN); |
| 2710 | |
Jiri Olsa | 8fab784 | 2018-03-09 11:14:37 +0100 | [diff] [blame] | 2711 | rec_argc = argc + 11; /* max number of arguments */ |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 2712 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 2713 | if (!rec_argv) |
| 2714 | return -1; |
| 2715 | |
| 2716 | rec_argv[i++] = "record"; |
| 2717 | |
| 2718 | if (!event_set) { |
| 2719 | perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true; |
| 2720 | perf_mem_events[PERF_MEM_EVENTS__STORE].record = true; |
| 2721 | } |
| 2722 | |
| 2723 | if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record) |
| 2724 | rec_argv[i++] = "-W"; |
| 2725 | |
| 2726 | rec_argv[i++] = "-d"; |
Jiri Olsa | 8fab784 | 2018-03-09 11:14:37 +0100 | [diff] [blame] | 2727 | rec_argv[i++] = "--phys-data"; |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 2728 | rec_argv[i++] = "--sample-cpu"; |
| 2729 | |
| 2730 | for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { |
| 2731 | if (!perf_mem_events[j].record) |
| 2732 | continue; |
| 2733 | |
| 2734 | if (!perf_mem_events[j].supported) { |
| 2735 | pr_err("failed: event '%s' not supported\n", |
| 2736 | perf_mem_events[j].name); |
Martin Kepplinger | c896f85 | 2017-09-13 21:14:19 +0200 | [diff] [blame] | 2737 | free(rec_argv); |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 2738 | return -1; |
| 2739 | } |
| 2740 | |
| 2741 | rec_argv[i++] = "-e"; |
| 2742 | rec_argv[i++] = perf_mem_events__name(j); |
| 2743 | }; |
| 2744 | |
| 2745 | if (all_user) |
| 2746 | rec_argv[i++] = "--all-user"; |
| 2747 | |
| 2748 | if (all_kernel) |
| 2749 | rec_argv[i++] = "--all-kernel"; |
| 2750 | |
| 2751 | for (j = 0; j < argc; j++, i++) |
| 2752 | rec_argv[i] = argv[j]; |
| 2753 | |
| 2754 | if (verbose > 0) { |
| 2755 | pr_debug("calling: "); |
| 2756 | |
| 2757 | j = 0; |
| 2758 | |
| 2759 | while (rec_argv[j]) { |
| 2760 | pr_debug("%s ", rec_argv[j]); |
| 2761 | j++; |
| 2762 | } |
| 2763 | pr_debug("\n"); |
| 2764 | } |
| 2765 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 2766 | ret = cmd_record(i, rec_argv); |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 2767 | free(rec_argv); |
| 2768 | return ret; |
| 2769 | } |
| 2770 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 2771 | int cmd_c2c(int argc, const char **argv) |
Jiri Olsa | 7aef3bf | 2016-09-22 17:36:38 +0200 | [diff] [blame] | 2772 | { |
Jiri Olsa | 7aef3bf | 2016-09-22 17:36:38 +0200 | [diff] [blame] | 2773 | argc = parse_options(argc, argv, c2c_options, c2c_usage, |
| 2774 | PARSE_OPT_STOP_AT_NON_OPTION); |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 2775 | |
| 2776 | if (!argc) |
| 2777 | usage_with_options(c2c_usage, c2c_options); |
| 2778 | |
| 2779 | if (!strncmp(argv[0], "rec", 3)) { |
| 2780 | return perf_c2c__record(argc, argv); |
Jiri Olsa | 903a6f1 | 2016-09-22 17:36:40 +0200 | [diff] [blame] | 2781 | } else if (!strncmp(argv[0], "rep", 3)) { |
| 2782 | return perf_c2c__report(argc, argv); |
Jiri Olsa | 39bcd4a | 2016-09-22 17:36:39 +0200 | [diff] [blame] | 2783 | } else { |
| 2784 | usage_with_options(c2c_usage, c2c_options); |
| 2785 | } |
| 2786 | |
Jiri Olsa | 7aef3bf | 2016-09-22 17:36:38 +0200 | [diff] [blame] | 2787 | return 0; |
| 2788 | } |