1 #include <linux/compiler.h>
2 #include <linux/kernel.h>
3 #include <linux/stringify.h>
8 #include <subcmd/parse-options.h>
9 #include "mem-events.h"
20 struct perf_hpp_list list;
21 struct c2c_stats stats;
24 struct compute_stats {
25 struct stats lcl_hitm;
26 struct stats rmt_hitm;
30 struct c2c_hist_entry {
31 struct c2c_hists *hists;
32 struct c2c_stats stats;
33 unsigned long *cpuset;
34 struct c2c_stats *node_stats;
36 struct compute_stats cstats;
40 * because of its callchain dynamic entry
46 struct perf_tool tool;
47 struct c2c_hists hists;
49 unsigned long **nodes;
58 static struct perf_c2c c2c;
60 static void *c2c_he_zalloc(size_t size)
62 struct c2c_hist_entry *c2c_he;
64 c2c_he = zalloc(size + sizeof(*c2c_he));
68 c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt);
72 c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
73 if (!c2c_he->node_stats)
76 init_stats(&c2c_he->cstats.lcl_hitm);
77 init_stats(&c2c_he->cstats.rmt_hitm);
78 init_stats(&c2c_he->cstats.load);
83 static void c2c_he_free(void *he)
85 struct c2c_hist_entry *c2c_he;
87 c2c_he = container_of(he, struct c2c_hist_entry, he);
89 hists__delete_entries(&c2c_he->hists->hists);
94 free(c2c_he->node_stats);
98 static struct hist_entry_ops c2c_entry_ops = {
103 static int c2c_hists__init(struct c2c_hists *hists,
105 int nr_header_lines);
107 static struct c2c_hists*
108 he__get_c2c_hists(struct hist_entry *he,
112 struct c2c_hist_entry *c2c_he;
113 struct c2c_hists *hists;
116 c2c_he = container_of(he, struct c2c_hist_entry, he);
118 return c2c_he->hists;
120 hists = c2c_he->hists = zalloc(sizeof(*hists));
124 ret = c2c_hists__init(hists, sort, nr_header_lines);
133 static void c2c_he__set_cpu(struct c2c_hist_entry *c2c_he,
134 struct perf_sample *sample)
136 if (WARN_ONCE(sample->cpu == (unsigned int) -1,
137 "WARNING: no sample cpu value"))
140 set_bit(sample->cpu, c2c_he->cpuset);
143 static void compute_stats(struct c2c_hist_entry *c2c_he,
144 struct c2c_stats *stats,
147 struct compute_stats *cstats = &c2c_he->cstats;
150 update_stats(&cstats->rmt_hitm, weight);
151 else if (stats->lcl_hitm)
152 update_stats(&cstats->lcl_hitm, weight);
153 else if (stats->load)
154 update_stats(&cstats->load, weight);
157 static int process_sample_event(struct perf_tool *tool __maybe_unused,
158 union perf_event *event,
159 struct perf_sample *sample,
160 struct perf_evsel *evsel __maybe_unused,
161 struct machine *machine)
163 struct c2c_hists *c2c_hists = &c2c.hists;
164 struct c2c_hist_entry *c2c_he;
165 struct c2c_stats stats = { .nr_entries = 0, };
166 struct hist_entry *he;
167 struct addr_location al;
168 struct mem_info *mi, *mi_dup;
171 if (machine__resolve(machine, &al, sample) < 0) {
172 pr_debug("problem processing %d event, skipping it.\n",
177 mi = sample__resolve_mem(sample, &al);
181 mi_dup = memdup(mi, sizeof(*mi));
185 c2c_decode_stats(&stats, mi);
187 he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops,
193 c2c_he = container_of(he, struct c2c_hist_entry, he);
194 c2c_add_stats(&c2c_he->stats, &stats);
195 c2c_add_stats(&c2c_hists->stats, &stats);
197 c2c_he__set_cpu(c2c_he, sample);
199 hists__inc_nr_samples(&c2c_hists->hists, he->filtered);
200 ret = hist_entry__append_callchain(he, sample);
204 * There's already been warning about missing
205 * sample's cpu value. Let's account all to
206 * node 0 in this case, without any further
209 * Doing node stats only for single callchain data.
211 int cpu = sample->cpu == (unsigned int) -1 ? 0 : sample->cpu;
212 int node = c2c.cpu2node[cpu];
216 mi_dup = memdup(mi, sizeof(*mi));
220 c2c_hists = he__get_c2c_hists(he, "offset", 2);
224 he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops,
230 c2c_he = container_of(he, struct c2c_hist_entry, he);
231 c2c_add_stats(&c2c_he->stats, &stats);
232 c2c_add_stats(&c2c_hists->stats, &stats);
233 c2c_add_stats(&c2c_he->node_stats[node], &stats);
235 compute_stats(c2c_he, &stats, sample->weight);
237 c2c_he__set_cpu(c2c_he, sample);
239 hists__inc_nr_samples(&c2c_hists->hists, he->filtered);
240 ret = hist_entry__append_callchain(he, sample);
244 addr_location__put(&al);
255 static struct perf_c2c c2c = {
257 .sample = process_sample_event,
258 .mmap = perf_event__process_mmap,
259 .mmap2 = perf_event__process_mmap2,
260 .comm = perf_event__process_comm,
261 .exit = perf_event__process_exit,
262 .fork = perf_event__process_fork,
263 .lost = perf_event__process_lost,
264 .ordered_events = true,
265 .ordering_requires_timestamps = true,
269 static const char * const c2c_usage[] = {
270 "perf c2c {record|report}",
274 static const char * const __usage_report[] = {
279 static const char * const *report_c2c_usage = __usage_report;
281 #define C2C_HEADER_MAX 2
287 } line[C2C_HEADER_MAX];
290 struct c2c_dimension {
291 struct c2c_header header;
294 struct sort_entry *se;
296 int64_t (*cmp)(struct perf_hpp_fmt *fmt,
297 struct hist_entry *, struct hist_entry *);
298 int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
299 struct hist_entry *he);
300 int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
301 struct hist_entry *he);
305 struct perf_hpp_fmt fmt;
306 struct c2c_dimension *dim;
309 static int c2c_width(struct perf_hpp_fmt *fmt,
310 struct perf_hpp *hpp __maybe_unused,
311 struct hists *hists __maybe_unused)
313 struct c2c_fmt *c2c_fmt;
314 struct c2c_dimension *dim;
316 c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
319 return dim->se ? hists__col_len(hists, dim->se->se_width_idx) :
323 static int c2c_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
324 struct hists *hists, int line, int *span)
326 struct perf_hpp_list *hpp_list = hists->hpp_list;
327 struct c2c_fmt *c2c_fmt;
328 struct c2c_dimension *dim;
329 const char *text = NULL;
330 int width = c2c_width(fmt, hpp, hists);
332 c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
336 text = dim->header.line[line].text;
337 /* Use the last line from sort_entry if not defined. */
338 if (!text && (line == hpp_list->nr_header_lines - 1))
339 text = dim->se->se_header;
341 text = dim->header.line[line].text;
347 *span = dim->header.line[line].span;
354 return scnprintf(hpp->buf, hpp->size, "%*s", width, text);
357 #define HEX_STR(__s, __v) \
359 scnprintf(__s, sizeof(__s), "0x%" PRIx64, __v); \
364 dcacheline_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
365 struct hist_entry *left, struct hist_entry *right)
367 return sort__dcacheline_cmp(left, right);
370 static int dcacheline_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
371 struct hist_entry *he)
374 int width = c2c_width(fmt, hpp, he->hists);
378 addr = cl_address(he->mem_info->daddr.addr);
380 return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr));
383 static int offset_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
384 struct hist_entry *he)
387 int width = c2c_width(fmt, hpp, he->hists);
391 addr = cl_offset(he->mem_info->daddr.al_addr);
393 return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr));
397 offset_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
398 struct hist_entry *left, struct hist_entry *right)
400 uint64_t l = 0, r = 0;
403 l = cl_offset(left->mem_info->daddr.addr);
405 r = cl_offset(right->mem_info->daddr.addr);
407 return (int64_t)(r - l);
411 iaddr_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
412 struct hist_entry *he)
415 int width = c2c_width(fmt, hpp, he->hists);
419 addr = he->mem_info->iaddr.addr;
421 return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr));
425 iaddr_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
426 struct hist_entry *left, struct hist_entry *right)
428 return sort__iaddr_cmp(left, right);
432 tot_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
433 struct hist_entry *he)
435 struct c2c_hist_entry *c2c_he;
436 int width = c2c_width(fmt, hpp, he->hists);
437 unsigned int tot_hitm;
439 c2c_he = container_of(he, struct c2c_hist_entry, he);
440 tot_hitm = c2c_he->stats.lcl_hitm + c2c_he->stats.rmt_hitm;
442 return scnprintf(hpp->buf, hpp->size, "%*u", width, tot_hitm);
446 tot_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
447 struct hist_entry *left, struct hist_entry *right)
449 struct c2c_hist_entry *c2c_left;
450 struct c2c_hist_entry *c2c_right;
451 unsigned int tot_hitm_left;
452 unsigned int tot_hitm_right;
454 c2c_left = container_of(left, struct c2c_hist_entry, he);
455 c2c_right = container_of(right, struct c2c_hist_entry, he);
457 tot_hitm_left = c2c_left->stats.lcl_hitm + c2c_left->stats.rmt_hitm;
458 tot_hitm_right = c2c_right->stats.lcl_hitm + c2c_right->stats.rmt_hitm;
460 return tot_hitm_left - tot_hitm_right;
463 #define STAT_FN_ENTRY(__f) \
465 __f ## _entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, \
466 struct hist_entry *he) \
468 struct c2c_hist_entry *c2c_he; \
469 int width = c2c_width(fmt, hpp, he->hists); \
471 c2c_he = container_of(he, struct c2c_hist_entry, he); \
472 return scnprintf(hpp->buf, hpp->size, "%*u", width, \
473 c2c_he->stats.__f); \
476 #define STAT_FN_CMP(__f) \
478 __f ## _cmp(struct perf_hpp_fmt *fmt __maybe_unused, \
479 struct hist_entry *left, struct hist_entry *right) \
481 struct c2c_hist_entry *c2c_left, *c2c_right; \
483 c2c_left = container_of(left, struct c2c_hist_entry, he); \
484 c2c_right = container_of(right, struct c2c_hist_entry, he); \
485 return c2c_left->stats.__f - c2c_right->stats.__f; \
488 #define STAT_FN(__f) \
503 static uint64_t llc_miss(struct c2c_stats *stats)
507 llcmiss = stats->lcl_dram +
516 ld_llcmiss_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
517 struct hist_entry *he)
519 struct c2c_hist_entry *c2c_he;
520 int width = c2c_width(fmt, hpp, he->hists);
522 c2c_he = container_of(he, struct c2c_hist_entry, he);
524 return scnprintf(hpp->buf, hpp->size, "%*lu", width,
525 llc_miss(&c2c_he->stats));
529 ld_llcmiss_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
530 struct hist_entry *left, struct hist_entry *right)
532 struct c2c_hist_entry *c2c_left;
533 struct c2c_hist_entry *c2c_right;
535 c2c_left = container_of(left, struct c2c_hist_entry, he);
536 c2c_right = container_of(right, struct c2c_hist_entry, he);
538 return llc_miss(&c2c_left->stats) - llc_miss(&c2c_right->stats);
541 static uint64_t total_records(struct c2c_stats *stats)
543 uint64_t lclmiss, ldcnt, total;
545 lclmiss = stats->lcl_dram +
565 tot_recs_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
566 struct hist_entry *he)
568 struct c2c_hist_entry *c2c_he;
569 int width = c2c_width(fmt, hpp, he->hists);
572 c2c_he = container_of(he, struct c2c_hist_entry, he);
573 tot_recs = total_records(&c2c_he->stats);
575 return scnprintf(hpp->buf, hpp->size, "%*" PRIu64, width, tot_recs);
579 tot_recs_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
580 struct hist_entry *left, struct hist_entry *right)
582 struct c2c_hist_entry *c2c_left;
583 struct c2c_hist_entry *c2c_right;
584 uint64_t tot_recs_left;
585 uint64_t tot_recs_right;
587 c2c_left = container_of(left, struct c2c_hist_entry, he);
588 c2c_right = container_of(right, struct c2c_hist_entry, he);
590 tot_recs_left = total_records(&c2c_left->stats);
591 tot_recs_right = total_records(&c2c_right->stats);
593 return tot_recs_left - tot_recs_right;
596 static uint64_t total_loads(struct c2c_stats *stats)
598 uint64_t lclmiss, ldcnt;
600 lclmiss = stats->lcl_dram +
616 tot_loads_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
617 struct hist_entry *he)
619 struct c2c_hist_entry *c2c_he;
620 int width = c2c_width(fmt, hpp, he->hists);
623 c2c_he = container_of(he, struct c2c_hist_entry, he);
624 tot_recs = total_loads(&c2c_he->stats);
626 return scnprintf(hpp->buf, hpp->size, "%*" PRIu64, width, tot_recs);
630 tot_loads_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
631 struct hist_entry *left, struct hist_entry *right)
633 struct c2c_hist_entry *c2c_left;
634 struct c2c_hist_entry *c2c_right;
635 uint64_t tot_recs_left;
636 uint64_t tot_recs_right;
638 c2c_left = container_of(left, struct c2c_hist_entry, he);
639 c2c_right = container_of(right, struct c2c_hist_entry, he);
641 tot_recs_left = total_loads(&c2c_left->stats);
642 tot_recs_right = total_loads(&c2c_right->stats);
644 return tot_recs_left - tot_recs_right;
647 typedef double (get_percent_cb)(struct c2c_hist_entry *);
650 percent_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
651 struct hist_entry *he, get_percent_cb get_percent)
653 struct c2c_hist_entry *c2c_he;
654 int width = c2c_width(fmt, hpp, he->hists);
657 c2c_he = container_of(he, struct c2c_hist_entry, he);
658 per = get_percent(c2c_he);
660 return hpp_color_scnprintf(hpp, "%*.2f%%", width - 1, per);
663 static double percent_hitm(struct c2c_hist_entry *c2c_he)
665 struct c2c_hists *hists;
666 struct c2c_stats *stats;
667 struct c2c_stats *total;
671 hists = container_of(c2c_he->he.hists, struct c2c_hists, hists);
672 stats = &c2c_he->stats;
673 total = &hists->stats;
675 st = stats->rmt_hitm;
676 tot = total->rmt_hitm;
678 p = tot ? (double) st / tot : 0;
683 #define PERC_STR(__s, __v) \
685 scnprintf(__s, sizeof(__s), "%.2F%%", __v); \
690 percent_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
691 struct hist_entry *he)
693 struct c2c_hist_entry *c2c_he;
694 int width = c2c_width(fmt, hpp, he->hists);
698 c2c_he = container_of(he, struct c2c_hist_entry, he);
699 per = percent_hitm(c2c_he);
700 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
704 percent_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
705 struct hist_entry *he)
707 return percent_color(fmt, hpp, he, percent_hitm);
711 percent_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
712 struct hist_entry *left, struct hist_entry *right)
714 struct c2c_hist_entry *c2c_left;
715 struct c2c_hist_entry *c2c_right;
719 c2c_left = container_of(left, struct c2c_hist_entry, he);
720 c2c_right = container_of(right, struct c2c_hist_entry, he);
722 per_left = percent_hitm(c2c_left);
723 per_right = percent_hitm(c2c_right);
725 return per_left - per_right;
728 static struct c2c_stats *he_stats(struct hist_entry *he)
730 struct c2c_hist_entry *c2c_he;
732 c2c_he = container_of(he, struct c2c_hist_entry, he);
733 return &c2c_he->stats;
736 static struct c2c_stats *total_stats(struct hist_entry *he)
738 struct c2c_hists *hists;
740 hists = container_of(he->hists, struct c2c_hists, hists);
741 return &hists->stats;
744 static double percent(int st, int tot)
746 return tot ? 100. * (double) st / (double) tot : 0;
749 #define PERCENT(__h, __f) percent(he_stats(__h)->__f, total_stats(__h)->__f)
751 #define PERCENT_FN(__f) \
752 static double percent_ ## __f(struct c2c_hist_entry *c2c_he) \
754 struct c2c_hists *hists; \
756 hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); \
757 return percent(c2c_he->stats.__f, hists->stats.__f); \
763 PERCENT_FN(st_l1miss)
766 percent_rmt_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
767 struct hist_entry *he)
769 int width = c2c_width(fmt, hpp, he->hists);
770 double per = PERCENT(he, rmt_hitm);
773 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
777 percent_rmt_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
778 struct hist_entry *he)
780 return percent_color(fmt, hpp, he, percent_rmt_hitm);
784 percent_rmt_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
785 struct hist_entry *left, struct hist_entry *right)
790 per_left = PERCENT(left, lcl_hitm);
791 per_right = PERCENT(right, lcl_hitm);
793 return per_left - per_right;
797 percent_lcl_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
798 struct hist_entry *he)
800 int width = c2c_width(fmt, hpp, he->hists);
801 double per = PERCENT(he, lcl_hitm);
804 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
808 percent_lcl_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
809 struct hist_entry *he)
811 return percent_color(fmt, hpp, he, percent_lcl_hitm);
815 percent_lcl_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
816 struct hist_entry *left, struct hist_entry *right)
821 per_left = PERCENT(left, lcl_hitm);
822 per_right = PERCENT(right, lcl_hitm);
824 return per_left - per_right;
828 percent_stores_l1hit_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
829 struct hist_entry *he)
831 int width = c2c_width(fmt, hpp, he->hists);
832 double per = PERCENT(he, st_l1hit);
835 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
839 percent_stores_l1hit_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
840 struct hist_entry *he)
842 return percent_color(fmt, hpp, he, percent_st_l1hit);
846 percent_stores_l1hit_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
847 struct hist_entry *left, struct hist_entry *right)
852 per_left = PERCENT(left, st_l1hit);
853 per_right = PERCENT(right, st_l1hit);
855 return per_left - per_right;
859 percent_stores_l1miss_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
860 struct hist_entry *he)
862 int width = c2c_width(fmt, hpp, he->hists);
863 double per = PERCENT(he, st_l1miss);
866 return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
870 percent_stores_l1miss_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
871 struct hist_entry *he)
873 return percent_color(fmt, hpp, he, percent_st_l1miss);
877 percent_stores_l1miss_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
878 struct hist_entry *left, struct hist_entry *right)
883 per_left = PERCENT(left, st_l1miss);
884 per_right = PERCENT(right, st_l1miss);
886 return per_left - per_right;
893 pid_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
894 struct hist_entry *he)
896 int width = c2c_width(fmt, hpp, he->hists);
898 return scnprintf(hpp->buf, hpp->size, "%*d", width, he->thread->pid_);
902 pid_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
903 struct hist_entry *left, struct hist_entry *right)
905 return left->thread->pid_ - right->thread->pid_;
909 empty_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
910 struct hist_entry *left __maybe_unused,
911 struct hist_entry *right __maybe_unused)
917 node_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
918 struct hist_entry *he)
920 struct c2c_hist_entry *c2c_he;
925 c2c_he = container_of(he, struct c2c_hist_entry, he);
927 for (node = 0; node < c2c.nodes_cnt; node++) {
928 DECLARE_BITMAP(set, c2c.cpus_cnt);
930 bitmap_zero(set, c2c.cpus_cnt);
931 bitmap_and(set, c2c_he->cpuset, c2c.nodes[node], c2c.cpus_cnt);
933 if (!bitmap_weight(set, c2c.cpus_cnt)) {
934 if (c2c.node_info == 1) {
935 ret = scnprintf(hpp->buf, hpp->size, "%21s", " ");
936 advance_hpp(hpp, ret);
942 ret = scnprintf(hpp->buf, hpp->size, " ");
943 advance_hpp(hpp, ret);
946 switch (c2c.node_info) {
948 ret = scnprintf(hpp->buf, hpp->size, "%2d", node);
949 advance_hpp(hpp, ret);
953 int num = bitmap_weight(c2c_he->cpuset, c2c.cpus_cnt);
954 struct c2c_stats *stats = &c2c_he->node_stats[node];
956 ret = scnprintf(hpp->buf, hpp->size, "%2d{%2d ", node, num);
957 advance_hpp(hpp, ret);
960 if (c2c_he->stats.rmt_hitm > 0) {
961 ret = scnprintf(hpp->buf, hpp->size, "%5.1f%% ",
962 percent(stats->rmt_hitm, c2c_he->stats.rmt_hitm));
964 ret = scnprintf(hpp->buf, hpp->size, "%6s ", "n/a");
967 advance_hpp(hpp, ret);
969 if (c2c_he->stats.store > 0) {
970 ret = scnprintf(hpp->buf, hpp->size, "%5.1f%%}",
971 percent(stats->store, c2c_he->stats.store));
973 ret = scnprintf(hpp->buf, hpp->size, "%6s}", "n/a");
976 advance_hpp(hpp, ret);
980 ret = scnprintf(hpp->buf, hpp->size, "%2d{", node);
981 advance_hpp(hpp, ret);
983 ret = bitmap_scnprintf(set, c2c.cpus_cnt, hpp->buf, hpp->size);
984 advance_hpp(hpp, ret);
986 ret = scnprintf(hpp->buf, hpp->size, "}");
987 advance_hpp(hpp, ret);
1000 mean_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
1001 struct hist_entry *he, double mean)
1003 int width = c2c_width(fmt, hpp, he->hists);
1006 scnprintf(buf, 10, "%6.0f", mean);
1007 return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
1010 #define MEAN_ENTRY(__func, __val) \
1012 __func(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, struct hist_entry *he) \
1014 struct c2c_hist_entry *c2c_he; \
1015 c2c_he = container_of(he, struct c2c_hist_entry, he); \
1016 return mean_entry(fmt, hpp, he, avg_stats(&c2c_he->cstats.__val)); \
1019 MEAN_ENTRY(mean_rmt_entry, rmt_hitm);
1020 MEAN_ENTRY(mean_lcl_entry, lcl_hitm);
1021 MEAN_ENTRY(mean_load_entry, load);
1024 cpucnt_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
1025 struct hist_entry *he)
1027 struct c2c_hist_entry *c2c_he;
1028 int width = c2c_width(fmt, hpp, he->hists);
1031 c2c_he = container_of(he, struct c2c_hist_entry, he);
1033 scnprintf(buf, 10, "%d", bitmap_weight(c2c_he->cpuset, c2c.cpus_cnt));
1034 return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
1037 #define HEADER_LOW(__h) \
1044 #define HEADER_BOTH(__h0, __h1) \
1054 #define HEADER_SPAN(__h0, __h1, __s) \
1065 #define HEADER_SPAN_LOW(__h) \
1072 static struct c2c_dimension dim_dcacheline = {
1073 .header = HEADER_LOW("Cacheline"),
1074 .name = "dcacheline",
1075 .cmp = dcacheline_cmp,
1076 .entry = dcacheline_entry,
1080 static struct c2c_dimension dim_offset = {
1081 .header = HEADER_BOTH("Data address", "Offset"),
1084 .entry = offset_entry,
1088 static struct c2c_dimension dim_iaddr = {
1089 .header = HEADER_LOW("Code address"),
1092 .entry = iaddr_entry,
1096 static struct c2c_dimension dim_tot_hitm = {
1097 .header = HEADER_SPAN("----- LLC Load Hitm -----", "Total", 2),
1099 .cmp = tot_hitm_cmp,
1100 .entry = tot_hitm_entry,
1104 static struct c2c_dimension dim_lcl_hitm = {
1105 .header = HEADER_SPAN_LOW("Lcl"),
1107 .cmp = lcl_hitm_cmp,
1108 .entry = lcl_hitm_entry,
1112 static struct c2c_dimension dim_rmt_hitm = {
1113 .header = HEADER_SPAN_LOW("Rmt"),
1115 .cmp = rmt_hitm_cmp,
1116 .entry = rmt_hitm_entry,
1120 static struct c2c_dimension dim_cl_rmt_hitm = {
1121 .header = HEADER_SPAN("----- HITM -----", "Rmt", 1),
1122 .name = "cl_rmt_hitm",
1123 .cmp = rmt_hitm_cmp,
1124 .entry = rmt_hitm_entry,
1128 static struct c2c_dimension dim_cl_lcl_hitm = {
1129 .header = HEADER_SPAN_LOW("Lcl"),
1130 .name = "cl_lcl_hitm",
1131 .cmp = lcl_hitm_cmp,
1132 .entry = lcl_hitm_entry,
1136 static struct c2c_dimension dim_stores = {
1137 .header = HEADER_SPAN("---- Store Reference ----", "Total", 2),
1140 .entry = store_entry,
1144 static struct c2c_dimension dim_stores_l1hit = {
1145 .header = HEADER_SPAN_LOW("L1Hit"),
1146 .name = "stores_l1hit",
1147 .cmp = st_l1hit_cmp,
1148 .entry = st_l1hit_entry,
1152 static struct c2c_dimension dim_stores_l1miss = {
1153 .header = HEADER_SPAN_LOW("L1Miss"),
1154 .name = "stores_l1miss",
1155 .cmp = st_l1miss_cmp,
1156 .entry = st_l1miss_entry,
1160 static struct c2c_dimension dim_cl_stores_l1hit = {
1161 .header = HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1162 .name = "cl_stores_l1hit",
1163 .cmp = st_l1hit_cmp,
1164 .entry = st_l1hit_entry,
1168 static struct c2c_dimension dim_cl_stores_l1miss = {
1169 .header = HEADER_SPAN_LOW("L1 Miss"),
1170 .name = "cl_stores_l1miss",
1171 .cmp = st_l1miss_cmp,
1172 .entry = st_l1miss_entry,
1176 static struct c2c_dimension dim_ld_fbhit = {
1177 .header = HEADER_SPAN("----- Core Load Hit -----", "FB", 2),
1179 .cmp = ld_fbhit_cmp,
1180 .entry = ld_fbhit_entry,
1184 static struct c2c_dimension dim_ld_l1hit = {
1185 .header = HEADER_SPAN_LOW("L1"),
1187 .cmp = ld_l1hit_cmp,
1188 .entry = ld_l1hit_entry,
1192 static struct c2c_dimension dim_ld_l2hit = {
1193 .header = HEADER_SPAN_LOW("L2"),
1195 .cmp = ld_l2hit_cmp,
1196 .entry = ld_l2hit_entry,
1200 static struct c2c_dimension dim_ld_llchit = {
1201 .header = HEADER_SPAN("-- LLC Load Hit --", "Llc", 1),
1202 .name = "ld_lclhit",
1203 .cmp = ld_llchit_cmp,
1204 .entry = ld_llchit_entry,
1208 static struct c2c_dimension dim_ld_rmthit = {
1209 .header = HEADER_SPAN_LOW("Rmt"),
1210 .name = "ld_rmthit",
1212 .entry = rmt_hit_entry,
1216 static struct c2c_dimension dim_ld_llcmiss = {
1217 .header = HEADER_BOTH("LLC", "Ld Miss"),
1218 .name = "ld_llcmiss",
1219 .cmp = ld_llcmiss_cmp,
1220 .entry = ld_llcmiss_entry,
1224 static struct c2c_dimension dim_tot_recs = {
1225 .header = HEADER_BOTH("Total", "records"),
1227 .cmp = tot_recs_cmp,
1228 .entry = tot_recs_entry,
1232 static struct c2c_dimension dim_tot_loads = {
1233 .header = HEADER_BOTH("Total", "Loads"),
1234 .name = "tot_loads",
1235 .cmp = tot_loads_cmp,
1236 .entry = tot_loads_entry,
1240 static struct c2c_dimension dim_percent_hitm = {
1241 .header = HEADER_LOW("%hitm"),
1242 .name = "percent_hitm",
1243 .cmp = percent_hitm_cmp,
1244 .entry = percent_hitm_entry,
1245 .color = percent_hitm_color,
1249 static struct c2c_dimension dim_percent_rmt_hitm = {
1250 .header = HEADER_SPAN("----- HITM -----", "Rmt", 1),
1251 .name = "percent_rmt_hitm",
1252 .cmp = percent_rmt_hitm_cmp,
1253 .entry = percent_rmt_hitm_entry,
1254 .color = percent_rmt_hitm_color,
1258 static struct c2c_dimension dim_percent_lcl_hitm = {
1259 .header = HEADER_SPAN_LOW("Lcl"),
1260 .name = "percent_lcl_hitm",
1261 .cmp = percent_lcl_hitm_cmp,
1262 .entry = percent_lcl_hitm_entry,
1263 .color = percent_lcl_hitm_color,
1267 static struct c2c_dimension dim_percent_stores_l1hit = {
1268 .header = HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1269 .name = "percent_stores_l1hit",
1270 .cmp = percent_stores_l1hit_cmp,
1271 .entry = percent_stores_l1hit_entry,
1272 .color = percent_stores_l1hit_color,
1276 static struct c2c_dimension dim_percent_stores_l1miss = {
1277 .header = HEADER_SPAN_LOW("L1 Miss"),
1278 .name = "percent_stores_l1miss",
1279 .cmp = percent_stores_l1miss_cmp,
1280 .entry = percent_stores_l1miss_entry,
1281 .color = percent_stores_l1miss_color,
1285 static struct c2c_dimension dim_dram_lcl = {
1286 .header = HEADER_SPAN("--- Load Dram ----", "Lcl", 1),
1288 .cmp = lcl_dram_cmp,
1289 .entry = lcl_dram_entry,
1293 static struct c2c_dimension dim_dram_rmt = {
1294 .header = HEADER_SPAN_LOW("Rmt"),
1296 .cmp = rmt_dram_cmp,
1297 .entry = rmt_dram_entry,
1301 static struct c2c_dimension dim_pid = {
1302 .header = HEADER_LOW("Pid"),
1309 static struct c2c_dimension dim_tid = {
1310 .header = HEADER_LOW("Tid"),
1315 static struct c2c_dimension dim_symbol = {
1320 static struct c2c_dimension dim_dso = {
1321 .header = HEADER_BOTH("Shared", "Object"),
1326 static struct c2c_header header_node[3] = {
1328 HEADER_LOW("Node{cpus %hitms %stores}"),
1329 HEADER_LOW("Node{cpu list}"),
1332 static struct c2c_dimension dim_node = {
1335 .entry = node_entry,
1339 static struct c2c_dimension dim_mean_rmt = {
1340 .header = HEADER_SPAN("---------- cycles ----------", "rmt hitm", 2),
1343 .entry = mean_rmt_entry,
1347 static struct c2c_dimension dim_mean_lcl = {
1348 .header = HEADER_SPAN_LOW("lcl hitm"),
1351 .entry = mean_lcl_entry,
1355 static struct c2c_dimension dim_mean_load = {
1356 .header = HEADER_SPAN_LOW("load"),
1357 .name = "mean_load",
1359 .entry = mean_load_entry,
1363 static struct c2c_dimension dim_cpucnt = {
1364 .header = HEADER_BOTH("cpu", "cnt"),
1367 .entry = cpucnt_entry,
1371 static struct c2c_dimension dim_srcline = {
1372 .name = "cl_srcline",
1373 .se = &sort_srcline,
1376 static struct c2c_dimension *dimensions[] = {
1388 &dim_cl_stores_l1hit,
1389 &dim_cl_stores_l1miss,
1399 &dim_percent_rmt_hitm,
1400 &dim_percent_lcl_hitm,
1401 &dim_percent_stores_l1hit,
1402 &dim_percent_stores_l1miss,
1418 static void fmt_free(struct perf_hpp_fmt *fmt)
1420 struct c2c_fmt *c2c_fmt;
1422 c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
1426 static bool fmt_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b)
1428 struct c2c_fmt *c2c_a = container_of(a, struct c2c_fmt, fmt);
1429 struct c2c_fmt *c2c_b = container_of(b, struct c2c_fmt, fmt);
1431 return c2c_a->dim == c2c_b->dim;
1434 static struct c2c_dimension *get_dimension(const char *name)
1438 for (i = 0; dimensions[i]; i++) {
1439 struct c2c_dimension *dim = dimensions[i];
1441 if (!strcmp(dim->name, name))
1448 static int c2c_se_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
1449 struct hist_entry *he)
1451 struct c2c_fmt *c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
1452 struct c2c_dimension *dim = c2c_fmt->dim;
1453 size_t len = fmt->user_len;
1456 len = hists__col_len(he->hists, dim->se->se_width_idx);
1458 return dim->se->se_snprintf(he, hpp->buf, hpp->size, len);
1461 static int64_t c2c_se_cmp(struct perf_hpp_fmt *fmt,
1462 struct hist_entry *a, struct hist_entry *b)
1464 struct c2c_fmt *c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
1465 struct c2c_dimension *dim = c2c_fmt->dim;
1467 return dim->se->se_cmp(a, b);
1470 static int64_t c2c_se_collapse(struct perf_hpp_fmt *fmt,
1471 struct hist_entry *a, struct hist_entry *b)
1473 struct c2c_fmt *c2c_fmt = container_of(fmt, struct c2c_fmt, fmt);
1474 struct c2c_dimension *dim = c2c_fmt->dim;
1475 int64_t (*collapse_fn)(struct hist_entry *, struct hist_entry *);
1477 collapse_fn = dim->se->se_collapse ?: dim->se->se_cmp;
1478 return collapse_fn(a, b);
1481 static struct c2c_fmt *get_format(const char *name)
1483 struct c2c_dimension *dim = get_dimension(name);
1484 struct c2c_fmt *c2c_fmt;
1485 struct perf_hpp_fmt *fmt;
1490 c2c_fmt = zalloc(sizeof(*c2c_fmt));
1496 fmt = &c2c_fmt->fmt;
1497 INIT_LIST_HEAD(&fmt->list);
1498 INIT_LIST_HEAD(&fmt->sort_list);
1500 fmt->cmp = dim->se ? c2c_se_cmp : dim->cmp;
1501 fmt->sort = dim->se ? c2c_se_cmp : dim->cmp;
1502 fmt->color = dim->se ? NULL : dim->color;
1503 fmt->entry = dim->se ? c2c_se_entry : dim->entry;
1504 fmt->header = c2c_header;
1505 fmt->width = c2c_width;
1506 fmt->collapse = dim->se ? c2c_se_collapse : dim->cmp;
1507 fmt->equal = fmt_equal;
1508 fmt->free = fmt_free;
1513 static int c2c_hists__init_output(struct perf_hpp_list *hpp_list, char *name)
1515 struct c2c_fmt *c2c_fmt = get_format(name);
1519 return output_field_add(hpp_list, name);
1522 perf_hpp_list__column_register(hpp_list, &c2c_fmt->fmt);
1526 static int c2c_hists__init_sort(struct perf_hpp_list *hpp_list, char *name)
1528 struct c2c_fmt *c2c_fmt = get_format(name);
1529 struct c2c_dimension *dim;
1533 return sort_dimension__add(hpp_list, name, NULL, 0);
1537 if (dim == &dim_dso)
1540 perf_hpp_list__register_sort_field(hpp_list, &c2c_fmt->fmt);
1544 #define PARSE_LIST(_list, _fn) \
1552 for (tok = strtok_r((char *)_list, ", ", &tmp); \
1553 tok; tok = strtok_r(NULL, ", ", &tmp)) { \
1554 ret = _fn(hpp_list, tok); \
1555 if (ret == -EINVAL) { \
1556 error("Invalid --fields key: `%s'", tok); \
1558 } else if (ret == -ESRCH) { \
1559 error("Unknown --fields key: `%s'", tok); \
1565 static int hpp_list__parse(struct perf_hpp_list *hpp_list,
1566 const char *output_,
1569 char *output = output_ ? strdup(output_) : NULL;
1570 char *sort = sort_ ? strdup(sort_) : NULL;
1573 PARSE_LIST(output, c2c_hists__init_output);
1574 PARSE_LIST(sort, c2c_hists__init_sort);
1576 /* copy sort keys to output fields */
1577 perf_hpp__setup_output_field(hpp_list);
1580 * We dont need other sorting keys other than those
1581 * we already specified. It also really slows down
1582 * the processing a lot with big number of output
1583 * fields, so switching this off for c2c.
1587 /* and then copy output fields to sort keys */
1588 perf_hpp__append_sort_keys(&hists->list);
1596 static int c2c_hists__init(struct c2c_hists *hists,
1598 int nr_header_lines)
1600 __hists__init(&hists->hists, &hists->list);
1603 * Initialize only with sort fields, we need to resort
1604 * later anyway, and that's where we add output fields
1607 perf_hpp_list__init(&hists->list);
1609 /* Overload number of header lines.*/
1610 hists->list.nr_header_lines = nr_header_lines;
1612 return hpp_list__parse(&hists->list, NULL, sort);
1616 static int c2c_hists__reinit(struct c2c_hists *c2c_hists,
1620 perf_hpp__reset_output_field(&c2c_hists->list);
1621 return hpp_list__parse(&c2c_hists->list, output, sort);
1624 static int filter_cb(struct hist_entry *he)
1626 if (c2c.show_src && !he->srcline)
1627 he->srcline = hist_entry__get_srcline(he);
1632 static int resort_cl_cb(struct hist_entry *he)
1634 struct c2c_hist_entry *c2c_he;
1635 struct c2c_hists *c2c_hists;
1637 c2c_he = container_of(he, struct c2c_hist_entry, he);
1638 c2c_hists = c2c_he->hists;
1641 c2c_hists__reinit(c2c_hists,
1644 "percent_stores_l1hit,"
1645 "percent_stores_l1miss,"
1656 "offset,rmt_hitm,lcl_hitm");
1658 hists__collapse_resort(&c2c_hists->hists, NULL);
1659 hists__output_resort_cb(&c2c_hists->hists, NULL, filter_cb);
1665 static void setup_nodes_header(void)
1667 dim_node.header = header_node[c2c.node_info];
1670 static int setup_nodes(struct perf_session *session)
1672 struct numa_node *n;
1673 unsigned long **nodes;
1677 if (c2c.node_info > 2)
1680 c2c.nodes_cnt = session->header.env.nr_numa_nodes;
1681 c2c.cpus_cnt = session->header.env.nr_cpus_online;
1683 n = session->header.env.numa_nodes;
1687 nodes = zalloc(sizeof(unsigned long *) * c2c.nodes_cnt);
1693 cpu2node = zalloc(sizeof(int) * c2c.cpus_cnt);
1697 for (cpu = 0; cpu < c2c.cpus_cnt; cpu++)
1700 c2c.cpu2node = cpu2node;
1702 for (node = 0; node < c2c.nodes_cnt; node++) {
1703 struct cpu_map *map = n[node].map;
1706 set = bitmap_alloc(c2c.cpus_cnt);
1710 for (cpu = 0; cpu < map->nr; cpu++) {
1711 set_bit(map->map[cpu], set);
1713 if (WARN_ONCE(cpu2node[map->map[cpu]] != -1, "node/cpu topology bug"))
1716 cpu2node[map->map[cpu]] = node;
1722 setup_nodes_header();
1726 static void print_cacheline(struct c2c_hists *c2c_hists,
1727 struct hist_entry *he_cl,
1728 struct perf_hpp_list *hpp_list,
1732 struct perf_hpp hpp = {
1739 hists__fprintf_headers(&c2c_hists->hists, out);
1745 fprintf(out, " ------------------------------------------------------\n");
1746 __hist_entry__snprintf(he_cl, &hpp, hpp_list);
1747 fprintf(out, "%s\n", bf);
1748 fprintf(out, " ------------------------------------------------------\n");
1750 hists__fprintf(&c2c_hists->hists, false, 0, 0, 0, out, true);
1753 static void print_pareto(FILE *out)
1755 struct perf_hpp_list hpp_list;
1759 perf_hpp_list__init(&hpp_list);
1760 ret = hpp_list__parse(&hpp_list,
1768 if (WARN_ONCE(ret, "failed to setup sort entries\n"))
1771 nd = rb_first(&c2c.hists.hists.entries);
1773 for (; nd; nd = rb_next(nd)) {
1774 struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
1775 struct c2c_hist_entry *c2c_he;
1780 c2c_he = container_of(he, struct c2c_hist_entry, he);
1781 print_cacheline(c2c_he->hists, he, &hpp_list, out);
1785 static void perf_c2c__hists_fprintf(FILE *out)
1790 fprintf(out, "=================================================\n");
1791 fprintf(out, " Shared Data Cache Line Table \n");
1792 fprintf(out, "=================================================\n");
1793 fprintf(out, "#\n");
1795 hists__fprintf(&c2c.hists.hists, true, 0, 0, 0, stdout, false);
1798 fprintf(out, "=================================================\n");
1799 fprintf(out, " Shared Cache Line Distribution Pareto \n");
1800 fprintf(out, "=================================================\n");
1801 fprintf(out, "#\n");
1806 static int perf_c2c__report(int argc, const char **argv)
1808 struct perf_session *session;
1809 struct ui_progress prog;
1810 struct perf_data_file file = {
1811 .mode = PERF_DATA_MODE_READ,
1813 const struct option c2c_options[] = {
1814 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
1815 "file", "vmlinux pathname"),
1816 OPT_INCR('v', "verbose", &verbose,
1817 "be more verbose (show counter open errors, etc)"),
1818 OPT_STRING('i', "input", &input_name, "file",
1819 "the input file to process"),
1820 OPT_INCR('N', "node-info", &c2c.node_info,
1821 "show extra node info in report (repeat for more info)"),
1826 argc = parse_options(argc, argv, c2c_options, report_c2c_usage,
1827 PARSE_OPT_STOP_AT_NON_OPTION);
1829 usage_with_options(report_c2c_usage, c2c_options);
1831 if (!input_name || !strlen(input_name))
1832 input_name = "perf.data";
1834 file.path = input_name;
1836 err = c2c_hists__init(&c2c.hists, "dcacheline", 2);
1838 pr_debug("Failed to initialize hists\n");
1842 session = perf_session__new(&file, 0, &c2c.tool);
1843 if (session == NULL) {
1844 pr_debug("No memory for session\n");
1847 err = setup_nodes(session);
1849 pr_err("Failed setup nodes\n");
1853 if (symbol__init(&session->header.env) < 0)
1856 /* No pipe support at the moment. */
1857 if (perf_data_file__is_pipe(session->file)) {
1858 pr_debug("No pipe support at the moment.\n");
1862 err = perf_session__process_events(session);
1864 pr_err("failed to process sample\n");
1868 c2c_hists__reinit(&c2c.hists,
1872 "tot_hitm,lcl_hitm,rmt_hitm,"
1873 "stores,stores_l1hit,stores_l1miss,"
1874 "dram_lcl,dram_rmt,"
1877 "ld_fbhit,ld_l1hit,ld_l2hit,"
1878 "ld_lclhit,ld_rmthit",
1882 ui_progress__init(&prog, c2c.hists.hists.nr_entries, "Sorting...");
1884 hists__collapse_resort(&c2c.hists.hists, NULL);
1885 hists__output_resort_cb(&c2c.hists.hists, &prog, resort_cl_cb);
1887 ui_progress__finish();
1890 perf_c2c__hists_fprintf(stdout);
1893 perf_session__delete(session);
1898 static int parse_record_events(const struct option *opt __maybe_unused,
1899 const char *str, int unset __maybe_unused)
1901 bool *event_set = (bool *) opt->value;
1904 return perf_mem_events__parse(str);
1908 static const char * const __usage_record[] = {
1909 "perf c2c record [<options>] [<command>]",
1910 "perf c2c record [<options>] -- <command> [<options>]",
1914 static const char * const *record_mem_usage = __usage_record;
1916 static int perf_c2c__record(int argc, const char **argv)
1918 int rec_argc, i = 0, j;
1919 const char **rec_argv;
1921 bool all_user = false, all_kernel = false;
1922 bool event_set = false;
1923 struct option options[] = {
1924 OPT_CALLBACK('e', "event", &event_set, "event",
1925 "event selector. Use 'perf mem record -e list' to list available events",
1926 parse_record_events),
1927 OPT_INCR('v', "verbose", &verbose,
1928 "be more verbose (show counter open errors, etc)"),
1929 OPT_BOOLEAN('u', "all-user", &all_user, "collect only user level data"),
1930 OPT_BOOLEAN('k', "all-kernel", &all_kernel, "collect only kernel level data"),
1931 OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat, "setup mem-loads latency"),
1935 if (perf_mem_events__init()) {
1936 pr_err("failed: memory events not supported\n");
1940 argc = parse_options(argc, argv, options, record_mem_usage,
1941 PARSE_OPT_KEEP_UNKNOWN);
1943 rec_argc = argc + 10; /* max number of arguments */
1944 rec_argv = calloc(rec_argc + 1, sizeof(char *));
1948 rec_argv[i++] = "record";
1951 perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true;
1952 perf_mem_events[PERF_MEM_EVENTS__STORE].record = true;
1955 if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record)
1956 rec_argv[i++] = "-W";
1958 rec_argv[i++] = "-d";
1959 rec_argv[i++] = "--sample-cpu";
1961 for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
1962 if (!perf_mem_events[j].record)
1965 if (!perf_mem_events[j].supported) {
1966 pr_err("failed: event '%s' not supported\n",
1967 perf_mem_events[j].name);
1971 rec_argv[i++] = "-e";
1972 rec_argv[i++] = perf_mem_events__name(j);
1976 rec_argv[i++] = "--all-user";
1979 rec_argv[i++] = "--all-kernel";
1981 for (j = 0; j < argc; j++, i++)
1982 rec_argv[i] = argv[j];
1985 pr_debug("calling: ");
1989 while (rec_argv[j]) {
1990 pr_debug("%s ", rec_argv[j]);
1996 ret = cmd_record(i, rec_argv, NULL);
2001 int cmd_c2c(int argc, const char **argv, const char *prefix __maybe_unused)
2003 const struct option c2c_options[] = {
2004 OPT_INCR('v', "verbose", &verbose, "be more verbose"),
2008 argc = parse_options(argc, argv, c2c_options, c2c_usage,
2009 PARSE_OPT_STOP_AT_NON_OPTION);
2012 usage_with_options(c2c_usage, c2c_options);
2014 if (!strncmp(argv[0], "rec", 3)) {
2015 return perf_c2c__record(argc, argv);
2016 } else if (!strncmp(argv[0], "rep", 3)) {
2017 return perf_c2c__report(argc, argv);
2019 usage_with_options(c2c_usage, c2c_options);