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