blob: 17855c4626a08b7d4add1b5c9922653a5be39ad4 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jiri Olsa465f27a2016-08-26 10:36:12 +02002/*
3 * This is rewrite of original c2c tool introduced in here:
4 * http://lwn.net/Articles/588866/
5 *
6 * The original tool was changed to fit in current perf state.
7 *
8 * Original authors:
9 * Don Zickus <dzickus@redhat.com>
10 * Dick Fowles <fowles@inreach.com>
11 * Joe Mario <jmario@redhat.com>
12 */
Arnaldo Carvalho de Meloa43783a2017-04-18 10:46:11 -030013#include <errno.h>
Arnaldo Carvalho de Melofd20e812017-04-17 15:23:08 -030014#include <inttypes.h>
Jiri Olsa7aef3bf2016-09-22 17:36:38 +020015#include <linux/compiler.h>
16#include <linux/kernel.h>
Jiri Olsacbb88502016-09-22 17:36:48 +020017#include <linux/stringify.h>
Jiri Olsa1e181b92016-06-03 15:40:28 +020018#include <asm/bug.h>
Arnaldo Carvalho de Melo391e4202017-04-19 18:51:14 -030019#include <sys/param.h>
Jiri Olsa7aef3bf2016-09-22 17:36:38 +020020#include "util.h"
21#include "debug.h"
22#include "builtin.h"
23#include <subcmd/parse-options.h>
Jiri Olsa39bcd4a2016-09-22 17:36:39 +020024#include "mem-events.h"
Jiri Olsa903a6f12016-09-22 17:36:40 +020025#include "session.h"
26#include "hist.h"
Jiri Olsacbb88502016-09-22 17:36:48 +020027#include "sort.h"
Jiri Olsa903a6f12016-09-22 17:36:40 +020028#include "tool.h"
29#include "data.h"
Jiri Olsa8d3f9382016-09-22 17:36:42 +020030#include "sort.h"
Arnaldo Carvalho de Melo5ab8c682017-04-25 15:30:47 -030031#include "event.h"
Jiri Olsa2709b972016-08-27 11:40:23 +020032#include "evlist.h"
33#include "evsel.h"
Jiri Olsa2d388bd2016-05-03 14:32:56 +020034#include <asm/bug.h>
Jiri Olsa5a1a99c2016-01-06 16:59:02 +010035#include "ui/browsers/hists.h"
Jiri Olsadd805762016-05-11 18:23:48 +020036#include "evlist.h"
Arnaldo Carvalho de Meloe7ff8922017-04-19 21:34:35 -030037#include "thread.h"
Jiri Olsa903a6f12016-09-22 17:36:40 +020038
Jiri Olsac75540e2016-09-22 17:36:41 +020039struct c2c_hists {
40 struct hists hists;
41 struct perf_hpp_list list;
Jiri Olsab2252ae2016-09-22 17:36:46 +020042 struct c2c_stats stats;
Jiri Olsac75540e2016-09-22 17:36:41 +020043};
44
Jiri Olsa92062d52016-06-05 13:40:53 +020045struct compute_stats {
46 struct stats lcl_hitm;
47 struct stats rmt_hitm;
48 struct stats load;
49};
50
Jiri Olsa78b27542016-09-22 17:36:44 +020051struct c2c_hist_entry {
52 struct c2c_hists *hists;
Jiri Olsab2252ae2016-09-22 17:36:46 +020053 struct c2c_stats stats;
Jiri Olsa1e181b92016-06-03 15:40:28 +020054 unsigned long *cpuset;
55 struct c2c_stats *node_stats;
Jiri Olsabb342dae2016-07-06 15:40:09 +020056 unsigned int cacheline_idx;
Jiri Olsa92062d52016-06-05 13:40:53 +020057
58 struct compute_stats cstats;
59
Jiri Olsa78b27542016-09-22 17:36:44 +020060 /*
61 * must be at the end,
62 * because of its callchain dynamic entry
63 */
64 struct hist_entry he;
65};
66
Jiri Olsa190bacc2017-01-20 10:20:32 +010067static char const *coalesce_default = "pid,iaddr";
Jiri Olsafc9c6302016-05-24 14:14:38 +020068
Jiri Olsa903a6f12016-09-22 17:36:40 +020069struct perf_c2c {
Jiri Olsac75540e2016-09-22 17:36:41 +020070 struct perf_tool tool;
71 struct c2c_hists hists;
Jiri Olsa1e181b92016-06-03 15:40:28 +020072
73 unsigned long **nodes;
74 int nodes_cnt;
75 int cpus_cnt;
76 int *cpu2node;
77 int node_info;
Jiri Olsa89d9ba8f2016-07-10 15:47:40 +020078
79 bool show_src;
Jiri Olsaaf09b2d2016-10-11 13:52:05 +020080 bool show_all;
Jiri Olsa5a1a99c2016-01-06 16:59:02 +010081 bool use_stdio;
Jiri Olsa74c63a22016-05-02 20:01:59 +020082 bool stats_only;
Jiri Olsa590b6a32016-07-10 16:25:15 +020083 bool symbol_full;
Jiri Olsa7ef2efa2016-07-01 11:12:11 +020084
85 /* HITM shared clines stats */
86 struct c2c_stats hitm_stats;
87 int shared_clines;
Jiri Olsa55b95772016-05-29 10:21:45 +020088
89 int display;
Jiri Olsafc9c6302016-05-24 14:14:38 +020090
91 const char *coalesce;
92 char *cl_sort;
93 char *cl_resort;
94 char *cl_output;
Jiri Olsa55b95772016-05-29 10:21:45 +020095};
96
97enum {
98 DISPLAY_LCL,
99 DISPLAY_RMT,
Jiri Olsad940bac2016-11-21 22:33:30 +0100100 DISPLAY_TOT,
101 DISPLAY_MAX,
102};
103
104static const char *display_str[DISPLAY_MAX] = {
105 [DISPLAY_LCL] = "Local",
106 [DISPLAY_RMT] = "Remote",
107 [DISPLAY_TOT] = "Total",
Jiri Olsa903a6f12016-09-22 17:36:40 +0200108};
109
Jiri Olsa3a5bfab2016-11-21 22:33:31 +0100110static const struct option c2c_options[] = {
111 OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
112 OPT_END()
113};
114
Jiri Olsa903a6f12016-09-22 17:36:40 +0200115static struct perf_c2c c2c;
Jiri Olsa7aef3bf2016-09-22 17:36:38 +0200116
Jiri Olsa78b27542016-09-22 17:36:44 +0200117static void *c2c_he_zalloc(size_t size)
118{
119 struct c2c_hist_entry *c2c_he;
120
121 c2c_he = zalloc(size + sizeof(*c2c_he));
122 if (!c2c_he)
123 return NULL;
124
Jiri Olsa1e181b92016-06-03 15:40:28 +0200125 c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt);
126 if (!c2c_he->cpuset)
127 return NULL;
128
129 c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
130 if (!c2c_he->node_stats)
131 return NULL;
132
Jiri Olsa92062d52016-06-05 13:40:53 +0200133 init_stats(&c2c_he->cstats.lcl_hitm);
134 init_stats(&c2c_he->cstats.rmt_hitm);
135 init_stats(&c2c_he->cstats.load);
136
Jiri Olsa78b27542016-09-22 17:36:44 +0200137 return &c2c_he->he;
138}
139
140static void c2c_he_free(void *he)
141{
142 struct c2c_hist_entry *c2c_he;
143
144 c2c_he = container_of(he, struct c2c_hist_entry, he);
145 if (c2c_he->hists) {
146 hists__delete_entries(&c2c_he->hists->hists);
147 free(c2c_he->hists);
148 }
149
Jiri Olsa1e181b92016-06-03 15:40:28 +0200150 free(c2c_he->cpuset);
151 free(c2c_he->node_stats);
Jiri Olsa78b27542016-09-22 17:36:44 +0200152 free(c2c_he);
153}
154
155static struct hist_entry_ops c2c_entry_ops = {
156 .new = c2c_he_zalloc,
157 .free = c2c_he_free,
158};
159
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200160static int c2c_hists__init(struct c2c_hists *hists,
Jiri Olsa1d62fcd2016-05-24 10:12:31 +0200161 const char *sort,
162 int nr_header_lines);
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200163
Jiri Olsab2252ae2016-09-22 17:36:46 +0200164static struct c2c_hists*
165he__get_c2c_hists(struct hist_entry *he,
Jiri Olsa1d62fcd2016-05-24 10:12:31 +0200166 const char *sort,
167 int nr_header_lines)
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200168{
169 struct c2c_hist_entry *c2c_he;
170 struct c2c_hists *hists;
171 int ret;
172
173 c2c_he = container_of(he, struct c2c_hist_entry, he);
174 if (c2c_he->hists)
Jiri Olsab2252ae2016-09-22 17:36:46 +0200175 return c2c_he->hists;
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200176
177 hists = c2c_he->hists = zalloc(sizeof(*hists));
178 if (!hists)
179 return NULL;
180
Jiri Olsa1d62fcd2016-05-24 10:12:31 +0200181 ret = c2c_hists__init(hists, sort, nr_header_lines);
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200182 if (ret) {
183 free(hists);
184 return NULL;
185 }
186
Jiri Olsab2252ae2016-09-22 17:36:46 +0200187 return hists;
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200188}
189
Jiri Olsa1e181b92016-06-03 15:40:28 +0200190static void c2c_he__set_cpu(struct c2c_hist_entry *c2c_he,
191 struct perf_sample *sample)
192{
193 if (WARN_ONCE(sample->cpu == (unsigned int) -1,
194 "WARNING: no sample cpu value"))
195 return;
196
197 set_bit(sample->cpu, c2c_he->cpuset);
198}
199
Jiri Olsa92062d52016-06-05 13:40:53 +0200200static void compute_stats(struct c2c_hist_entry *c2c_he,
201 struct c2c_stats *stats,
202 u64 weight)
203{
204 struct compute_stats *cstats = &c2c_he->cstats;
205
206 if (stats->rmt_hitm)
207 update_stats(&cstats->rmt_hitm, weight);
208 else if (stats->lcl_hitm)
209 update_stats(&cstats->lcl_hitm, weight);
210 else if (stats->load)
211 update_stats(&cstats->load, weight);
212}
213
Jiri Olsa78b27542016-09-22 17:36:44 +0200214static int process_sample_event(struct perf_tool *tool __maybe_unused,
215 union perf_event *event,
216 struct perf_sample *sample,
Arnaldo Carvalho de Melo7e6a7992016-12-12 10:52:10 -0300217 struct perf_evsel *evsel,
Jiri Olsa78b27542016-09-22 17:36:44 +0200218 struct machine *machine)
219{
Jiri Olsab2252ae2016-09-22 17:36:46 +0200220 struct c2c_hists *c2c_hists = &c2c.hists;
221 struct c2c_hist_entry *c2c_he;
222 struct c2c_stats stats = { .nr_entries = 0, };
Jiri Olsa78b27542016-09-22 17:36:44 +0200223 struct hist_entry *he;
224 struct addr_location al;
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200225 struct mem_info *mi, *mi_dup;
Jiri Olsa78b27542016-09-22 17:36:44 +0200226 int ret;
227
228 if (machine__resolve(machine, &al, sample) < 0) {
229 pr_debug("problem processing %d event, skipping it.\n",
230 event->header.type);
231 return -1;
232 }
233
Jiri Olsadd805762016-05-11 18:23:48 +0200234 ret = sample__resolve_callchain(sample, &callchain_cursor, NULL,
235 evsel, &al, sysctl_perf_event_max_stack);
236 if (ret)
237 goto out;
238
Jiri Olsa78b27542016-09-22 17:36:44 +0200239 mi = sample__resolve_mem(sample, &al);
240 if (mi == NULL)
241 return -ENOMEM;
242
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200243 mi_dup = memdup(mi, sizeof(*mi));
244 if (!mi_dup)
245 goto free_mi;
246
Jiri Olsab2252ae2016-09-22 17:36:46 +0200247 c2c_decode_stats(&stats, mi);
248
249 he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops,
Jiri Olsa78b27542016-09-22 17:36:44 +0200250 &al, NULL, NULL, mi,
251 sample, true);
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200252 if (he == NULL)
253 goto free_mi_dup;
Jiri Olsa78b27542016-09-22 17:36:44 +0200254
Jiri Olsab2252ae2016-09-22 17:36:46 +0200255 c2c_he = container_of(he, struct c2c_hist_entry, he);
256 c2c_add_stats(&c2c_he->stats, &stats);
257 c2c_add_stats(&c2c_hists->stats, &stats);
258
Jiri Olsa1e181b92016-06-03 15:40:28 +0200259 c2c_he__set_cpu(c2c_he, sample);
260
Jiri Olsab2252ae2016-09-22 17:36:46 +0200261 hists__inc_nr_samples(&c2c_hists->hists, he->filtered);
Jiri Olsa78b27542016-09-22 17:36:44 +0200262 ret = hist_entry__append_callchain(he, sample);
263
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200264 if (!ret) {
Jiri Olsa1e181b92016-06-03 15:40:28 +0200265 /*
266 * There's already been warning about missing
267 * sample's cpu value. Let's account all to
268 * node 0 in this case, without any further
269 * warning.
270 *
271 * Doing node stats only for single callchain data.
272 */
273 int cpu = sample->cpu == (unsigned int) -1 ? 0 : sample->cpu;
274 int node = c2c.cpu2node[cpu];
275
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200276 mi = mi_dup;
277
278 mi_dup = memdup(mi, sizeof(*mi));
279 if (!mi_dup)
280 goto free_mi;
281
Jiri Olsafc9c6302016-05-24 14:14:38 +0200282 c2c_hists = he__get_c2c_hists(he, c2c.cl_sort, 2);
Jiri Olsab2252ae2016-09-22 17:36:46 +0200283 if (!c2c_hists)
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200284 goto free_mi_dup;
285
Jiri Olsab2252ae2016-09-22 17:36:46 +0200286 he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops,
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200287 &al, NULL, NULL, mi,
288 sample, true);
289 if (he == NULL)
290 goto free_mi_dup;
291
Jiri Olsab2252ae2016-09-22 17:36:46 +0200292 c2c_he = container_of(he, struct c2c_hist_entry, he);
293 c2c_add_stats(&c2c_he->stats, &stats);
294 c2c_add_stats(&c2c_hists->stats, &stats);
Jiri Olsa1e181b92016-06-03 15:40:28 +0200295 c2c_add_stats(&c2c_he->node_stats[node], &stats);
296
Jiri Olsa92062d52016-06-05 13:40:53 +0200297 compute_stats(c2c_he, &stats, sample->weight);
298
Jiri Olsa1e181b92016-06-03 15:40:28 +0200299 c2c_he__set_cpu(c2c_he, sample);
Jiri Olsab2252ae2016-09-22 17:36:46 +0200300
301 hists__inc_nr_samples(&c2c_hists->hists, he->filtered);
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200302 ret = hist_entry__append_callchain(he, sample);
303 }
304
305out:
Jiri Olsa78b27542016-09-22 17:36:44 +0200306 addr_location__put(&al);
307 return ret;
Jiri Olsaec06f9b2016-09-22 17:36:45 +0200308
309free_mi_dup:
310 free(mi_dup);
311free_mi:
312 free(mi);
313 ret = -ENOMEM;
314 goto out;
Jiri Olsa78b27542016-09-22 17:36:44 +0200315}
316
317static struct perf_c2c c2c = {
318 .tool = {
319 .sample = process_sample_event,
320 .mmap = perf_event__process_mmap,
321 .mmap2 = perf_event__process_mmap2,
322 .comm = perf_event__process_comm,
323 .exit = perf_event__process_exit,
324 .fork = perf_event__process_fork,
325 .lost = perf_event__process_lost,
326 .ordered_events = true,
327 .ordering_requires_timestamps = true,
328 },
329};
330
Jiri Olsa7aef3bf2016-09-22 17:36:38 +0200331static const char * const c2c_usage[] = {
Jiri Olsa903a6f12016-09-22 17:36:40 +0200332 "perf c2c {record|report}",
Jiri Olsa7aef3bf2016-09-22 17:36:38 +0200333 NULL
334};
335
Jiri Olsa903a6f12016-09-22 17:36:40 +0200336static const char * const __usage_report[] = {
337 "perf c2c report",
338 NULL
339};
340
341static const char * const *report_c2c_usage = __usage_report;
342
Jiri Olsac75540e2016-09-22 17:36:41 +0200343#define C2C_HEADER_MAX 2
344
345struct c2c_header {
346 struct {
347 const char *text;
348 int span;
349 } line[C2C_HEADER_MAX];
350};
351
352struct c2c_dimension {
353 struct c2c_header header;
354 const char *name;
355 int width;
Jiri Olsa8d3f9382016-09-22 17:36:42 +0200356 struct sort_entry *se;
Jiri Olsac75540e2016-09-22 17:36:41 +0200357
358 int64_t (*cmp)(struct perf_hpp_fmt *fmt,
359 struct hist_entry *, struct hist_entry *);
360 int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
361 struct hist_entry *he);
362 int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
363 struct hist_entry *he);
364};
365
366struct c2c_fmt {
367 struct perf_hpp_fmt fmt;
368 struct c2c_dimension *dim;
369};
370
Jiri Olsa590b6a32016-07-10 16:25:15 +0200371#define SYMBOL_WIDTH 30
372
373static struct c2c_dimension dim_symbol;
374static struct c2c_dimension dim_srcline;
375
376static int symbol_width(struct hists *hists, struct sort_entry *se)
377{
378 int width = hists__col_len(hists, se->se_width_idx);
379
380 if (!c2c.symbol_full)
381 width = MIN(width, SYMBOL_WIDTH);
382
383 return width;
384}
385
Jiri Olsac75540e2016-09-22 17:36:41 +0200386static int c2c_width(struct perf_hpp_fmt *fmt,
387 struct perf_hpp *hpp __maybe_unused,
Arnaldo Carvalho de Melo7e6a7992016-12-12 10:52:10 -0300388 struct hists *hists)
Jiri Olsac75540e2016-09-22 17:36:41 +0200389{
390 struct c2c_fmt *c2c_fmt;
Jiri Olsac75540e2016-09-22 17:36:41 +0200391 struct c2c_dimension *dim;
Jiri Olsac75540e2016-09-22 17:36:41 +0200392
393 c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
394 dim = c2c_fmt->dim;
395
Jiri Olsa590b6a32016-07-10 16:25:15 +0200396 if (dim == &dim_symbol || dim == &dim_srcline)
397 return symbol_width(hists, dim->se);
398
Jiri Olsa8d3f9382016-09-22 17:36:42 +0200399 return dim->se ? hists__col_len(hists, dim->se->se_width_idx) :
400 c2c_fmt->dim->width;
401}
402
403static int c2c_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
404 struct hists *hists, int line, int *span)
405{
406 struct perf_hpp_list *hpp_list = hists->hpp_list;
407 struct c2c_fmt *c2c_fmt;
408 struct c2c_dimension *dim;
409 const char *text = NULL;
410 int width = c2c_width(fmt, hpp, hists);
411
412 c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
413 dim = c2c_fmt->dim;
414
415 if (dim->se) {
416 text = dim->header.line[line].text;
417 /* Use the last line from sort_entry if not defined. */
418 if (!text && (line == hpp_list->nr_header_lines - 1))
419 text = dim->se->se_header;
420 } else {
421 text = dim->header.line[line].text;
422
423 if (*span) {
424 (*span)--;
425 return 0;
426 } else {
427 *span = dim->header.line[line].span;
428 }
429 }
430
Jiri Olsac75540e2016-09-22 17:36:41 +0200431 if (text == NULL)
432 text = "";
433
Jiri Olsa8d3f9382016-09-22 17:36:42 +0200434 return scnprintf(hpp->buf, hpp->size, "%*s", width, text);
Jiri Olsac75540e2016-09-22 17:36:41 +0200435}
436
Jiri Olsacbb88502016-09-22 17:36:48 +0200437#define HEX_STR(__s, __v) \
438({ \
439 scnprintf(__s, sizeof(__s), "0x%" PRIx64, __v); \
440 __s; \
441})
442
443static int64_t
444dcacheline_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
445 struct hist_entry *left, struct hist_entry *right)
446{
447 return sort__dcacheline_cmp(left, right);
448}
449
450static int dcacheline_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
451 struct hist_entry *he)
452{
453 uint64_t addr = 0;
454 int width = c2c_width(fmt, hpp, he->hists);
455 char buf[20];
456
457 if (he->mem_info)
458 addr = cl_address(he->mem_info->daddr.addr);
459
460 return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr));
461}
462
Jiri Olsa48acdeb2016-04-29 14:37:06 +0200463static int offset_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
464 struct hist_entry *he)
465{
466 uint64_t addr = 0;
467 int width = c2c_width(fmt, hpp, he->hists);
468 char buf[20];
469
470 if (he->mem_info)
471 addr = cl_offset(he->mem_info->daddr.al_addr);
472
473 return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr));
474}
475
476static int64_t
477offset_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
478 struct hist_entry *left, struct hist_entry *right)
479{
480 uint64_t l = 0, r = 0;
481
482 if (left->mem_info)
483 l = cl_offset(left->mem_info->daddr.addr);
484 if (right->mem_info)
485 r = cl_offset(right->mem_info->daddr.addr);
486
487 return (int64_t)(r - l);
488}
489
Jiri Olsa43575a92016-05-03 21:48:56 +0200490static int
491iaddr_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
492 struct hist_entry *he)
493{
494 uint64_t addr = 0;
495 int width = c2c_width(fmt, hpp, he->hists);
496 char buf[20];
497
498 if (he->mem_info)
499 addr = he->mem_info->iaddr.addr;
500
501 return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr));
502}
503
504static int64_t
505iaddr_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
506 struct hist_entry *left, struct hist_entry *right)
507{
508 return sort__iaddr_cmp(left, right);
509}
510
Jiri Olsa97cb4862016-05-23 16:20:14 +0200511static int
512tot_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
513 struct hist_entry *he)
514{
515 struct c2c_hist_entry *c2c_he;
516 int width = c2c_width(fmt, hpp, he->hists);
517 unsigned int tot_hitm;
518
519 c2c_he = container_of(he, struct c2c_hist_entry, he);
520 tot_hitm = c2c_he->stats.lcl_hitm + c2c_he->stats.rmt_hitm;
521
522 return scnprintf(hpp->buf, hpp->size, "%*u", width, tot_hitm);
523}
524
525static int64_t
526tot_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
527 struct hist_entry *left, struct hist_entry *right)
528{
529 struct c2c_hist_entry *c2c_left;
530 struct c2c_hist_entry *c2c_right;
531 unsigned int tot_hitm_left;
532 unsigned int tot_hitm_right;
533
534 c2c_left = container_of(left, struct c2c_hist_entry, he);
535 c2c_right = container_of(right, struct c2c_hist_entry, he);
536
537 tot_hitm_left = c2c_left->stats.lcl_hitm + c2c_left->stats.rmt_hitm;
538 tot_hitm_right = c2c_right->stats.lcl_hitm + c2c_right->stats.rmt_hitm;
539
540 return tot_hitm_left - tot_hitm_right;
541}
542
543#define STAT_FN_ENTRY(__f) \
544static int \
545__f ## _entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, \
546 struct hist_entry *he) \
547{ \
548 struct c2c_hist_entry *c2c_he; \
549 int width = c2c_width(fmt, hpp, he->hists); \
550 \
551 c2c_he = container_of(he, struct c2c_hist_entry, he); \
552 return scnprintf(hpp->buf, hpp->size, "%*u", width, \
553 c2c_he->stats.__f); \
554}
555
556#define STAT_FN_CMP(__f) \
557static int64_t \
558__f ## _cmp(struct perf_hpp_fmt *fmt __maybe_unused, \
559 struct hist_entry *left, struct hist_entry *right) \
560{ \
561 struct c2c_hist_entry *c2c_left, *c2c_right; \
562 \
563 c2c_left = container_of(left, struct c2c_hist_entry, he); \
564 c2c_right = container_of(right, struct c2c_hist_entry, he); \
565 return c2c_left->stats.__f - c2c_right->stats.__f; \
566}
567
568#define STAT_FN(__f) \
569 STAT_FN_ENTRY(__f) \
570 STAT_FN_CMP(__f)
571
572STAT_FN(rmt_hitm)
573STAT_FN(lcl_hitm)
Jiri Olsa0f188962016-05-04 10:10:11 +0200574STAT_FN(store)
575STAT_FN(st_l1hit)
576STAT_FN(st_l1miss)
Jiri Olsa1295f682016-05-04 10:18:24 +0200577STAT_FN(ld_fbhit)
578STAT_FN(ld_l1hit)
579STAT_FN(ld_l2hit)
Jiri Olsa4d089102016-05-04 10:27:51 +0200580STAT_FN(ld_llchit)
581STAT_FN(rmt_hit)
Jiri Olsa97cb4862016-05-23 16:20:14 +0200582
Jiri Olsa04402d22016-05-19 10:10:51 +0200583static uint64_t llc_miss(struct c2c_stats *stats)
584{
585 uint64_t llcmiss;
586
587 llcmiss = stats->lcl_dram +
588 stats->rmt_dram +
589 stats->rmt_hitm +
590 stats->rmt_hit;
591
592 return llcmiss;
593}
594
595static int
596ld_llcmiss_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
597 struct hist_entry *he)
598{
599 struct c2c_hist_entry *c2c_he;
600 int width = c2c_width(fmt, hpp, he->hists);
601
602 c2c_he = container_of(he, struct c2c_hist_entry, he);
603
604 return scnprintf(hpp->buf, hpp->size, "%*lu", width,
605 llc_miss(&c2c_he->stats));
606}
607
608static int64_t
609ld_llcmiss_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
610 struct hist_entry *left, struct hist_entry *right)
611{
612 struct c2c_hist_entry *c2c_left;
613 struct c2c_hist_entry *c2c_right;
614
615 c2c_left = container_of(left, struct c2c_hist_entry, he);
616 c2c_right = container_of(right, struct c2c_hist_entry, he);
617
618 return llc_miss(&c2c_left->stats) - llc_miss(&c2c_right->stats);
619}
620
Jiri Olsa01b84d72016-05-04 10:35:29 +0200621static uint64_t total_records(struct c2c_stats *stats)
622{
623 uint64_t lclmiss, ldcnt, total;
624
625 lclmiss = stats->lcl_dram +
626 stats->rmt_dram +
627 stats->rmt_hitm +
628 stats->rmt_hit;
629
630 ldcnt = lclmiss +
631 stats->ld_fbhit +
632 stats->ld_l1hit +
633 stats->ld_l2hit +
634 stats->ld_llchit +
635 stats->lcl_hitm;
636
637 total = ldcnt +
638 stats->st_l1hit +
639 stats->st_l1miss;
640
641 return total;
642}
643
644static int
645tot_recs_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
646 struct hist_entry *he)
647{
648 struct c2c_hist_entry *c2c_he;
649 int width = c2c_width(fmt, hpp, he->hists);
650 uint64_t tot_recs;
651
652 c2c_he = container_of(he, struct c2c_hist_entry, he);
653 tot_recs = total_records(&c2c_he->stats);
654
655 return scnprintf(hpp->buf, hpp->size, "%*" PRIu64, width, tot_recs);
656}
657
658static int64_t
659tot_recs_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
660 struct hist_entry *left, struct hist_entry *right)
661{
662 struct c2c_hist_entry *c2c_left;
663 struct c2c_hist_entry *c2c_right;
664 uint64_t tot_recs_left;
665 uint64_t tot_recs_right;
666
667 c2c_left = container_of(left, struct c2c_hist_entry, he);
668 c2c_right = container_of(right, struct c2c_hist_entry, he);
669
670 tot_recs_left = total_records(&c2c_left->stats);
671 tot_recs_right = total_records(&c2c_right->stats);
672
673 return tot_recs_left - tot_recs_right;
674}
675
Jiri Olsa55177c42016-05-19 09:52:37 +0200676static uint64_t total_loads(struct c2c_stats *stats)
677{
678 uint64_t lclmiss, ldcnt;
679
680 lclmiss = stats->lcl_dram +
681 stats->rmt_dram +
682 stats->rmt_hitm +
683 stats->rmt_hit;
684
685 ldcnt = lclmiss +
686 stats->ld_fbhit +
687 stats->ld_l1hit +
688 stats->ld_l2hit +
689 stats->ld_llchit +
690 stats->lcl_hitm;
691
692 return ldcnt;
693}
694
695static int
696tot_loads_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
697 struct hist_entry *he)
698{
699 struct c2c_hist_entry *c2c_he;
700 int width = c2c_width(fmt, hpp, he->hists);
701 uint64_t tot_recs;
702
703 c2c_he = container_of(he, struct c2c_hist_entry, he);
704 tot_recs = total_loads(&c2c_he->stats);
705
706 return scnprintf(hpp->buf, hpp->size, "%*" PRIu64, width, tot_recs);
707}
708
709static int64_t
710tot_loads_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
711 struct hist_entry *left, struct hist_entry *right)
712{
713 struct c2c_hist_entry *c2c_left;
714 struct c2c_hist_entry *c2c_right;
715 uint64_t tot_recs_left;
716 uint64_t tot_recs_right;
717
718 c2c_left = container_of(left, struct c2c_hist_entry, he);
719 c2c_right = container_of(right, struct c2c_hist_entry, he);
720
721 tot_recs_left = total_loads(&c2c_left->stats);
722 tot_recs_right = total_loads(&c2c_right->stats);
723
724 return tot_recs_left - tot_recs_right;
725}
726
Jiri Olsaf0c50c12016-05-04 10:50:09 +0200727typedef double (get_percent_cb)(struct c2c_hist_entry *);
728
729static int
730percent_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
731 struct hist_entry *he, get_percent_cb get_percent)
732{
733 struct c2c_hist_entry *c2c_he;
734 int width = c2c_width(fmt, hpp, he->hists);
735 double per;
736
737 c2c_he = container_of(he, struct c2c_hist_entry, he);
738 per = get_percent(c2c_he);
739
Jiri Olsa5a1a99c2016-01-06 16:59:02 +0100740#ifdef HAVE_SLANG_SUPPORT
741 if (use_browser)
742 return __hpp__slsmg_color_printf(hpp, "%*.2f%%", width - 1, per);
743#endif
Jiri Olsaf0c50c12016-05-04 10:50:09 +0200744 return hpp_color_scnprintf(hpp, "%*.2f%%", width - 1, per);
745}
746
747static double percent_hitm(struct c2c_hist_entry *c2c_he)
748{
749 struct c2c_hists *hists;
750 struct c2c_stats *stats;
751 struct c2c_stats *total;
Jiri Olsa55b95772016-05-29 10:21:45 +0200752 int tot = 0, st = 0;
Jiri Olsaf0c50c12016-05-04 10:50:09 +0200753 double p;
754
755 hists = container_of(c2c_he->he.hists, struct c2c_hists, hists);
756 stats = &c2c_he->stats;
757 total = &hists->stats;
758
Jiri Olsa55b95772016-05-29 10:21:45 +0200759 switch (c2c.display) {
760 case DISPLAY_RMT:
761 st = stats->rmt_hitm;
762 tot = total->rmt_hitm;
763 break;
764 case DISPLAY_LCL:
765 st = stats->lcl_hitm;
766 tot = total->lcl_hitm;
Jiri Olsad940bac2016-11-21 22:33:30 +0100767 break;
768 case DISPLAY_TOT:
769 st = stats->tot_hitm;
770 tot = total->tot_hitm;
Jiri Olsa55b95772016-05-29 10:21:45 +0200771 default:
772 break;
773 }
Jiri Olsaf0c50c12016-05-04 10:50:09 +0200774
775 p = tot ? (double) st / tot : 0;
776
777 return 100 * p;
778}
779
780#define PERC_STR(__s, __v) \
781({ \
782 scnprintf(__s, sizeof(__s), "%.2F%%", __v); \
783 __s; \
784})
785
786static int
787percent_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
788 struct hist_entry *he)
789{
790 struct c2c_hist_entry *c2c_he;
791 int width = c2c_width(fmt, hpp, he->hists);
792 char buf[10];
793 double per;
794
795 c2c_he = container_of(he, struct c2c_hist_entry, he);
796 per = percent_hitm(c2c_he);
797 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
798}
799
800static int
801percent_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
802 struct hist_entry *he)
803{
804 return percent_color(fmt, hpp, he, percent_hitm);
805}
806
807static int64_t
808percent_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
809 struct hist_entry *left, struct hist_entry *right)
810{
811 struct c2c_hist_entry *c2c_left;
812 struct c2c_hist_entry *c2c_right;
813 double per_left;
814 double per_right;
815
816 c2c_left = container_of(left, struct c2c_hist_entry, he);
817 c2c_right = container_of(right, struct c2c_hist_entry, he);
818
819 per_left = percent_hitm(c2c_left);
820 per_right = percent_hitm(c2c_right);
821
822 return per_left - per_right;
823}
824
Jiri Olsa9cb35002016-05-04 12:16:50 +0200825static struct c2c_stats *he_stats(struct hist_entry *he)
826{
827 struct c2c_hist_entry *c2c_he;
828
829 c2c_he = container_of(he, struct c2c_hist_entry, he);
830 return &c2c_he->stats;
831}
832
833static struct c2c_stats *total_stats(struct hist_entry *he)
834{
835 struct c2c_hists *hists;
836
837 hists = container_of(he->hists, struct c2c_hists, hists);
838 return &hists->stats;
839}
840
841static double percent(int st, int tot)
842{
843 return tot ? 100. * (double) st / (double) tot : 0;
844}
845
846#define PERCENT(__h, __f) percent(he_stats(__h)->__f, total_stats(__h)->__f)
847
848#define PERCENT_FN(__f) \
849static double percent_ ## __f(struct c2c_hist_entry *c2c_he) \
850{ \
851 struct c2c_hists *hists; \
852 \
853 hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); \
854 return percent(c2c_he->stats.__f, hists->stats.__f); \
855}
856
857PERCENT_FN(rmt_hitm)
858PERCENT_FN(lcl_hitm)
859PERCENT_FN(st_l1hit)
860PERCENT_FN(st_l1miss)
861
862static int
863percent_rmt_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
864 struct hist_entry *he)
865{
866 int width = c2c_width(fmt, hpp, he->hists);
867 double per = PERCENT(he, rmt_hitm);
868 char buf[10];
869
870 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
871}
872
873static int
874percent_rmt_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
875 struct hist_entry *he)
876{
877 return percent_color(fmt, hpp, he, percent_rmt_hitm);
878}
879
880static int64_t
881percent_rmt_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
882 struct hist_entry *left, struct hist_entry *right)
883{
884 double per_left;
885 double per_right;
886
887 per_left = PERCENT(left, lcl_hitm);
888 per_right = PERCENT(right, lcl_hitm);
889
890 return per_left - per_right;
891}
892
893static int
894percent_lcl_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
895 struct hist_entry *he)
896{
897 int width = c2c_width(fmt, hpp, he->hists);
898 double per = PERCENT(he, lcl_hitm);
899 char buf[10];
900
901 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
902}
903
904static int
905percent_lcl_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
906 struct hist_entry *he)
907{
908 return percent_color(fmt, hpp, he, percent_lcl_hitm);
909}
910
911static int64_t
912percent_lcl_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
913 struct hist_entry *left, struct hist_entry *right)
914{
915 double per_left;
916 double per_right;
917
918 per_left = PERCENT(left, lcl_hitm);
919 per_right = PERCENT(right, lcl_hitm);
920
921 return per_left - per_right;
922}
923
924static int
925percent_stores_l1hit_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
926 struct hist_entry *he)
927{
928 int width = c2c_width(fmt, hpp, he->hists);
929 double per = PERCENT(he, st_l1hit);
930 char buf[10];
931
932 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
933}
934
935static int
936percent_stores_l1hit_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
937 struct hist_entry *he)
938{
939 return percent_color(fmt, hpp, he, percent_st_l1hit);
940}
941
942static int64_t
943percent_stores_l1hit_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
944 struct hist_entry *left, struct hist_entry *right)
945{
946 double per_left;
947 double per_right;
948
949 per_left = PERCENT(left, st_l1hit);
950 per_right = PERCENT(right, st_l1hit);
951
952 return per_left - per_right;
953}
954
955static int
956percent_stores_l1miss_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
957 struct hist_entry *he)
958{
959 int width = c2c_width(fmt, hpp, he->hists);
960 double per = PERCENT(he, st_l1miss);
961 char buf[10];
962
963 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
964}
965
966static int
967percent_stores_l1miss_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
968 struct hist_entry *he)
969{
970 return percent_color(fmt, hpp, he, percent_st_l1miss);
971}
972
973static int64_t
974percent_stores_l1miss_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
975 struct hist_entry *left, struct hist_entry *right)
976{
977 double per_left;
978 double per_right;
979
980 per_left = PERCENT(left, st_l1miss);
981 per_right = PERCENT(right, st_l1miss);
982
983 return per_left - per_right;
984}
985
Jiri Olsa6c70f542016-05-28 12:30:13 +0200986STAT_FN(lcl_dram)
987STAT_FN(rmt_dram)
988
Jiri Olsa36d3deb2016-05-24 13:09:47 +0200989static int
990pid_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
991 struct hist_entry *he)
992{
993 int width = c2c_width(fmt, hpp, he->hists);
994
995 return scnprintf(hpp->buf, hpp->size, "%*d", width, he->thread->pid_);
996}
997
998static int64_t
999pid_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
1000 struct hist_entry *left, struct hist_entry *right)
1001{
1002 return left->thread->pid_ - right->thread->pid_;
1003}
1004
Jiri Olsa1e181b92016-06-03 15:40:28 +02001005static int64_t
1006empty_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
1007 struct hist_entry *left __maybe_unused,
1008 struct hist_entry *right __maybe_unused)
1009{
1010 return 0;
1011}
1012
1013static int
1014node_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
1015 struct hist_entry *he)
1016{
1017 struct c2c_hist_entry *c2c_he;
1018 bool first = true;
1019 int node;
1020 int ret = 0;
1021
1022 c2c_he = container_of(he, struct c2c_hist_entry, he);
1023
1024 for (node = 0; node < c2c.nodes_cnt; node++) {
1025 DECLARE_BITMAP(set, c2c.cpus_cnt);
1026
1027 bitmap_zero(set, c2c.cpus_cnt);
1028 bitmap_and(set, c2c_he->cpuset, c2c.nodes[node], c2c.cpus_cnt);
1029
1030 if (!bitmap_weight(set, c2c.cpus_cnt)) {
1031 if (c2c.node_info == 1) {
1032 ret = scnprintf(hpp->buf, hpp->size, "%21s", " ");
1033 advance_hpp(hpp, ret);
1034 }
1035 continue;
1036 }
1037
1038 if (!first) {
1039 ret = scnprintf(hpp->buf, hpp->size, " ");
1040 advance_hpp(hpp, ret);
1041 }
1042
1043 switch (c2c.node_info) {
1044 case 0:
1045 ret = scnprintf(hpp->buf, hpp->size, "%2d", node);
1046 advance_hpp(hpp, ret);
1047 break;
1048 case 1:
1049 {
1050 int num = bitmap_weight(c2c_he->cpuset, c2c.cpus_cnt);
1051 struct c2c_stats *stats = &c2c_he->node_stats[node];
1052
1053 ret = scnprintf(hpp->buf, hpp->size, "%2d{%2d ", node, num);
1054 advance_hpp(hpp, ret);
1055
Jiri Olsa55b95772016-05-29 10:21:45 +02001056 #define DISPLAY_HITM(__h) \
1057 if (c2c_he->stats.__h> 0) { \
1058 ret = scnprintf(hpp->buf, hpp->size, "%5.1f%% ", \
1059 percent(stats->__h, c2c_he->stats.__h));\
1060 } else { \
1061 ret = scnprintf(hpp->buf, hpp->size, "%6s ", "n/a"); \
Jiri Olsa1e181b92016-06-03 15:40:28 +02001062 }
1063
Jiri Olsa55b95772016-05-29 10:21:45 +02001064 switch (c2c.display) {
1065 case DISPLAY_RMT:
1066 DISPLAY_HITM(rmt_hitm);
1067 break;
1068 case DISPLAY_LCL:
1069 DISPLAY_HITM(lcl_hitm);
Jiri Olsad940bac2016-11-21 22:33:30 +01001070 break;
1071 case DISPLAY_TOT:
1072 DISPLAY_HITM(tot_hitm);
Jiri Olsa55b95772016-05-29 10:21:45 +02001073 default:
1074 break;
1075 }
1076
1077 #undef DISPLAY_HITM
1078
Jiri Olsa1e181b92016-06-03 15:40:28 +02001079 advance_hpp(hpp, ret);
1080
1081 if (c2c_he->stats.store > 0) {
1082 ret = scnprintf(hpp->buf, hpp->size, "%5.1f%%}",
1083 percent(stats->store, c2c_he->stats.store));
1084 } else {
1085 ret = scnprintf(hpp->buf, hpp->size, "%6s}", "n/a");
1086 }
1087
1088 advance_hpp(hpp, ret);
1089 break;
1090 }
1091 case 2:
1092 ret = scnprintf(hpp->buf, hpp->size, "%2d{", node);
1093 advance_hpp(hpp, ret);
1094
1095 ret = bitmap_scnprintf(set, c2c.cpus_cnt, hpp->buf, hpp->size);
1096 advance_hpp(hpp, ret);
1097
1098 ret = scnprintf(hpp->buf, hpp->size, "}");
1099 advance_hpp(hpp, ret);
1100 break;
1101 default:
1102 break;
1103 }
1104
1105 first = false;
1106 }
1107
1108 return 0;
1109}
1110
Jiri Olsa92062d52016-06-05 13:40:53 +02001111static int
1112mean_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
1113 struct hist_entry *he, double mean)
1114{
1115 int width = c2c_width(fmt, hpp, he->hists);
1116 char buf[10];
1117
1118 scnprintf(buf, 10, "%6.0f", mean);
1119 return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
1120}
1121
1122#define MEAN_ENTRY(__func, __val) \
1123static int \
1124__func(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, struct hist_entry *he) \
1125{ \
1126 struct c2c_hist_entry *c2c_he; \
1127 c2c_he = container_of(he, struct c2c_hist_entry, he); \
1128 return mean_entry(fmt, hpp, he, avg_stats(&c2c_he->cstats.__val)); \
1129}
1130
1131MEAN_ENTRY(mean_rmt_entry, rmt_hitm);
1132MEAN_ENTRY(mean_lcl_entry, lcl_hitm);
1133MEAN_ENTRY(mean_load_entry, load);
1134
Jiri Olsab6fe2bb2016-06-23 23:05:52 +02001135static int
Arnaldo Carvalho de Melo7e6a7992016-12-12 10:52:10 -03001136cpucnt_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
Jiri Olsab6fe2bb2016-06-23 23:05:52 +02001137 struct hist_entry *he)
1138{
1139 struct c2c_hist_entry *c2c_he;
1140 int width = c2c_width(fmt, hpp, he->hists);
1141 char buf[10];
1142
1143 c2c_he = container_of(he, struct c2c_hist_entry, he);
1144
1145 scnprintf(buf, 10, "%d", bitmap_weight(c2c_he->cpuset, c2c.cpus_cnt));
1146 return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
1147}
1148
Jiri Olsabb342dae2016-07-06 15:40:09 +02001149static int
Arnaldo Carvalho de Melo7e6a7992016-12-12 10:52:10 -03001150cl_idx_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
Jiri Olsabb342dae2016-07-06 15:40:09 +02001151 struct hist_entry *he)
1152{
1153 struct c2c_hist_entry *c2c_he;
1154 int width = c2c_width(fmt, hpp, he->hists);
1155 char buf[10];
1156
1157 c2c_he = container_of(he, struct c2c_hist_entry, he);
1158
1159 scnprintf(buf, 10, "%u", c2c_he->cacheline_idx);
1160 return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
1161}
1162
1163static int
Arnaldo Carvalho de Melo7e6a7992016-12-12 10:52:10 -03001164cl_idx_empty_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
Jiri Olsabb342dae2016-07-06 15:40:09 +02001165 struct hist_entry *he)
1166{
1167 int width = c2c_width(fmt, hpp, he->hists);
1168
1169 return scnprintf(hpp->buf, hpp->size, "%*s", width, "");
1170}
1171
Jiri Olsa600a8cf2016-09-22 17:36:47 +02001172#define HEADER_LOW(__h) \
1173 { \
1174 .line[1] = { \
1175 .text = __h, \
1176 }, \
1177 }
1178
1179#define HEADER_BOTH(__h0, __h1) \
1180 { \
1181 .line[0] = { \
1182 .text = __h0, \
1183 }, \
1184 .line[1] = { \
1185 .text = __h1, \
1186 }, \
1187 }
1188
1189#define HEADER_SPAN(__h0, __h1, __s) \
1190 { \
1191 .line[0] = { \
1192 .text = __h0, \
1193 .span = __s, \
1194 }, \
1195 .line[1] = { \
1196 .text = __h1, \
1197 }, \
1198 }
1199
1200#define HEADER_SPAN_LOW(__h) \
1201 { \
1202 .line[1] = { \
1203 .text = __h, \
1204 }, \
1205 }
1206
Jiri Olsacbb88502016-09-22 17:36:48 +02001207static struct c2c_dimension dim_dcacheline = {
1208 .header = HEADER_LOW("Cacheline"),
1209 .name = "dcacheline",
1210 .cmp = dcacheline_cmp,
1211 .entry = dcacheline_entry,
1212 .width = 18,
1213};
1214
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01001215static struct c2c_header header_offset_tui = HEADER_LOW("Off");
1216
Jiri Olsa48acdeb2016-04-29 14:37:06 +02001217static struct c2c_dimension dim_offset = {
1218 .header = HEADER_BOTH("Data address", "Offset"),
1219 .name = "offset",
1220 .cmp = offset_cmp,
1221 .entry = offset_entry,
1222 .width = 18,
1223};
1224
Jiri Olsa43575a92016-05-03 21:48:56 +02001225static struct c2c_dimension dim_iaddr = {
1226 .header = HEADER_LOW("Code address"),
1227 .name = "iaddr",
1228 .cmp = iaddr_cmp,
1229 .entry = iaddr_entry,
1230 .width = 18,
1231};
1232
Jiri Olsa97cb4862016-05-23 16:20:14 +02001233static struct c2c_dimension dim_tot_hitm = {
1234 .header = HEADER_SPAN("----- LLC Load Hitm -----", "Total", 2),
1235 .name = "tot_hitm",
1236 .cmp = tot_hitm_cmp,
1237 .entry = tot_hitm_entry,
1238 .width = 7,
1239};
1240
1241static struct c2c_dimension dim_lcl_hitm = {
1242 .header = HEADER_SPAN_LOW("Lcl"),
1243 .name = "lcl_hitm",
1244 .cmp = lcl_hitm_cmp,
1245 .entry = lcl_hitm_entry,
1246 .width = 7,
1247};
1248
1249static struct c2c_dimension dim_rmt_hitm = {
1250 .header = HEADER_SPAN_LOW("Rmt"),
1251 .name = "rmt_hitm",
1252 .cmp = rmt_hitm_cmp,
1253 .entry = rmt_hitm_entry,
1254 .width = 7,
1255};
1256
1257static struct c2c_dimension dim_cl_rmt_hitm = {
1258 .header = HEADER_SPAN("----- HITM -----", "Rmt", 1),
1259 .name = "cl_rmt_hitm",
1260 .cmp = rmt_hitm_cmp,
1261 .entry = rmt_hitm_entry,
1262 .width = 7,
1263};
1264
1265static struct c2c_dimension dim_cl_lcl_hitm = {
1266 .header = HEADER_SPAN_LOW("Lcl"),
1267 .name = "cl_lcl_hitm",
1268 .cmp = lcl_hitm_cmp,
1269 .entry = lcl_hitm_entry,
1270 .width = 7,
1271};
1272
Jiri Olsa0f188962016-05-04 10:10:11 +02001273static struct c2c_dimension dim_stores = {
1274 .header = HEADER_SPAN("---- Store Reference ----", "Total", 2),
1275 .name = "stores",
1276 .cmp = store_cmp,
1277 .entry = store_entry,
1278 .width = 7,
1279};
1280
1281static struct c2c_dimension dim_stores_l1hit = {
1282 .header = HEADER_SPAN_LOW("L1Hit"),
1283 .name = "stores_l1hit",
1284 .cmp = st_l1hit_cmp,
1285 .entry = st_l1hit_entry,
1286 .width = 7,
1287};
1288
1289static struct c2c_dimension dim_stores_l1miss = {
1290 .header = HEADER_SPAN_LOW("L1Miss"),
1291 .name = "stores_l1miss",
1292 .cmp = st_l1miss_cmp,
1293 .entry = st_l1miss_entry,
1294 .width = 7,
1295};
1296
1297static struct c2c_dimension dim_cl_stores_l1hit = {
1298 .header = HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1299 .name = "cl_stores_l1hit",
1300 .cmp = st_l1hit_cmp,
1301 .entry = st_l1hit_entry,
1302 .width = 7,
1303};
1304
1305static struct c2c_dimension dim_cl_stores_l1miss = {
1306 .header = HEADER_SPAN_LOW("L1 Miss"),
1307 .name = "cl_stores_l1miss",
1308 .cmp = st_l1miss_cmp,
1309 .entry = st_l1miss_entry,
1310 .width = 7,
1311};
1312
Jiri Olsa1295f682016-05-04 10:18:24 +02001313static struct c2c_dimension dim_ld_fbhit = {
1314 .header = HEADER_SPAN("----- Core Load Hit -----", "FB", 2),
1315 .name = "ld_fbhit",
1316 .cmp = ld_fbhit_cmp,
1317 .entry = ld_fbhit_entry,
1318 .width = 7,
1319};
1320
1321static struct c2c_dimension dim_ld_l1hit = {
1322 .header = HEADER_SPAN_LOW("L1"),
1323 .name = "ld_l1hit",
1324 .cmp = ld_l1hit_cmp,
1325 .entry = ld_l1hit_entry,
1326 .width = 7,
1327};
1328
1329static struct c2c_dimension dim_ld_l2hit = {
1330 .header = HEADER_SPAN_LOW("L2"),
1331 .name = "ld_l2hit",
1332 .cmp = ld_l2hit_cmp,
1333 .entry = ld_l2hit_entry,
1334 .width = 7,
1335};
1336
Jiri Olsa4d089102016-05-04 10:27:51 +02001337static struct c2c_dimension dim_ld_llchit = {
1338 .header = HEADER_SPAN("-- LLC Load Hit --", "Llc", 1),
1339 .name = "ld_lclhit",
1340 .cmp = ld_llchit_cmp,
1341 .entry = ld_llchit_entry,
1342 .width = 8,
1343};
1344
1345static struct c2c_dimension dim_ld_rmthit = {
1346 .header = HEADER_SPAN_LOW("Rmt"),
1347 .name = "ld_rmthit",
1348 .cmp = rmt_hit_cmp,
1349 .entry = rmt_hit_entry,
1350 .width = 8,
1351};
1352
Jiri Olsa04402d22016-05-19 10:10:51 +02001353static struct c2c_dimension dim_ld_llcmiss = {
1354 .header = HEADER_BOTH("LLC", "Ld Miss"),
1355 .name = "ld_llcmiss",
1356 .cmp = ld_llcmiss_cmp,
1357 .entry = ld_llcmiss_entry,
1358 .width = 7,
1359};
1360
Jiri Olsa01b84d72016-05-04 10:35:29 +02001361static struct c2c_dimension dim_tot_recs = {
1362 .header = HEADER_BOTH("Total", "records"),
1363 .name = "tot_recs",
1364 .cmp = tot_recs_cmp,
1365 .entry = tot_recs_entry,
1366 .width = 7,
1367};
1368
Jiri Olsa55177c42016-05-19 09:52:37 +02001369static struct c2c_dimension dim_tot_loads = {
1370 .header = HEADER_BOTH("Total", "Loads"),
1371 .name = "tot_loads",
1372 .cmp = tot_loads_cmp,
1373 .entry = tot_loads_entry,
1374 .width = 7,
1375};
1376
Jiri Olsa55b95772016-05-29 10:21:45 +02001377static struct c2c_header percent_hitm_header[] = {
1378 [DISPLAY_LCL] = HEADER_BOTH("Lcl", "Hitm"),
1379 [DISPLAY_RMT] = HEADER_BOTH("Rmt", "Hitm"),
Jiri Olsad940bac2016-11-21 22:33:30 +01001380 [DISPLAY_TOT] = HEADER_BOTH("Tot", "Hitm"),
Jiri Olsa55b95772016-05-29 10:21:45 +02001381};
1382
Jiri Olsaf0c50c12016-05-04 10:50:09 +02001383static struct c2c_dimension dim_percent_hitm = {
Jiri Olsaf0c50c12016-05-04 10:50:09 +02001384 .name = "percent_hitm",
1385 .cmp = percent_hitm_cmp,
1386 .entry = percent_hitm_entry,
1387 .color = percent_hitm_color,
1388 .width = 7,
1389};
1390
Jiri Olsa9cb35002016-05-04 12:16:50 +02001391static struct c2c_dimension dim_percent_rmt_hitm = {
1392 .header = HEADER_SPAN("----- HITM -----", "Rmt", 1),
1393 .name = "percent_rmt_hitm",
1394 .cmp = percent_rmt_hitm_cmp,
1395 .entry = percent_rmt_hitm_entry,
1396 .color = percent_rmt_hitm_color,
1397 .width = 7,
1398};
1399
1400static struct c2c_dimension dim_percent_lcl_hitm = {
1401 .header = HEADER_SPAN_LOW("Lcl"),
1402 .name = "percent_lcl_hitm",
1403 .cmp = percent_lcl_hitm_cmp,
1404 .entry = percent_lcl_hitm_entry,
1405 .color = percent_lcl_hitm_color,
1406 .width = 7,
1407};
1408
1409static struct c2c_dimension dim_percent_stores_l1hit = {
1410 .header = HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1411 .name = "percent_stores_l1hit",
1412 .cmp = percent_stores_l1hit_cmp,
1413 .entry = percent_stores_l1hit_entry,
1414 .color = percent_stores_l1hit_color,
1415 .width = 7,
1416};
1417
1418static struct c2c_dimension dim_percent_stores_l1miss = {
1419 .header = HEADER_SPAN_LOW("L1 Miss"),
1420 .name = "percent_stores_l1miss",
1421 .cmp = percent_stores_l1miss_cmp,
1422 .entry = percent_stores_l1miss_entry,
1423 .color = percent_stores_l1miss_color,
1424 .width = 7,
1425};
1426
Jiri Olsa6c70f542016-05-28 12:30:13 +02001427static struct c2c_dimension dim_dram_lcl = {
1428 .header = HEADER_SPAN("--- Load Dram ----", "Lcl", 1),
1429 .name = "dram_lcl",
1430 .cmp = lcl_dram_cmp,
1431 .entry = lcl_dram_entry,
1432 .width = 8,
1433};
1434
1435static struct c2c_dimension dim_dram_rmt = {
1436 .header = HEADER_SPAN_LOW("Rmt"),
1437 .name = "dram_rmt",
1438 .cmp = rmt_dram_cmp,
1439 .entry = rmt_dram_entry,
1440 .width = 8,
1441};
1442
Jiri Olsa36d3deb2016-05-24 13:09:47 +02001443static struct c2c_dimension dim_pid = {
1444 .header = HEADER_LOW("Pid"),
1445 .name = "pid",
1446 .cmp = pid_cmp,
1447 .entry = pid_entry,
1448 .width = 7,
1449};
1450
Jiri Olsae87019c2016-05-25 08:50:10 +02001451static struct c2c_dimension dim_tid = {
1452 .header = HEADER_LOW("Tid"),
1453 .name = "tid",
1454 .se = &sort_thread,
1455};
1456
Jiri Olsa51dedaa2016-05-24 23:41:52 +02001457static struct c2c_dimension dim_symbol = {
1458 .name = "symbol",
1459 .se = &sort_sym,
1460};
1461
1462static struct c2c_dimension dim_dso = {
1463 .header = HEADER_BOTH("Shared", "Object"),
1464 .name = "dso",
1465 .se = &sort_dso,
1466};
1467
Jiri Olsa1e181b92016-06-03 15:40:28 +02001468static struct c2c_header header_node[3] = {
1469 HEADER_LOW("Node"),
1470 HEADER_LOW("Node{cpus %hitms %stores}"),
1471 HEADER_LOW("Node{cpu list}"),
1472};
1473
1474static struct c2c_dimension dim_node = {
1475 .name = "node",
1476 .cmp = empty_cmp,
1477 .entry = node_entry,
1478 .width = 4,
1479};
1480
Jiri Olsa92062d52016-06-05 13:40:53 +02001481static struct c2c_dimension dim_mean_rmt = {
1482 .header = HEADER_SPAN("---------- cycles ----------", "rmt hitm", 2),
1483 .name = "mean_rmt",
1484 .cmp = empty_cmp,
1485 .entry = mean_rmt_entry,
1486 .width = 8,
1487};
1488
1489static struct c2c_dimension dim_mean_lcl = {
1490 .header = HEADER_SPAN_LOW("lcl hitm"),
1491 .name = "mean_lcl",
1492 .cmp = empty_cmp,
1493 .entry = mean_lcl_entry,
1494 .width = 8,
1495};
1496
1497static struct c2c_dimension dim_mean_load = {
1498 .header = HEADER_SPAN_LOW("load"),
1499 .name = "mean_load",
1500 .cmp = empty_cmp,
1501 .entry = mean_load_entry,
1502 .width = 8,
1503};
1504
Jiri Olsab6fe2bb2016-06-23 23:05:52 +02001505static struct c2c_dimension dim_cpucnt = {
1506 .header = HEADER_BOTH("cpu", "cnt"),
1507 .name = "cpucnt",
1508 .cmp = empty_cmp,
1509 .entry = cpucnt_entry,
1510 .width = 8,
1511};
1512
Jiri Olsa89d9ba8f2016-07-10 15:47:40 +02001513static struct c2c_dimension dim_srcline = {
1514 .name = "cl_srcline",
1515 .se = &sort_srcline,
1516};
1517
Jiri Olsabb342dae2016-07-06 15:40:09 +02001518static struct c2c_dimension dim_dcacheline_idx = {
1519 .header = HEADER_LOW("Index"),
1520 .name = "cl_idx",
1521 .cmp = empty_cmp,
1522 .entry = cl_idx_entry,
1523 .width = 5,
1524};
1525
1526static struct c2c_dimension dim_dcacheline_num = {
1527 .header = HEADER_LOW("Num"),
1528 .name = "cl_num",
1529 .cmp = empty_cmp,
1530 .entry = cl_idx_entry,
1531 .width = 5,
1532};
1533
1534static struct c2c_dimension dim_dcacheline_num_empty = {
1535 .header = HEADER_LOW("Num"),
1536 .name = "cl_num_empty",
1537 .cmp = empty_cmp,
1538 .entry = cl_idx_empty_entry,
1539 .width = 5,
1540};
1541
Jiri Olsac75540e2016-09-22 17:36:41 +02001542static struct c2c_dimension *dimensions[] = {
Jiri Olsacbb88502016-09-22 17:36:48 +02001543 &dim_dcacheline,
Jiri Olsa48acdeb2016-04-29 14:37:06 +02001544 &dim_offset,
Jiri Olsa43575a92016-05-03 21:48:56 +02001545 &dim_iaddr,
Jiri Olsa97cb4862016-05-23 16:20:14 +02001546 &dim_tot_hitm,
1547 &dim_lcl_hitm,
1548 &dim_rmt_hitm,
1549 &dim_cl_lcl_hitm,
1550 &dim_cl_rmt_hitm,
Jiri Olsa0f188962016-05-04 10:10:11 +02001551 &dim_stores,
1552 &dim_stores_l1hit,
1553 &dim_stores_l1miss,
1554 &dim_cl_stores_l1hit,
1555 &dim_cl_stores_l1miss,
Jiri Olsa1295f682016-05-04 10:18:24 +02001556 &dim_ld_fbhit,
1557 &dim_ld_l1hit,
1558 &dim_ld_l2hit,
Jiri Olsa4d089102016-05-04 10:27:51 +02001559 &dim_ld_llchit,
1560 &dim_ld_rmthit,
Jiri Olsa04402d22016-05-19 10:10:51 +02001561 &dim_ld_llcmiss,
Jiri Olsa01b84d72016-05-04 10:35:29 +02001562 &dim_tot_recs,
Jiri Olsa55177c42016-05-19 09:52:37 +02001563 &dim_tot_loads,
Jiri Olsaf0c50c12016-05-04 10:50:09 +02001564 &dim_percent_hitm,
Jiri Olsa9cb35002016-05-04 12:16:50 +02001565 &dim_percent_rmt_hitm,
1566 &dim_percent_lcl_hitm,
1567 &dim_percent_stores_l1hit,
1568 &dim_percent_stores_l1miss,
Jiri Olsa6c70f542016-05-28 12:30:13 +02001569 &dim_dram_lcl,
1570 &dim_dram_rmt,
Jiri Olsa36d3deb2016-05-24 13:09:47 +02001571 &dim_pid,
Jiri Olsae87019c2016-05-25 08:50:10 +02001572 &dim_tid,
Jiri Olsa51dedaa2016-05-24 23:41:52 +02001573 &dim_symbol,
1574 &dim_dso,
Jiri Olsa1e181b92016-06-03 15:40:28 +02001575 &dim_node,
Jiri Olsa92062d52016-06-05 13:40:53 +02001576 &dim_mean_rmt,
1577 &dim_mean_lcl,
1578 &dim_mean_load,
Jiri Olsab6fe2bb2016-06-23 23:05:52 +02001579 &dim_cpucnt,
Jiri Olsa89d9ba8f2016-07-10 15:47:40 +02001580 &dim_srcline,
Jiri Olsabb342dae2016-07-06 15:40:09 +02001581 &dim_dcacheline_idx,
1582 &dim_dcacheline_num,
1583 &dim_dcacheline_num_empty,
Jiri Olsac75540e2016-09-22 17:36:41 +02001584 NULL,
1585};
1586
1587static void fmt_free(struct perf_hpp_fmt *fmt)
1588{
1589 struct c2c_fmt *c2c_fmt;
1590
1591 c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
1592 free(c2c_fmt);
1593}
1594
1595static bool fmt_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b)
1596{
1597 struct c2c_fmt *c2c_a = container_of(a, struct c2c_fmt, fmt);
1598 struct c2c_fmt *c2c_b = container_of(b, struct c2c_fmt, fmt);
1599
1600 return c2c_a->dim == c2c_b->dim;
1601}
1602
1603static struct c2c_dimension *get_dimension(const char *name)
1604{
1605 unsigned int i;
1606
1607 for (i = 0; dimensions[i]; i++) {
1608 struct c2c_dimension *dim = dimensions[i];
1609
1610 if (!strcmp(dim->name, name))
1611 return dim;
1612 };
1613
1614 return NULL;
1615}
1616
Jiri Olsa8d3f9382016-09-22 17:36:42 +02001617static int c2c_se_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
1618 struct hist_entry *he)
1619{
1620 struct c2c_fmt *c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
1621 struct c2c_dimension *dim = c2c_fmt->dim;
1622 size_t len = fmt->user_len;
1623
Jiri Olsa590b6a32016-07-10 16:25:15 +02001624 if (!len) {
Jiri Olsa8d3f9382016-09-22 17:36:42 +02001625 len = hists__col_len(he->hists, dim->se->se_width_idx);
1626
Jiri Olsa590b6a32016-07-10 16:25:15 +02001627 if (dim == &dim_symbol || dim == &dim_srcline)
1628 len = symbol_width(he->hists, dim->se);
1629 }
1630
Jiri Olsa8d3f9382016-09-22 17:36:42 +02001631 return dim->se->se_snprintf(he, hpp->buf, hpp->size, len);
1632}
1633
1634static int64_t c2c_se_cmp(struct perf_hpp_fmt *fmt,
1635 struct hist_entry *a, struct hist_entry *b)
1636{
1637 struct c2c_fmt *c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
1638 struct c2c_dimension *dim = c2c_fmt->dim;
1639
1640 return dim->se->se_cmp(a, b);
1641}
1642
1643static int64_t c2c_se_collapse(struct perf_hpp_fmt *fmt,
1644 struct hist_entry *a, struct hist_entry *b)
1645{
1646 struct c2c_fmt *c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
1647 struct c2c_dimension *dim = c2c_fmt->dim;
1648 int64_t (*collapse_fn)(struct hist_entry *, struct hist_entry *);
1649
1650 collapse_fn = dim->se->se_collapse ?: dim->se->se_cmp;
1651 return collapse_fn(a, b);
1652}
1653
Jiri Olsac75540e2016-09-22 17:36:41 +02001654static struct c2c_fmt *get_format(const char *name)
1655{
1656 struct c2c_dimension *dim = get_dimension(name);
1657 struct c2c_fmt *c2c_fmt;
1658 struct perf_hpp_fmt *fmt;
1659
1660 if (!dim)
1661 return NULL;
1662
1663 c2c_fmt = zalloc(sizeof(*c2c_fmt));
1664 if (!c2c_fmt)
1665 return NULL;
1666
1667 c2c_fmt->dim = dim;
1668
1669 fmt = &c2c_fmt->fmt;
1670 INIT_LIST_HEAD(&fmt->list);
1671 INIT_LIST_HEAD(&fmt->sort_list);
1672
Jiri Olsa8d3f9382016-09-22 17:36:42 +02001673 fmt->cmp = dim->se ? c2c_se_cmp : dim->cmp;
1674 fmt->sort = dim->se ? c2c_se_cmp : dim->cmp;
Jiri Olsa9cb35002016-05-04 12:16:50 +02001675 fmt->color = dim->se ? NULL : dim->color;
Jiri Olsa8d3f9382016-09-22 17:36:42 +02001676 fmt->entry = dim->se ? c2c_se_entry : dim->entry;
Jiri Olsac75540e2016-09-22 17:36:41 +02001677 fmt->header = c2c_header;
1678 fmt->width = c2c_width;
Jiri Olsa8d3f9382016-09-22 17:36:42 +02001679 fmt->collapse = dim->se ? c2c_se_collapse : dim->cmp;
Jiri Olsac75540e2016-09-22 17:36:41 +02001680 fmt->equal = fmt_equal;
1681 fmt->free = fmt_free;
1682
1683 return c2c_fmt;
1684}
1685
1686static int c2c_hists__init_output(struct perf_hpp_list *hpp_list, char *name)
1687{
1688 struct c2c_fmt *c2c_fmt = get_format(name);
1689
Jiri Olsa5f2eca82016-09-22 17:36:43 +02001690 if (!c2c_fmt) {
1691 reset_dimensions();
1692 return output_field_add(hpp_list, name);
1693 }
Jiri Olsac75540e2016-09-22 17:36:41 +02001694
1695 perf_hpp_list__column_register(hpp_list, &c2c_fmt->fmt);
1696 return 0;
1697}
1698
1699static int c2c_hists__init_sort(struct perf_hpp_list *hpp_list, char *name)
1700{
1701 struct c2c_fmt *c2c_fmt = get_format(name);
Jiri Olsa51dedaa2016-05-24 23:41:52 +02001702 struct c2c_dimension *dim;
Jiri Olsac75540e2016-09-22 17:36:41 +02001703
Jiri Olsa5f2eca82016-09-22 17:36:43 +02001704 if (!c2c_fmt) {
1705 reset_dimensions();
1706 return sort_dimension__add(hpp_list, name, NULL, 0);
1707 }
Jiri Olsac75540e2016-09-22 17:36:41 +02001708
Jiri Olsa51dedaa2016-05-24 23:41:52 +02001709 dim = c2c_fmt->dim;
1710 if (dim == &dim_dso)
1711 hpp_list->dso = 1;
1712
Jiri Olsac75540e2016-09-22 17:36:41 +02001713 perf_hpp_list__register_sort_field(hpp_list, &c2c_fmt->fmt);
1714 return 0;
1715}
1716
1717#define PARSE_LIST(_list, _fn) \
1718 do { \
1719 char *tmp, *tok; \
1720 ret = 0; \
1721 \
1722 if (!_list) \
1723 break; \
1724 \
1725 for (tok = strtok_r((char *)_list, ", ", &tmp); \
1726 tok; tok = strtok_r(NULL, ", ", &tmp)) { \
1727 ret = _fn(hpp_list, tok); \
1728 if (ret == -EINVAL) { \
Arnaldo Carvalho de Melo62d94b02017-06-27 11:22:31 -03001729 pr_err("Invalid --fields key: `%s'", tok); \
Jiri Olsac75540e2016-09-22 17:36:41 +02001730 break; \
1731 } else if (ret == -ESRCH) { \
Arnaldo Carvalho de Melo62d94b02017-06-27 11:22:31 -03001732 pr_err("Unknown --fields key: `%s'", tok); \
Jiri Olsac75540e2016-09-22 17:36:41 +02001733 break; \
1734 } \
1735 } \
1736 } while (0)
1737
1738static int hpp_list__parse(struct perf_hpp_list *hpp_list,
1739 const char *output_,
1740 const char *sort_)
1741{
1742 char *output = output_ ? strdup(output_) : NULL;
1743 char *sort = sort_ ? strdup(sort_) : NULL;
1744 int ret;
1745
1746 PARSE_LIST(output, c2c_hists__init_output);
1747 PARSE_LIST(sort, c2c_hists__init_sort);
1748
1749 /* copy sort keys to output fields */
1750 perf_hpp__setup_output_field(hpp_list);
1751
1752 /*
1753 * We dont need other sorting keys other than those
1754 * we already specified. It also really slows down
1755 * the processing a lot with big number of output
1756 * fields, so switching this off for c2c.
1757 */
1758
1759#if 0
1760 /* and then copy output fields to sort keys */
1761 perf_hpp__append_sort_keys(&hists->list);
1762#endif
1763
1764 free(output);
1765 free(sort);
1766 return ret;
1767}
1768
1769static int c2c_hists__init(struct c2c_hists *hists,
Jiri Olsa1d62fcd2016-05-24 10:12:31 +02001770 const char *sort,
1771 int nr_header_lines)
Jiri Olsac75540e2016-09-22 17:36:41 +02001772{
1773 __hists__init(&hists->hists, &hists->list);
1774
1775 /*
1776 * Initialize only with sort fields, we need to resort
1777 * later anyway, and that's where we add output fields
1778 * as well.
1779 */
1780 perf_hpp_list__init(&hists->list);
1781
Jiri Olsa1d62fcd2016-05-24 10:12:31 +02001782 /* Overload number of header lines.*/
1783 hists->list.nr_header_lines = nr_header_lines;
1784
Jiri Olsac75540e2016-09-22 17:36:41 +02001785 return hpp_list__parse(&hists->list, NULL, sort);
1786}
1787
Jiri Olsac75540e2016-09-22 17:36:41 +02001788static int c2c_hists__reinit(struct c2c_hists *c2c_hists,
1789 const char *output,
1790 const char *sort)
1791{
1792 perf_hpp__reset_output_field(&c2c_hists->list);
1793 return hpp_list__parse(&c2c_hists->list, output, sort);
1794}
1795
Jiri Olsa9857b712016-08-17 14:55:23 +02001796#define DISPLAY_LINE_LIMIT 0.0005
1797
1798static bool he__display(struct hist_entry *he, struct c2c_stats *stats)
1799{
1800 struct c2c_hist_entry *c2c_he;
1801 double ld_dist;
1802
Jiri Olsaaf09b2d2016-10-11 13:52:05 +02001803 if (c2c.show_all)
1804 return true;
Jiri Olsa9857b712016-08-17 14:55:23 +02001805
1806 c2c_he = container_of(he, struct c2c_hist_entry, he);
1807
Jiri Olsa55b95772016-05-29 10:21:45 +02001808#define FILTER_HITM(__h) \
1809 if (stats->__h) { \
1810 ld_dist = ((double)c2c_he->stats.__h / stats->__h); \
1811 if (ld_dist < DISPLAY_LINE_LIMIT) \
1812 he->filtered = HIST_FILTER__C2C; \
1813 } else { \
1814 he->filtered = HIST_FILTER__C2C; \
Jiri Olsa9857b712016-08-17 14:55:23 +02001815 }
1816
Jiri Olsa55b95772016-05-29 10:21:45 +02001817 switch (c2c.display) {
1818 case DISPLAY_LCL:
1819 FILTER_HITM(lcl_hitm);
1820 break;
1821 case DISPLAY_RMT:
1822 FILTER_HITM(rmt_hitm);
Jiri Olsad940bac2016-11-21 22:33:30 +01001823 break;
1824 case DISPLAY_TOT:
1825 FILTER_HITM(tot_hitm);
Jiri Olsa55b95772016-05-29 10:21:45 +02001826 default:
1827 break;
1828 };
1829
1830#undef FILTER_HITM
1831
Jiri Olsa9857b712016-08-17 14:55:23 +02001832 return he->filtered == 0;
1833}
1834
1835static inline int valid_hitm_or_store(struct hist_entry *he)
1836{
1837 struct c2c_hist_entry *c2c_he;
Jiri Olsa55b95772016-05-29 10:21:45 +02001838 bool has_hitm;
Jiri Olsa9857b712016-08-17 14:55:23 +02001839
1840 c2c_he = container_of(he, struct c2c_hist_entry, he);
Jiri Olsad940bac2016-11-21 22:33:30 +01001841 has_hitm = c2c.display == DISPLAY_TOT ? c2c_he->stats.tot_hitm :
1842 c2c.display == DISPLAY_LCL ? c2c_he->stats.lcl_hitm :
1843 c2c_he->stats.rmt_hitm;
Jiri Olsa55b95772016-05-29 10:21:45 +02001844 return has_hitm || c2c_he->stats.store;
Jiri Olsa9857b712016-08-17 14:55:23 +02001845}
1846
Jiri Olsa25aa84e2016-06-07 19:02:43 +02001847static void calc_width(struct hist_entry *he)
1848{
1849 struct c2c_hists *c2c_hists;
1850
1851 c2c_hists = container_of(he->hists, struct c2c_hists, hists);
1852 hists__calc_col_len(&c2c_hists->hists, he);
1853}
1854
Jiri Olsa89d9ba8f2016-07-10 15:47:40 +02001855static int filter_cb(struct hist_entry *he)
Jiri Olsaec06f9b2016-09-22 17:36:45 +02001856{
Jiri Olsa89d9ba8f2016-07-10 15:47:40 +02001857 if (c2c.show_src && !he->srcline)
1858 he->srcline = hist_entry__get_srcline(he);
1859
Jiri Olsa25aa84e2016-06-07 19:02:43 +02001860 calc_width(he);
1861
Jiri Olsa9857b712016-08-17 14:55:23 +02001862 if (!valid_hitm_or_store(he))
1863 he->filtered = HIST_FILTER__C2C;
1864
Jiri Olsaec06f9b2016-09-22 17:36:45 +02001865 return 0;
1866}
1867
1868static int resort_cl_cb(struct hist_entry *he)
1869{
1870 struct c2c_hist_entry *c2c_he;
1871 struct c2c_hists *c2c_hists;
Jiri Olsa9857b712016-08-17 14:55:23 +02001872 bool display = he__display(he, &c2c.hitm_stats);
Jiri Olsaec06f9b2016-09-22 17:36:45 +02001873
1874 c2c_he = container_of(he, struct c2c_hist_entry, he);
1875 c2c_hists = c2c_he->hists;
1876
Jiri Olsa25aa84e2016-06-07 19:02:43 +02001877 calc_width(he);
1878
Jiri Olsa9857b712016-08-17 14:55:23 +02001879 if (display && c2c_hists) {
Jiri Olsabb342dae2016-07-06 15:40:09 +02001880 static unsigned int idx;
1881
1882 c2c_he->cacheline_idx = idx++;
1883
Jiri Olsafc9c6302016-05-24 14:14:38 +02001884 c2c_hists__reinit(c2c_hists, c2c.cl_output, c2c.cl_resort);
Jiri Olsa22dd59d2016-05-10 14:08:29 +02001885
Jiri Olsaec06f9b2016-09-22 17:36:45 +02001886 hists__collapse_resort(&c2c_hists->hists, NULL);
1887 hists__output_resort_cb(&c2c_hists->hists, NULL, filter_cb);
1888 }
1889
1890 return 0;
1891}
1892
Jiri Olsa1e181b92016-06-03 15:40:28 +02001893static void setup_nodes_header(void)
1894{
1895 dim_node.header = header_node[c2c.node_info];
1896}
1897
1898static int setup_nodes(struct perf_session *session)
1899{
1900 struct numa_node *n;
1901 unsigned long **nodes;
1902 int node, cpu;
1903 int *cpu2node;
1904
1905 if (c2c.node_info > 2)
1906 c2c.node_info = 2;
1907
1908 c2c.nodes_cnt = session->header.env.nr_numa_nodes;
1909 c2c.cpus_cnt = session->header.env.nr_cpus_online;
1910
1911 n = session->header.env.numa_nodes;
1912 if (!n)
1913 return -EINVAL;
1914
1915 nodes = zalloc(sizeof(unsigned long *) * c2c.nodes_cnt);
1916 if (!nodes)
1917 return -ENOMEM;
1918
1919 c2c.nodes = nodes;
1920
1921 cpu2node = zalloc(sizeof(int) * c2c.cpus_cnt);
1922 if (!cpu2node)
1923 return -ENOMEM;
1924
1925 for (cpu = 0; cpu < c2c.cpus_cnt; cpu++)
1926 cpu2node[cpu] = -1;
1927
1928 c2c.cpu2node = cpu2node;
1929
1930 for (node = 0; node < c2c.nodes_cnt; node++) {
1931 struct cpu_map *map = n[node].map;
1932 unsigned long *set;
1933
1934 set = bitmap_alloc(c2c.cpus_cnt);
1935 if (!set)
1936 return -ENOMEM;
1937
1938 for (cpu = 0; cpu < map->nr; cpu++) {
1939 set_bit(map->map[cpu], set);
1940
1941 if (WARN_ONCE(cpu2node[map->map[cpu]] != -1, "node/cpu topology bug"))
1942 return -EINVAL;
1943
1944 cpu2node[map->map[cpu]] = node;
1945 }
1946
1947 nodes[node] = set;
1948 }
1949
1950 setup_nodes_header();
1951 return 0;
1952}
1953
Jiri Olsa7ef2efa2016-07-01 11:12:11 +02001954#define HAS_HITMS(__h) ((__h)->stats.lcl_hitm || (__h)->stats.rmt_hitm)
1955
1956static int resort_hitm_cb(struct hist_entry *he)
1957{
1958 struct c2c_hist_entry *c2c_he;
1959 c2c_he = container_of(he, struct c2c_hist_entry, he);
1960
1961 if (HAS_HITMS(c2c_he)) {
1962 c2c.shared_clines++;
1963 c2c_add_stats(&c2c.hitm_stats, &c2c_he->stats);
1964 }
1965
1966 return 0;
1967}
1968
1969static int hists__iterate_cb(struct hists *hists, hists__resort_cb_t cb)
1970{
1971 struct rb_node *next = rb_first(&hists->entries);
1972 int ret = 0;
1973
1974 while (next) {
1975 struct hist_entry *he;
1976
1977 he = rb_entry(next, struct hist_entry, rb_node);
1978 ret = cb(he);
1979 if (ret)
1980 break;
1981 next = rb_next(&he->rb_node);
1982 }
1983
1984 return ret;
1985}
1986
Jiri Olsa74c63a22016-05-02 20:01:59 +02001987static void print_c2c__display_stats(FILE *out)
1988{
1989 int llc_misses;
1990 struct c2c_stats *stats = &c2c.hists.stats;
1991
1992 llc_misses = stats->lcl_dram +
1993 stats->rmt_dram +
1994 stats->rmt_hit +
1995 stats->rmt_hitm;
1996
1997 fprintf(out, "=================================================\n");
1998 fprintf(out, " Trace Event Information \n");
1999 fprintf(out, "=================================================\n");
2000 fprintf(out, " Total records : %10d\n", stats->nr_entries);
2001 fprintf(out, " Locked Load/Store Operations : %10d\n", stats->locks);
2002 fprintf(out, " Load Operations : %10d\n", stats->load);
2003 fprintf(out, " Loads - uncacheable : %10d\n", stats->ld_uncache);
2004 fprintf(out, " Loads - IO : %10d\n", stats->ld_io);
2005 fprintf(out, " Loads - Miss : %10d\n", stats->ld_miss);
2006 fprintf(out, " Loads - no mapping : %10d\n", stats->ld_noadrs);
2007 fprintf(out, " Load Fill Buffer Hit : %10d\n", stats->ld_fbhit);
2008 fprintf(out, " Load L1D hit : %10d\n", stats->ld_l1hit);
2009 fprintf(out, " Load L2D hit : %10d\n", stats->ld_l2hit);
2010 fprintf(out, " Load LLC hit : %10d\n", stats->ld_llchit + stats->lcl_hitm);
2011 fprintf(out, " Load Local HITM : %10d\n", stats->lcl_hitm);
2012 fprintf(out, " Load Remote HITM : %10d\n", stats->rmt_hitm);
2013 fprintf(out, " Load Remote HIT : %10d\n", stats->rmt_hit);
2014 fprintf(out, " Load Local DRAM : %10d\n", stats->lcl_dram);
2015 fprintf(out, " Load Remote DRAM : %10d\n", stats->rmt_dram);
2016 fprintf(out, " Load MESI State Exclusive : %10d\n", stats->ld_excl);
2017 fprintf(out, " Load MESI State Shared : %10d\n", stats->ld_shared);
2018 fprintf(out, " Load LLC Misses : %10d\n", llc_misses);
2019 fprintf(out, " LLC Misses to Local DRAM : %10.1f%%\n", ((double)stats->lcl_dram/(double)llc_misses) * 100.);
2020 fprintf(out, " LLC Misses to Remote DRAM : %10.1f%%\n", ((double)stats->rmt_dram/(double)llc_misses) * 100.);
2021 fprintf(out, " LLC Misses to Remote cache (HIT) : %10.1f%%\n", ((double)stats->rmt_hit /(double)llc_misses) * 100.);
2022 fprintf(out, " LLC Misses to Remote cache (HITM) : %10.1f%%\n", ((double)stats->rmt_hitm/(double)llc_misses) * 100.);
2023 fprintf(out, " Store Operations : %10d\n", stats->store);
2024 fprintf(out, " Store - uncacheable : %10d\n", stats->st_uncache);
2025 fprintf(out, " Store - no mapping : %10d\n", stats->st_noadrs);
2026 fprintf(out, " Store L1D Hit : %10d\n", stats->st_l1hit);
2027 fprintf(out, " Store L1D Miss : %10d\n", stats->st_l1miss);
2028 fprintf(out, " No Page Map Rejects : %10d\n", stats->nomap);
2029 fprintf(out, " Unable to parse data source : %10d\n", stats->noparse);
2030}
2031
Jiri Olsa7ef2efa2016-07-01 11:12:11 +02002032static void print_shared_cacheline_info(FILE *out)
2033{
2034 struct c2c_stats *stats = &c2c.hitm_stats;
2035 int hitm_cnt = stats->lcl_hitm + stats->rmt_hitm;
2036
2037 fprintf(out, "=================================================\n");
2038 fprintf(out, " Global Shared Cache Line Event Information \n");
2039 fprintf(out, "=================================================\n");
2040 fprintf(out, " Total Shared Cache Lines : %10d\n", c2c.shared_clines);
2041 fprintf(out, " Load HITs on shared lines : %10d\n", stats->load);
2042 fprintf(out, " Fill Buffer Hits on shared lines : %10d\n", stats->ld_fbhit);
2043 fprintf(out, " L1D hits on shared lines : %10d\n", stats->ld_l1hit);
2044 fprintf(out, " L2D hits on shared lines : %10d\n", stats->ld_l2hit);
2045 fprintf(out, " LLC hits on shared lines : %10d\n", stats->ld_llchit + stats->lcl_hitm);
2046 fprintf(out, " Locked Access on shared lines : %10d\n", stats->locks);
2047 fprintf(out, " Store HITs on shared lines : %10d\n", stats->store);
2048 fprintf(out, " Store L1D hits on shared lines : %10d\n", stats->st_l1hit);
2049 fprintf(out, " Total Merged records : %10d\n", hitm_cnt + stats->store);
2050}
2051
Jiri Olsa2d388bd2016-05-03 14:32:56 +02002052static void print_cacheline(struct c2c_hists *c2c_hists,
2053 struct hist_entry *he_cl,
2054 struct perf_hpp_list *hpp_list,
2055 FILE *out)
2056{
2057 char bf[1000];
2058 struct perf_hpp hpp = {
2059 .buf = bf,
2060 .size = 1000,
2061 };
2062 static bool once;
2063
2064 if (!once) {
2065 hists__fprintf_headers(&c2c_hists->hists, out);
2066 once = true;
2067 } else {
2068 fprintf(out, "\n");
2069 }
2070
Jiri Olsabb342dae2016-07-06 15:40:09 +02002071 fprintf(out, " -------------------------------------------------------------\n");
Jiri Olsa2d388bd2016-05-03 14:32:56 +02002072 __hist_entry__snprintf(he_cl, &hpp, hpp_list);
2073 fprintf(out, "%s\n", bf);
Jiri Olsabb342dae2016-07-06 15:40:09 +02002074 fprintf(out, " -------------------------------------------------------------\n");
Jiri Olsa2d388bd2016-05-03 14:32:56 +02002075
2076 hists__fprintf(&c2c_hists->hists, false, 0, 0, 0, out, true);
2077}
2078
2079static void print_pareto(FILE *out)
2080{
2081 struct perf_hpp_list hpp_list;
2082 struct rb_node *nd;
2083 int ret;
2084
2085 perf_hpp_list__init(&hpp_list);
2086 ret = hpp_list__parse(&hpp_list,
Jiri Olsabb342dae2016-07-06 15:40:09 +02002087 "cl_num,"
Jiri Olsa2d388bd2016-05-03 14:32:56 +02002088 "cl_rmt_hitm,"
2089 "cl_lcl_hitm,"
2090 "cl_stores_l1hit,"
2091 "cl_stores_l1miss,"
2092 "dcacheline",
2093 NULL);
2094
2095 if (WARN_ONCE(ret, "failed to setup sort entries\n"))
2096 return;
2097
2098 nd = rb_first(&c2c.hists.hists.entries);
2099
2100 for (; nd; nd = rb_next(nd)) {
2101 struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
2102 struct c2c_hist_entry *c2c_he;
2103
2104 if (he->filtered)
2105 continue;
2106
2107 c2c_he = container_of(he, struct c2c_hist_entry, he);
2108 print_cacheline(c2c_he->hists, he, &hpp_list, out);
2109 }
2110}
2111
Jiri Olsa2709b972016-08-27 11:40:23 +02002112static void print_c2c_info(FILE *out, struct perf_session *session)
2113{
2114 struct perf_evlist *evlist = session->evlist;
2115 struct perf_evsel *evsel;
2116 bool first = true;
2117
2118 fprintf(out, "=================================================\n");
2119 fprintf(out, " c2c details \n");
2120 fprintf(out, "=================================================\n");
2121
2122 evlist__for_each_entry(evlist, evsel) {
2123 fprintf(out, "%-36s: %s\n", first ? " Events" : "",
2124 perf_evsel__name(evsel));
2125 first = false;
2126 }
Jiri Olsa55b95772016-05-29 10:21:45 +02002127 fprintf(out, " Cachelines sort on : %s HITMs\n",
Jiri Olsad940bac2016-11-21 22:33:30 +01002128 display_str[c2c.display]);
Jiri Olsafc9c6302016-05-24 14:14:38 +02002129 fprintf(out, " Cacheline data grouping : %s\n", c2c.cl_sort);
Jiri Olsa2709b972016-08-27 11:40:23 +02002130}
2131
2132static void perf_c2c__hists_fprintf(FILE *out, struct perf_session *session)
Jiri Olsa2d388bd2016-05-03 14:32:56 +02002133{
2134 setup_pager();
2135
Jiri Olsa74c63a22016-05-02 20:01:59 +02002136 print_c2c__display_stats(out);
Jiri Olsa7ef2efa2016-07-01 11:12:11 +02002137 fprintf(out, "\n");
2138 print_shared_cacheline_info(out);
Jiri Olsa2709b972016-08-27 11:40:23 +02002139 fprintf(out, "\n");
2140 print_c2c_info(out, session);
Jiri Olsa74c63a22016-05-02 20:01:59 +02002141
2142 if (c2c.stats_only)
2143 return;
2144
Jiri Olsa2d388bd2016-05-03 14:32:56 +02002145 fprintf(out, "\n");
2146 fprintf(out, "=================================================\n");
2147 fprintf(out, " Shared Data Cache Line Table \n");
2148 fprintf(out, "=================================================\n");
2149 fprintf(out, "#\n");
2150
2151 hists__fprintf(&c2c.hists.hists, true, 0, 0, 0, stdout, false);
2152
2153 fprintf(out, "\n");
2154 fprintf(out, "=================================================\n");
2155 fprintf(out, " Shared Cache Line Distribution Pareto \n");
2156 fprintf(out, "=================================================\n");
2157 fprintf(out, "#\n");
2158
2159 print_pareto(out);
2160}
Jiri Olsa1e181b92016-06-03 15:40:28 +02002161
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002162#ifdef HAVE_SLANG_SUPPORT
2163static void c2c_browser__update_nr_entries(struct hist_browser *hb)
2164{
2165 u64 nr_entries = 0;
2166 struct rb_node *nd = rb_first(&hb->hists->entries);
2167
2168 while (nd) {
2169 struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
2170
2171 if (!he->filtered)
2172 nr_entries++;
2173
2174 nd = rb_next(nd);
2175 }
2176
2177 hb->nr_non_filtered_entries = nr_entries;
2178}
2179
Jiri Olsaf1c5fd42016-05-02 18:30:44 +02002180struct c2c_cacheline_browser {
2181 struct hist_browser hb;
2182 struct hist_entry *he;
2183};
2184
2185static int
2186perf_c2c_cacheline_browser__title(struct hist_browser *browser,
2187 char *bf, size_t size)
2188{
2189 struct c2c_cacheline_browser *cl_browser;
2190 struct hist_entry *he;
2191 uint64_t addr = 0;
2192
2193 cl_browser = container_of(browser, struct c2c_cacheline_browser, hb);
2194 he = cl_browser->he;
2195
2196 if (he->mem_info)
2197 addr = cl_address(he->mem_info->daddr.addr);
2198
2199 scnprintf(bf, size, "Cacheline 0x%lx", addr);
2200 return 0;
2201}
2202
2203static struct c2c_cacheline_browser*
2204c2c_cacheline_browser__new(struct hists *hists, struct hist_entry *he)
2205{
2206 struct c2c_cacheline_browser *browser;
2207
2208 browser = zalloc(sizeof(*browser));
2209 if (browser) {
2210 hist_browser__init(&browser->hb, hists);
2211 browser->hb.c2c_filter = true;
2212 browser->hb.title = perf_c2c_cacheline_browser__title;
2213 browser->he = he;
2214 }
2215
2216 return browser;
2217}
2218
2219static int perf_c2c__browse_cacheline(struct hist_entry *he)
2220{
2221 struct c2c_hist_entry *c2c_he;
2222 struct c2c_hists *c2c_hists;
2223 struct c2c_cacheline_browser *cl_browser;
2224 struct hist_browser *browser;
2225 int key = -1;
Jiri Olsa9a406eb2016-08-17 15:54:58 +02002226 const char help[] =
2227 " ENTER Togle callchains (if present) \n"
2228 " n Togle Node details info \n"
2229 " s Togle full lenght of symbol and source line columns \n"
2230 " q Return back to cacheline list \n";
Jiri Olsaf1c5fd42016-05-02 18:30:44 +02002231
Jiri Olsa590b6a32016-07-10 16:25:15 +02002232 /* Display compact version first. */
2233 c2c.symbol_full = false;
2234
Jiri Olsaf1c5fd42016-05-02 18:30:44 +02002235 c2c_he = container_of(he, struct c2c_hist_entry, he);
2236 c2c_hists = c2c_he->hists;
2237
2238 cl_browser = c2c_cacheline_browser__new(&c2c_hists->hists, he);
2239 if (cl_browser == NULL)
2240 return -1;
2241
2242 browser = &cl_browser->hb;
2243
2244 /* reset abort key so that it can get Ctrl-C as a key */
2245 SLang_reset_tty();
2246 SLang_init_tty(0, 0, 0);
2247
2248 c2c_browser__update_nr_entries(browser);
2249
2250 while (1) {
Jiri Olsa9a406eb2016-08-17 15:54:58 +02002251 key = hist_browser__run(browser, "? - help");
Jiri Olsaf1c5fd42016-05-02 18:30:44 +02002252
2253 switch (key) {
Jiri Olsa590b6a32016-07-10 16:25:15 +02002254 case 's':
2255 c2c.symbol_full = !c2c.symbol_full;
2256 break;
Jiri Olsa1a56a422016-07-10 16:30:27 +02002257 case 'n':
2258 c2c.node_info = (c2c.node_info + 1) % 3;
2259 setup_nodes_header();
2260 break;
Jiri Olsaf1c5fd42016-05-02 18:30:44 +02002261 case 'q':
2262 goto out;
Jiri Olsa9a406eb2016-08-17 15:54:58 +02002263 case '?':
2264 ui_browser__help_window(&browser->b, help);
2265 break;
Jiri Olsaf1c5fd42016-05-02 18:30:44 +02002266 default:
2267 break;
2268 }
2269 }
2270
2271out:
2272 free(cl_browser);
2273 return 0;
2274}
2275
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002276static int perf_c2c_browser__title(struct hist_browser *browser,
2277 char *bf, size_t size)
2278{
2279 scnprintf(bf, size,
Jiri Olsa55b95772016-05-29 10:21:45 +02002280 "Shared Data Cache Line Table "
2281 "(%lu entries, sorted on %s HITMs)",
2282 browser->nr_non_filtered_entries,
Jiri Olsad940bac2016-11-21 22:33:30 +01002283 display_str[c2c.display]);
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002284 return 0;
2285}
2286
2287static struct hist_browser*
2288perf_c2c_browser__new(struct hists *hists)
2289{
2290 struct hist_browser *browser = hist_browser__new(hists);
2291
2292 if (browser) {
2293 browser->title = perf_c2c_browser__title;
2294 browser->c2c_filter = true;
2295 }
2296
2297 return browser;
2298}
2299
2300static int perf_c2c__hists_browse(struct hists *hists)
2301{
2302 struct hist_browser *browser;
2303 int key = -1;
Jiri Olsa9a406eb2016-08-17 15:54:58 +02002304 const char help[] =
2305 " d Display cacheline details \n"
2306 " ENTER Togle callchains (if present) \n"
2307 " q Quit \n";
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002308
2309 browser = perf_c2c_browser__new(hists);
2310 if (browser == NULL)
2311 return -1;
2312
2313 /* reset abort key so that it can get Ctrl-C as a key */
2314 SLang_reset_tty();
2315 SLang_init_tty(0, 0, 0);
2316
2317 c2c_browser__update_nr_entries(browser);
2318
2319 while (1) {
Jiri Olsa9a406eb2016-08-17 15:54:58 +02002320 key = hist_browser__run(browser, "? - help");
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002321
2322 switch (key) {
2323 case 'q':
2324 goto out;
Jiri Olsaf1c5fd42016-05-02 18:30:44 +02002325 case 'd':
2326 perf_c2c__browse_cacheline(browser->he_selection);
2327 break;
Jiri Olsa9a406eb2016-08-17 15:54:58 +02002328 case '?':
2329 ui_browser__help_window(&browser->b, help);
2330 break;
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002331 default:
2332 break;
2333 }
2334 }
2335
2336out:
2337 hist_browser__delete(browser);
2338 return 0;
2339}
2340
Jiri Olsa2709b972016-08-27 11:40:23 +02002341static void perf_c2c_display(struct perf_session *session)
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002342{
Namhyung Kim1936fea2017-03-08 00:08:33 +09002343 if (use_browser == 0)
Jiri Olsa2709b972016-08-27 11:40:23 +02002344 perf_c2c__hists_fprintf(stdout, session);
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002345 else
2346 perf_c2c__hists_browse(&c2c.hists.hists);
2347}
2348#else
Jiri Olsa2709b972016-08-27 11:40:23 +02002349static void perf_c2c_display(struct perf_session *session)
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002350{
2351 use_browser = 0;
Jiri Olsa2709b972016-08-27 11:40:23 +02002352 perf_c2c__hists_fprintf(stdout, session);
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002353}
2354#endif /* HAVE_SLANG_SUPPORT */
2355
2356static void ui_quirks(void)
2357{
2358 if (!c2c.use_stdio) {
2359 dim_offset.width = 5;
2360 dim_offset.header = header_offset_tui;
2361 }
Jiri Olsa55b95772016-05-29 10:21:45 +02002362
2363 dim_percent_hitm.header = percent_hitm_header[c2c.display];
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002364}
2365
Jiri Olsadd805762016-05-11 18:23:48 +02002366#define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
2367
2368const char callchain_help[] = "Display call graph (stack chain/backtrace):\n\n"
2369 CALLCHAIN_REPORT_HELP
2370 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT;
2371
2372static int
2373parse_callchain_opt(const struct option *opt, const char *arg, int unset)
2374{
2375 struct callchain_param *callchain = opt->value;
2376
2377 callchain->enabled = !unset;
2378 /*
2379 * --no-call-graph
2380 */
2381 if (unset) {
2382 symbol_conf.use_callchain = false;
2383 callchain->mode = CHAIN_NONE;
2384 return 0;
2385 }
2386
2387 return parse_callchain_report_opt(arg);
2388}
2389
2390static int setup_callchain(struct perf_evlist *evlist)
2391{
2392 u64 sample_type = perf_evlist__combined_sample_type(evlist);
2393 enum perf_call_graph_mode mode = CALLCHAIN_NONE;
2394
2395 if ((sample_type & PERF_SAMPLE_REGS_USER) &&
2396 (sample_type & PERF_SAMPLE_STACK_USER))
2397 mode = CALLCHAIN_DWARF;
2398 else if (sample_type & PERF_SAMPLE_BRANCH_STACK)
2399 mode = CALLCHAIN_LBR;
2400 else if (sample_type & PERF_SAMPLE_CALLCHAIN)
2401 mode = CALLCHAIN_FP;
2402
2403 if (!callchain_param.enabled &&
2404 callchain_param.mode != CHAIN_NONE &&
2405 mode != CALLCHAIN_NONE) {
2406 symbol_conf.use_callchain = true;
2407 if (callchain_register_param(&callchain_param) < 0) {
2408 ui__error("Can't register callchain params.\n");
2409 return -EINVAL;
2410 }
2411 }
2412
2413 callchain_param.record_mode = mode;
2414 callchain_param.min_percent = 0;
2415 return 0;
2416}
2417
Jiri Olsa55b95772016-05-29 10:21:45 +02002418static int setup_display(const char *str)
2419{
Jiri Olsad940bac2016-11-21 22:33:30 +01002420 const char *display = str ?: "tot";
Jiri Olsa55b95772016-05-29 10:21:45 +02002421
Jiri Olsad940bac2016-11-21 22:33:30 +01002422 if (!strcmp(display, "tot"))
2423 c2c.display = DISPLAY_TOT;
2424 else if (!strcmp(display, "rmt"))
Jiri Olsa55b95772016-05-29 10:21:45 +02002425 c2c.display = DISPLAY_RMT;
2426 else if (!strcmp(display, "lcl"))
2427 c2c.display = DISPLAY_LCL;
2428 else {
2429 pr_err("failed: unknown display type: %s\n", str);
2430 return -1;
2431 }
2432
2433 return 0;
2434}
2435
Jiri Olsafc9c6302016-05-24 14:14:38 +02002436#define for_each_token(__tok, __buf, __sep, __tmp) \
2437 for (__tok = strtok_r(__buf, __sep, &__tmp); __tok; \
2438 __tok = strtok_r(NULL, __sep, &__tmp))
2439
Jiri Olsa18f278d2016-10-11 13:39:47 +02002440static int build_cl_output(char *cl_sort, bool no_source)
Jiri Olsafc9c6302016-05-24 14:14:38 +02002441{
2442 char *tok, *tmp, *buf = strdup(cl_sort);
2443 bool add_pid = false;
2444 bool add_tid = false;
2445 bool add_iaddr = false;
2446 bool add_sym = false;
2447 bool add_dso = false;
2448 bool add_src = false;
2449
2450 if (!buf)
2451 return -ENOMEM;
2452
2453 for_each_token(tok, buf, ",", tmp) {
2454 if (!strcmp(tok, "tid")) {
2455 add_tid = true;
2456 } else if (!strcmp(tok, "pid")) {
2457 add_pid = true;
2458 } else if (!strcmp(tok, "iaddr")) {
2459 add_iaddr = true;
2460 add_sym = true;
2461 add_dso = true;
Jiri Olsa18f278d2016-10-11 13:39:47 +02002462 add_src = no_source ? false : true;
Jiri Olsafc9c6302016-05-24 14:14:38 +02002463 } else if (!strcmp(tok, "dso")) {
2464 add_dso = true;
2465 } else if (strcmp(tok, "offset")) {
2466 pr_err("unrecognized sort token: %s\n", tok);
2467 return -EINVAL;
2468 }
2469 }
2470
2471 if (asprintf(&c2c.cl_output,
Jiri Olsabb342dae2016-07-06 15:40:09 +02002472 "%s%s%s%s%s%s%s%s%s%s",
2473 c2c.use_stdio ? "cl_num_empty," : "",
Jiri Olsafc9c6302016-05-24 14:14:38 +02002474 "percent_rmt_hitm,"
2475 "percent_lcl_hitm,"
2476 "percent_stores_l1hit,"
2477 "percent_stores_l1miss,"
2478 "offset,",
2479 add_pid ? "pid," : "",
2480 add_tid ? "tid," : "",
2481 add_iaddr ? "iaddr," : "",
2482 "mean_rmt,"
2483 "mean_lcl,"
2484 "mean_load,"
Jiri Olsa8763e6a2017-01-20 10:20:31 +01002485 "tot_recs,"
Jiri Olsafc9c6302016-05-24 14:14:38 +02002486 "cpucnt,",
2487 add_sym ? "symbol," : "",
2488 add_dso ? "dso," : "",
2489 add_src ? "cl_srcline," : "",
2490 "node") < 0)
2491 return -ENOMEM;
2492
2493 c2c.show_src = add_src;
2494
2495 free(buf);
2496 return 0;
2497}
2498
Jiri Olsa18f278d2016-10-11 13:39:47 +02002499static int setup_coalesce(const char *coalesce, bool no_source)
Jiri Olsafc9c6302016-05-24 14:14:38 +02002500{
2501 const char *c = coalesce ?: coalesce_default;
2502
2503 if (asprintf(&c2c.cl_sort, "offset,%s", c) < 0)
2504 return -ENOMEM;
2505
Jiri Olsa18f278d2016-10-11 13:39:47 +02002506 if (build_cl_output(c2c.cl_sort, no_source))
Jiri Olsafc9c6302016-05-24 14:14:38 +02002507 return -1;
2508
2509 if (asprintf(&c2c.cl_resort, "offset,%s",
Jiri Olsad940bac2016-11-21 22:33:30 +01002510 c2c.display == DISPLAY_TOT ?
2511 "tot_hitm" :
Jiri Olsafc9c6302016-05-24 14:14:38 +02002512 c2c.display == DISPLAY_RMT ?
2513 "rmt_hitm,lcl_hitm" :
2514 "lcl_hitm,rmt_hitm") < 0)
2515 return -ENOMEM;
2516
2517 pr_debug("coalesce sort fields: %s\n", c2c.cl_sort);
2518 pr_debug("coalesce resort fields: %s\n", c2c.cl_resort);
2519 pr_debug("coalesce output fields: %s\n", c2c.cl_output);
2520 return 0;
2521}
2522
Jiri Olsa903a6f12016-09-22 17:36:40 +02002523static int perf_c2c__report(int argc, const char **argv)
2524{
2525 struct perf_session *session;
Jiri Olsa78b27542016-09-22 17:36:44 +02002526 struct ui_progress prog;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +01002527 struct perf_data data = {
Jiri Olsa903a6f12016-09-22 17:36:40 +02002528 .mode = PERF_DATA_MODE_READ,
2529 };
Jiri Olsadd805762016-05-11 18:23:48 +02002530 char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT;
Jiri Olsa55b95772016-05-29 10:21:45 +02002531 const char *display = NULL;
Jiri Olsafc9c6302016-05-24 14:14:38 +02002532 const char *coalesce = NULL;
Jiri Olsa18f278d2016-10-11 13:39:47 +02002533 bool no_source = false;
Jiri Olsa3a5bfab2016-11-21 22:33:31 +01002534 const struct option options[] = {
Jiri Olsa903a6f12016-09-22 17:36:40 +02002535 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
2536 "file", "vmlinux pathname"),
Jiri Olsa903a6f12016-09-22 17:36:40 +02002537 OPT_STRING('i', "input", &input_name, "file",
2538 "the input file to process"),
Jiri Olsa1e181b92016-06-03 15:40:28 +02002539 OPT_INCR('N', "node-info", &c2c.node_info,
2540 "show extra node info in report (repeat for more info)"),
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002541#ifdef HAVE_SLANG_SUPPORT
2542 OPT_BOOLEAN(0, "stdio", &c2c.use_stdio, "Use the stdio interface"),
2543#endif
Jiri Olsa74c63a22016-05-02 20:01:59 +02002544 OPT_BOOLEAN(0, "stats", &c2c.stats_only,
Namhyung Kimf75d2892017-03-08 00:08:32 +09002545 "Display only statistic tables (implies --stdio)"),
Jiri Olsa590b6a32016-07-10 16:25:15 +02002546 OPT_BOOLEAN(0, "full-symbols", &c2c.symbol_full,
2547 "Display full length of symbols"),
Jiri Olsa18f278d2016-10-11 13:39:47 +02002548 OPT_BOOLEAN(0, "no-source", &no_source,
2549 "Do not display Source Line column"),
Jiri Olsaaf09b2d2016-10-11 13:52:05 +02002550 OPT_BOOLEAN(0, "show-all", &c2c.show_all,
2551 "Show all captured HITM lines."),
Jiri Olsadd805762016-05-11 18:23:48 +02002552 OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param,
2553 "print_type,threshold[,print_limit],order,sort_key[,branch],value",
2554 callchain_help, &parse_callchain_opt,
2555 callchain_default_opt),
Jiri Olsad940bac2016-11-21 22:33:30 +01002556 OPT_STRING('d', "display", &display, "Switch HITM output type", "lcl,rmt"),
Jiri Olsafc9c6302016-05-24 14:14:38 +02002557 OPT_STRING('c', "coalesce", &coalesce, "coalesce fields",
2558 "coalesce fields: pid,tid,iaddr,dso"),
Jiri Olsab7ac4f92016-11-21 22:33:28 +01002559 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
Jiri Olsa3a5bfab2016-11-21 22:33:31 +01002560 OPT_PARENT(c2c_options),
Jiri Olsa903a6f12016-09-22 17:36:40 +02002561 OPT_END()
2562 };
2563 int err = 0;
2564
Jiri Olsa3a5bfab2016-11-21 22:33:31 +01002565 argc = parse_options(argc, argv, options, report_c2c_usage,
Jiri Olsa903a6f12016-09-22 17:36:40 +02002566 PARSE_OPT_STOP_AT_NON_OPTION);
Jiri Olsa78b27542016-09-22 17:36:44 +02002567 if (argc)
Jiri Olsa3a5bfab2016-11-21 22:33:31 +01002568 usage_with_options(report_c2c_usage, options);
Jiri Olsa903a6f12016-09-22 17:36:40 +02002569
Jiri Olsa74c63a22016-05-02 20:01:59 +02002570 if (c2c.stats_only)
2571 c2c.use_stdio = true;
2572
Jiri Olsa78b27542016-09-22 17:36:44 +02002573 if (!input_name || !strlen(input_name))
2574 input_name = "perf.data";
2575
Jiri Olsaeae8ad82017-01-23 22:25:41 +01002576 data.file.path = input_name;
2577 data.force = symbol_conf.force;
Jiri Olsa903a6f12016-09-22 17:36:40 +02002578
Jiri Olsa55b95772016-05-29 10:21:45 +02002579 err = setup_display(display);
2580 if (err)
2581 goto out;
2582
Jiri Olsa18f278d2016-10-11 13:39:47 +02002583 err = setup_coalesce(coalesce, no_source);
Jiri Olsafc9c6302016-05-24 14:14:38 +02002584 if (err) {
2585 pr_debug("Failed to initialize hists\n");
2586 goto out;
2587 }
2588
Jiri Olsa1d62fcd2016-05-24 10:12:31 +02002589 err = c2c_hists__init(&c2c.hists, "dcacheline", 2);
Jiri Olsac75540e2016-09-22 17:36:41 +02002590 if (err) {
2591 pr_debug("Failed to initialize hists\n");
2592 goto out;
2593 }
2594
Jiri Olsa8ceb41d2017-01-23 22:07:59 +01002595 session = perf_session__new(&data, 0, &c2c.tool);
Jiri Olsa903a6f12016-09-22 17:36:40 +02002596 if (session == NULL) {
2597 pr_debug("No memory for session\n");
2598 goto out;
2599 }
Jiri Olsae8c5fe12016-11-21 22:33:27 +01002600
Jiri Olsa1e181b92016-06-03 15:40:28 +02002601 err = setup_nodes(session);
2602 if (err) {
2603 pr_err("Failed setup nodes\n");
2604 goto out;
2605 }
Jiri Olsa903a6f12016-09-22 17:36:40 +02002606
Jiri Olsadd805762016-05-11 18:23:48 +02002607 err = setup_callchain(session->evlist);
2608 if (err)
2609 goto out_session;
2610
Jiri Olsa903a6f12016-09-22 17:36:40 +02002611 if (symbol__init(&session->header.env) < 0)
2612 goto out_session;
2613
2614 /* No pipe support at the moment. */
Jiri Olsa8ceb41d2017-01-23 22:07:59 +01002615 if (perf_data__is_pipe(session->data)) {
Jiri Olsa903a6f12016-09-22 17:36:40 +02002616 pr_debug("No pipe support at the moment.\n");
2617 goto out_session;
2618 }
2619
Jiri Olsae8c5fe12016-11-21 22:33:27 +01002620 if (c2c.use_stdio)
2621 use_browser = 0;
2622 else
2623 use_browser = 1;
2624
2625 setup_browser(false);
2626
Jiri Olsa78b27542016-09-22 17:36:44 +02002627 err = perf_session__process_events(session);
2628 if (err) {
2629 pr_err("failed to process sample\n");
2630 goto out_session;
2631 }
2632
Jiri Olsa22dd59d2016-05-10 14:08:29 +02002633 c2c_hists__reinit(&c2c.hists,
Jiri Olsabb342dae2016-07-06 15:40:09 +02002634 "cl_idx,"
Jiri Olsa22dd59d2016-05-10 14:08:29 +02002635 "dcacheline,"
2636 "tot_recs,"
2637 "percent_hitm,"
2638 "tot_hitm,lcl_hitm,rmt_hitm,"
2639 "stores,stores_l1hit,stores_l1miss,"
2640 "dram_lcl,dram_rmt,"
2641 "ld_llcmiss,"
2642 "tot_loads,"
2643 "ld_fbhit,ld_l1hit,ld_l2hit,"
2644 "ld_lclhit,ld_rmthit",
Jiri Olsad940bac2016-11-21 22:33:30 +01002645 c2c.display == DISPLAY_TOT ? "tot_hitm" :
Jiri Olsa55b95772016-05-29 10:21:45 +02002646 c2c.display == DISPLAY_LCL ? "lcl_hitm" : "rmt_hitm"
Jiri Olsa22dd59d2016-05-10 14:08:29 +02002647 );
2648
Jiri Olsa78b27542016-09-22 17:36:44 +02002649 ui_progress__init(&prog, c2c.hists.hists.nr_entries, "Sorting...");
2650
2651 hists__collapse_resort(&c2c.hists.hists, NULL);
Jiri Olsa7ef2efa2016-07-01 11:12:11 +02002652 hists__output_resort_cb(&c2c.hists.hists, &prog, resort_hitm_cb);
2653 hists__iterate_cb(&c2c.hists.hists, resort_cl_cb);
Jiri Olsa78b27542016-09-22 17:36:44 +02002654
2655 ui_progress__finish();
2656
Jiri Olsa5a1a99c2016-01-06 16:59:02 +01002657 ui_quirks();
2658
Jiri Olsa2709b972016-08-27 11:40:23 +02002659 perf_c2c_display(session);
Jiri Olsa2d388bd2016-05-03 14:32:56 +02002660
Jiri Olsa903a6f12016-09-22 17:36:40 +02002661out_session:
2662 perf_session__delete(session);
2663out:
2664 return err;
2665}
2666
Arnaldo Carvalho de Melo7e6a7992016-12-12 10:52:10 -03002667static int parse_record_events(const struct option *opt,
Jiri Olsa39bcd4a2016-09-22 17:36:39 +02002668 const char *str, int unset __maybe_unused)
2669{
2670 bool *event_set = (bool *) opt->value;
2671
2672 *event_set = true;
2673 return perf_mem_events__parse(str);
2674}
2675
2676
2677static const char * const __usage_record[] = {
2678 "perf c2c record [<options>] [<command>]",
2679 "perf c2c record [<options>] -- <command> [<options>]",
2680 NULL
2681};
2682
2683static const char * const *record_mem_usage = __usage_record;
2684
2685static int perf_c2c__record(int argc, const char **argv)
2686{
2687 int rec_argc, i = 0, j;
2688 const char **rec_argv;
2689 int ret;
2690 bool all_user = false, all_kernel = false;
2691 bool event_set = false;
2692 struct option options[] = {
2693 OPT_CALLBACK('e', "event", &event_set, "event",
2694 "event selector. Use 'perf mem record -e list' to list available events",
2695 parse_record_events),
Jiri Olsa39bcd4a2016-09-22 17:36:39 +02002696 OPT_BOOLEAN('u', "all-user", &all_user, "collect only user level data"),
2697 OPT_BOOLEAN('k', "all-kernel", &all_kernel, "collect only kernel level data"),
2698 OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat, "setup mem-loads latency"),
Jiri Olsa3a5bfab2016-11-21 22:33:31 +01002699 OPT_PARENT(c2c_options),
Jiri Olsa39bcd4a2016-09-22 17:36:39 +02002700 OPT_END()
2701 };
2702
2703 if (perf_mem_events__init()) {
2704 pr_err("failed: memory events not supported\n");
2705 return -1;
2706 }
2707
2708 argc = parse_options(argc, argv, options, record_mem_usage,
2709 PARSE_OPT_KEEP_UNKNOWN);
2710
2711 rec_argc = argc + 10; /* max number of arguments */
2712 rec_argv = calloc(rec_argc + 1, sizeof(char *));
2713 if (!rec_argv)
2714 return -1;
2715
2716 rec_argv[i++] = "record";
2717
2718 if (!event_set) {
2719 perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true;
2720 perf_mem_events[PERF_MEM_EVENTS__STORE].record = true;
2721 }
2722
2723 if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record)
2724 rec_argv[i++] = "-W";
2725
2726 rec_argv[i++] = "-d";
2727 rec_argv[i++] = "--sample-cpu";
2728
2729 for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
2730 if (!perf_mem_events[j].record)
2731 continue;
2732
2733 if (!perf_mem_events[j].supported) {
2734 pr_err("failed: event '%s' not supported\n",
2735 perf_mem_events[j].name);
Martin Kepplingerc896f852017-09-13 21:14:19 +02002736 free(rec_argv);
Jiri Olsa39bcd4a2016-09-22 17:36:39 +02002737 return -1;
2738 }
2739
2740 rec_argv[i++] = "-e";
2741 rec_argv[i++] = perf_mem_events__name(j);
2742 };
2743
2744 if (all_user)
2745 rec_argv[i++] = "--all-user";
2746
2747 if (all_kernel)
2748 rec_argv[i++] = "--all-kernel";
2749
2750 for (j = 0; j < argc; j++, i++)
2751 rec_argv[i] = argv[j];
2752
2753 if (verbose > 0) {
2754 pr_debug("calling: ");
2755
2756 j = 0;
2757
2758 while (rec_argv[j]) {
2759 pr_debug("%s ", rec_argv[j]);
2760 j++;
2761 }
2762 pr_debug("\n");
2763 }
2764
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -03002765 ret = cmd_record(i, rec_argv);
Jiri Olsa39bcd4a2016-09-22 17:36:39 +02002766 free(rec_argv);
2767 return ret;
2768}
2769
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -03002770int cmd_c2c(int argc, const char **argv)
Jiri Olsa7aef3bf2016-09-22 17:36:38 +02002771{
Jiri Olsa7aef3bf2016-09-22 17:36:38 +02002772 argc = parse_options(argc, argv, c2c_options, c2c_usage,
2773 PARSE_OPT_STOP_AT_NON_OPTION);
Jiri Olsa39bcd4a2016-09-22 17:36:39 +02002774
2775 if (!argc)
2776 usage_with_options(c2c_usage, c2c_options);
2777
2778 if (!strncmp(argv[0], "rec", 3)) {
2779 return perf_c2c__record(argc, argv);
Jiri Olsa903a6f12016-09-22 17:36:40 +02002780 } else if (!strncmp(argv[0], "rep", 3)) {
2781 return perf_c2c__report(argc, argv);
Jiri Olsa39bcd4a2016-09-22 17:36:39 +02002782 } else {
2783 usage_with_options(c2c_usage, c2c_options);
2784 }
2785
Jiri Olsa7aef3bf2016-09-22 17:36:38 +02002786 return 0;
2787}