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