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