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"
19 #include "ui/browsers/hists.h"
24 struct perf_hpp_list list
;
25 struct c2c_stats stats
;
28 struct compute_stats
{
29 struct stats lcl_hitm
;
30 struct stats rmt_hitm
;
34 struct c2c_hist_entry
{
35 struct c2c_hists
*hists
;
36 struct c2c_stats stats
;
37 unsigned long *cpuset
;
38 struct c2c_stats
*node_stats
;
39 unsigned int cacheline_idx
;
41 struct compute_stats cstats
;
45 * because of its callchain dynamic entry
50 static char const *coalesce_default
= "pid,tid,iaddr";
53 struct perf_tool tool
;
54 struct c2c_hists hists
;
56 unsigned long **nodes
;
66 /* HITM shared clines stats */
67 struct c2c_stats hitm_stats
;
83 static struct perf_c2c c2c
;
85 static void *c2c_he_zalloc(size_t size
)
87 struct c2c_hist_entry
*c2c_he
;
89 c2c_he
= zalloc(size
+ sizeof(*c2c_he
));
93 c2c_he
->cpuset
= bitmap_alloc(c2c
.cpus_cnt
);
97 c2c_he
->node_stats
= zalloc(c2c
.nodes_cnt
* sizeof(*c2c_he
->node_stats
));
98 if (!c2c_he
->node_stats
)
101 init_stats(&c2c_he
->cstats
.lcl_hitm
);
102 init_stats(&c2c_he
->cstats
.rmt_hitm
);
103 init_stats(&c2c_he
->cstats
.load
);
108 static void c2c_he_free(void *he
)
110 struct c2c_hist_entry
*c2c_he
;
112 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
114 hists__delete_entries(&c2c_he
->hists
->hists
);
118 free(c2c_he
->cpuset
);
119 free(c2c_he
->node_stats
);
123 static struct hist_entry_ops c2c_entry_ops
= {
124 .new = c2c_he_zalloc
,
128 static int c2c_hists__init(struct c2c_hists
*hists
,
130 int nr_header_lines
);
132 static struct c2c_hists
*
133 he__get_c2c_hists(struct hist_entry
*he
,
137 struct c2c_hist_entry
*c2c_he
;
138 struct c2c_hists
*hists
;
141 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
143 return c2c_he
->hists
;
145 hists
= c2c_he
->hists
= zalloc(sizeof(*hists
));
149 ret
= c2c_hists__init(hists
, sort
, nr_header_lines
);
158 static void c2c_he__set_cpu(struct c2c_hist_entry
*c2c_he
,
159 struct perf_sample
*sample
)
161 if (WARN_ONCE(sample
->cpu
== (unsigned int) -1,
162 "WARNING: no sample cpu value"))
165 set_bit(sample
->cpu
, c2c_he
->cpuset
);
168 static void compute_stats(struct c2c_hist_entry
*c2c_he
,
169 struct c2c_stats
*stats
,
172 struct compute_stats
*cstats
= &c2c_he
->cstats
;
175 update_stats(&cstats
->rmt_hitm
, weight
);
176 else if (stats
->lcl_hitm
)
177 update_stats(&cstats
->lcl_hitm
, weight
);
178 else if (stats
->load
)
179 update_stats(&cstats
->load
, weight
);
182 static int process_sample_event(struct perf_tool
*tool __maybe_unused
,
183 union perf_event
*event
,
184 struct perf_sample
*sample
,
185 struct perf_evsel
*evsel __maybe_unused
,
186 struct machine
*machine
)
188 struct c2c_hists
*c2c_hists
= &c2c
.hists
;
189 struct c2c_hist_entry
*c2c_he
;
190 struct c2c_stats stats
= { .nr_entries
= 0, };
191 struct hist_entry
*he
;
192 struct addr_location al
;
193 struct mem_info
*mi
, *mi_dup
;
196 if (machine__resolve(machine
, &al
, sample
) < 0) {
197 pr_debug("problem processing %d event, skipping it.\n",
202 ret
= sample__resolve_callchain(sample
, &callchain_cursor
, NULL
,
203 evsel
, &al
, sysctl_perf_event_max_stack
);
207 mi
= sample__resolve_mem(sample
, &al
);
211 mi_dup
= memdup(mi
, sizeof(*mi
));
215 c2c_decode_stats(&stats
, mi
);
217 he
= hists__add_entry_ops(&c2c_hists
->hists
, &c2c_entry_ops
,
223 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
224 c2c_add_stats(&c2c_he
->stats
, &stats
);
225 c2c_add_stats(&c2c_hists
->stats
, &stats
);
227 c2c_he__set_cpu(c2c_he
, sample
);
229 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
230 ret
= hist_entry__append_callchain(he
, sample
);
234 * There's already been warning about missing
235 * sample's cpu value. Let's account all to
236 * node 0 in this case, without any further
239 * Doing node stats only for single callchain data.
241 int cpu
= sample
->cpu
== (unsigned int) -1 ? 0 : sample
->cpu
;
242 int node
= c2c
.cpu2node
[cpu
];
246 mi_dup
= memdup(mi
, sizeof(*mi
));
250 c2c_hists
= he__get_c2c_hists(he
, c2c
.cl_sort
, 2);
254 he
= hists__add_entry_ops(&c2c_hists
->hists
, &c2c_entry_ops
,
260 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
261 c2c_add_stats(&c2c_he
->stats
, &stats
);
262 c2c_add_stats(&c2c_hists
->stats
, &stats
);
263 c2c_add_stats(&c2c_he
->node_stats
[node
], &stats
);
265 compute_stats(c2c_he
, &stats
, sample
->weight
);
267 c2c_he__set_cpu(c2c_he
, sample
);
269 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
270 ret
= hist_entry__append_callchain(he
, sample
);
274 addr_location__put(&al
);
285 static struct perf_c2c c2c
= {
287 .sample
= process_sample_event
,
288 .mmap
= perf_event__process_mmap
,
289 .mmap2
= perf_event__process_mmap2
,
290 .comm
= perf_event__process_comm
,
291 .exit
= perf_event__process_exit
,
292 .fork
= perf_event__process_fork
,
293 .lost
= perf_event__process_lost
,
294 .ordered_events
= true,
295 .ordering_requires_timestamps
= true,
299 static const char * const c2c_usage
[] = {
300 "perf c2c {record|report}",
304 static const char * const __usage_report
[] = {
309 static const char * const *report_c2c_usage
= __usage_report
;
311 #define C2C_HEADER_MAX 2
317 } line
[C2C_HEADER_MAX
];
320 struct c2c_dimension
{
321 struct c2c_header header
;
324 struct sort_entry
*se
;
326 int64_t (*cmp
)(struct perf_hpp_fmt
*fmt
,
327 struct hist_entry
*, struct hist_entry
*);
328 int (*entry
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
329 struct hist_entry
*he
);
330 int (*color
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
331 struct hist_entry
*he
);
335 struct perf_hpp_fmt fmt
;
336 struct c2c_dimension
*dim
;
339 static int c2c_width(struct perf_hpp_fmt
*fmt
,
340 struct perf_hpp
*hpp __maybe_unused
,
341 struct hists
*hists __maybe_unused
)
343 struct c2c_fmt
*c2c_fmt
;
344 struct c2c_dimension
*dim
;
346 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
349 return dim
->se
? hists__col_len(hists
, dim
->se
->se_width_idx
) :
353 static int c2c_header(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
354 struct hists
*hists
, int line
, int *span
)
356 struct perf_hpp_list
*hpp_list
= hists
->hpp_list
;
357 struct c2c_fmt
*c2c_fmt
;
358 struct c2c_dimension
*dim
;
359 const char *text
= NULL
;
360 int width
= c2c_width(fmt
, hpp
, hists
);
362 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
366 text
= dim
->header
.line
[line
].text
;
367 /* Use the last line from sort_entry if not defined. */
368 if (!text
&& (line
== hpp_list
->nr_header_lines
- 1))
369 text
= dim
->se
->se_header
;
371 text
= dim
->header
.line
[line
].text
;
377 *span
= dim
->header
.line
[line
].span
;
384 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, text
);
387 #define HEX_STR(__s, __v) \
389 scnprintf(__s, sizeof(__s), "0x%" PRIx64, __v); \
394 dcacheline_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
395 struct hist_entry
*left
, struct hist_entry
*right
)
397 return sort__dcacheline_cmp(left
, right
);
400 static int dcacheline_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
401 struct hist_entry
*he
)
404 int width
= c2c_width(fmt
, hpp
, he
->hists
);
408 addr
= cl_address(he
->mem_info
->daddr
.addr
);
410 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
413 static int offset_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
414 struct hist_entry
*he
)
417 int width
= c2c_width(fmt
, hpp
, he
->hists
);
421 addr
= cl_offset(he
->mem_info
->daddr
.al_addr
);
423 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
427 offset_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
428 struct hist_entry
*left
, struct hist_entry
*right
)
430 uint64_t l
= 0, r
= 0;
433 l
= cl_offset(left
->mem_info
->daddr
.addr
);
435 r
= cl_offset(right
->mem_info
->daddr
.addr
);
437 return (int64_t)(r
- l
);
441 iaddr_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
442 struct hist_entry
*he
)
445 int width
= c2c_width(fmt
, hpp
, he
->hists
);
449 addr
= he
->mem_info
->iaddr
.addr
;
451 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
455 iaddr_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
456 struct hist_entry
*left
, struct hist_entry
*right
)
458 return sort__iaddr_cmp(left
, right
);
462 tot_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
463 struct hist_entry
*he
)
465 struct c2c_hist_entry
*c2c_he
;
466 int width
= c2c_width(fmt
, hpp
, he
->hists
);
467 unsigned int tot_hitm
;
469 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
470 tot_hitm
= c2c_he
->stats
.lcl_hitm
+ c2c_he
->stats
.rmt_hitm
;
472 return scnprintf(hpp
->buf
, hpp
->size
, "%*u", width
, tot_hitm
);
476 tot_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
477 struct hist_entry
*left
, struct hist_entry
*right
)
479 struct c2c_hist_entry
*c2c_left
;
480 struct c2c_hist_entry
*c2c_right
;
481 unsigned int tot_hitm_left
;
482 unsigned int tot_hitm_right
;
484 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
485 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
487 tot_hitm_left
= c2c_left
->stats
.lcl_hitm
+ c2c_left
->stats
.rmt_hitm
;
488 tot_hitm_right
= c2c_right
->stats
.lcl_hitm
+ c2c_right
->stats
.rmt_hitm
;
490 return tot_hitm_left
- tot_hitm_right
;
493 #define STAT_FN_ENTRY(__f) \
495 __f ## _entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, \
496 struct hist_entry *he) \
498 struct c2c_hist_entry *c2c_he; \
499 int width = c2c_width(fmt, hpp, he->hists); \
501 c2c_he = container_of(he, struct c2c_hist_entry, he); \
502 return scnprintf(hpp->buf, hpp->size, "%*u", width, \
503 c2c_he->stats.__f); \
506 #define STAT_FN_CMP(__f) \
508 __f ## _cmp(struct perf_hpp_fmt *fmt __maybe_unused, \
509 struct hist_entry *left, struct hist_entry *right) \
511 struct c2c_hist_entry *c2c_left, *c2c_right; \
513 c2c_left = container_of(left, struct c2c_hist_entry, he); \
514 c2c_right = container_of(right, struct c2c_hist_entry, he); \
515 return c2c_left->stats.__f - c2c_right->stats.__f; \
518 #define STAT_FN(__f) \
533 static uint64_t llc_miss(struct c2c_stats
*stats
)
537 llcmiss
= stats
->lcl_dram
+
546 ld_llcmiss_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
547 struct hist_entry
*he
)
549 struct c2c_hist_entry
*c2c_he
;
550 int width
= c2c_width(fmt
, hpp
, he
->hists
);
552 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
554 return scnprintf(hpp
->buf
, hpp
->size
, "%*lu", width
,
555 llc_miss(&c2c_he
->stats
));
559 ld_llcmiss_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
560 struct hist_entry
*left
, struct hist_entry
*right
)
562 struct c2c_hist_entry
*c2c_left
;
563 struct c2c_hist_entry
*c2c_right
;
565 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
566 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
568 return llc_miss(&c2c_left
->stats
) - llc_miss(&c2c_right
->stats
);
571 static uint64_t total_records(struct c2c_stats
*stats
)
573 uint64_t lclmiss
, ldcnt
, total
;
575 lclmiss
= stats
->lcl_dram
+
595 tot_recs_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
596 struct hist_entry
*he
)
598 struct c2c_hist_entry
*c2c_he
;
599 int width
= c2c_width(fmt
, hpp
, he
->hists
);
602 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
603 tot_recs
= total_records(&c2c_he
->stats
);
605 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
609 tot_recs_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
610 struct hist_entry
*left
, struct hist_entry
*right
)
612 struct c2c_hist_entry
*c2c_left
;
613 struct c2c_hist_entry
*c2c_right
;
614 uint64_t tot_recs_left
;
615 uint64_t tot_recs_right
;
617 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
618 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
620 tot_recs_left
= total_records(&c2c_left
->stats
);
621 tot_recs_right
= total_records(&c2c_right
->stats
);
623 return tot_recs_left
- tot_recs_right
;
626 static uint64_t total_loads(struct c2c_stats
*stats
)
628 uint64_t lclmiss
, ldcnt
;
630 lclmiss
= stats
->lcl_dram
+
646 tot_loads_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
647 struct hist_entry
*he
)
649 struct c2c_hist_entry
*c2c_he
;
650 int width
= c2c_width(fmt
, hpp
, he
->hists
);
653 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
654 tot_recs
= total_loads(&c2c_he
->stats
);
656 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
660 tot_loads_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
661 struct hist_entry
*left
, struct hist_entry
*right
)
663 struct c2c_hist_entry
*c2c_left
;
664 struct c2c_hist_entry
*c2c_right
;
665 uint64_t tot_recs_left
;
666 uint64_t tot_recs_right
;
668 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
669 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
671 tot_recs_left
= total_loads(&c2c_left
->stats
);
672 tot_recs_right
= total_loads(&c2c_right
->stats
);
674 return tot_recs_left
- tot_recs_right
;
677 typedef double (get_percent_cb
)(struct c2c_hist_entry
*);
680 percent_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
681 struct hist_entry
*he
, get_percent_cb get_percent
)
683 struct c2c_hist_entry
*c2c_he
;
684 int width
= c2c_width(fmt
, hpp
, he
->hists
);
687 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
688 per
= get_percent(c2c_he
);
690 #ifdef HAVE_SLANG_SUPPORT
692 return __hpp__slsmg_color_printf(hpp
, "%*.2f%%", width
- 1, per
);
694 return hpp_color_scnprintf(hpp
, "%*.2f%%", width
- 1, per
);
697 static double percent_hitm(struct c2c_hist_entry
*c2c_he
)
699 struct c2c_hists
*hists
;
700 struct c2c_stats
*stats
;
701 struct c2c_stats
*total
;
705 hists
= container_of(c2c_he
->he
.hists
, struct c2c_hists
, hists
);
706 stats
= &c2c_he
->stats
;
707 total
= &hists
->stats
;
709 switch (c2c
.display
) {
711 st
= stats
->rmt_hitm
;
712 tot
= total
->rmt_hitm
;
715 st
= stats
->lcl_hitm
;
716 tot
= total
->lcl_hitm
;
721 p
= tot
? (double) st
/ tot
: 0;
726 #define PERC_STR(__s, __v) \
728 scnprintf(__s, sizeof(__s), "%.2F%%", __v); \
733 percent_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
734 struct hist_entry
*he
)
736 struct c2c_hist_entry
*c2c_he
;
737 int width
= c2c_width(fmt
, hpp
, he
->hists
);
741 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
742 per
= percent_hitm(c2c_he
);
743 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
747 percent_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
748 struct hist_entry
*he
)
750 return percent_color(fmt
, hpp
, he
, percent_hitm
);
754 percent_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
755 struct hist_entry
*left
, struct hist_entry
*right
)
757 struct c2c_hist_entry
*c2c_left
;
758 struct c2c_hist_entry
*c2c_right
;
762 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
763 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
765 per_left
= percent_hitm(c2c_left
);
766 per_right
= percent_hitm(c2c_right
);
768 return per_left
- per_right
;
771 static struct c2c_stats
*he_stats(struct hist_entry
*he
)
773 struct c2c_hist_entry
*c2c_he
;
775 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
776 return &c2c_he
->stats
;
779 static struct c2c_stats
*total_stats(struct hist_entry
*he
)
781 struct c2c_hists
*hists
;
783 hists
= container_of(he
->hists
, struct c2c_hists
, hists
);
784 return &hists
->stats
;
787 static double percent(int st
, int tot
)
789 return tot
? 100. * (double) st
/ (double) tot
: 0;
792 #define PERCENT(__h, __f) percent(he_stats(__h)->__f, total_stats(__h)->__f)
794 #define PERCENT_FN(__f) \
795 static double percent_ ## __f(struct c2c_hist_entry *c2c_he) \
797 struct c2c_hists *hists; \
799 hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); \
800 return percent(c2c_he->stats.__f, hists->stats.__f); \
806 PERCENT_FN(st_l1miss
)
809 percent_rmt_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
810 struct hist_entry
*he
)
812 int width
= c2c_width(fmt
, hpp
, he
->hists
);
813 double per
= PERCENT(he
, rmt_hitm
);
816 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
820 percent_rmt_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
821 struct hist_entry
*he
)
823 return percent_color(fmt
, hpp
, he
, percent_rmt_hitm
);
827 percent_rmt_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
828 struct hist_entry
*left
, struct hist_entry
*right
)
833 per_left
= PERCENT(left
, lcl_hitm
);
834 per_right
= PERCENT(right
, lcl_hitm
);
836 return per_left
- per_right
;
840 percent_lcl_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
841 struct hist_entry
*he
)
843 int width
= c2c_width(fmt
, hpp
, he
->hists
);
844 double per
= PERCENT(he
, lcl_hitm
);
847 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
851 percent_lcl_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
852 struct hist_entry
*he
)
854 return percent_color(fmt
, hpp
, he
, percent_lcl_hitm
);
858 percent_lcl_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
859 struct hist_entry
*left
, struct hist_entry
*right
)
864 per_left
= PERCENT(left
, lcl_hitm
);
865 per_right
= PERCENT(right
, lcl_hitm
);
867 return per_left
- per_right
;
871 percent_stores_l1hit_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
872 struct hist_entry
*he
)
874 int width
= c2c_width(fmt
, hpp
, he
->hists
);
875 double per
= PERCENT(he
, st_l1hit
);
878 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
882 percent_stores_l1hit_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
883 struct hist_entry
*he
)
885 return percent_color(fmt
, hpp
, he
, percent_st_l1hit
);
889 percent_stores_l1hit_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
890 struct hist_entry
*left
, struct hist_entry
*right
)
895 per_left
= PERCENT(left
, st_l1hit
);
896 per_right
= PERCENT(right
, st_l1hit
);
898 return per_left
- per_right
;
902 percent_stores_l1miss_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
903 struct hist_entry
*he
)
905 int width
= c2c_width(fmt
, hpp
, he
->hists
);
906 double per
= PERCENT(he
, st_l1miss
);
909 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
913 percent_stores_l1miss_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
914 struct hist_entry
*he
)
916 return percent_color(fmt
, hpp
, he
, percent_st_l1miss
);
920 percent_stores_l1miss_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
921 struct hist_entry
*left
, struct hist_entry
*right
)
926 per_left
= PERCENT(left
, st_l1miss
);
927 per_right
= PERCENT(right
, st_l1miss
);
929 return per_left
- per_right
;
936 pid_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
937 struct hist_entry
*he
)
939 int width
= c2c_width(fmt
, hpp
, he
->hists
);
941 return scnprintf(hpp
->buf
, hpp
->size
, "%*d", width
, he
->thread
->pid_
);
945 pid_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
946 struct hist_entry
*left
, struct hist_entry
*right
)
948 return left
->thread
->pid_
- right
->thread
->pid_
;
952 empty_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
953 struct hist_entry
*left __maybe_unused
,
954 struct hist_entry
*right __maybe_unused
)
960 node_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
961 struct hist_entry
*he
)
963 struct c2c_hist_entry
*c2c_he
;
968 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
970 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
971 DECLARE_BITMAP(set
, c2c
.cpus_cnt
);
973 bitmap_zero(set
, c2c
.cpus_cnt
);
974 bitmap_and(set
, c2c_he
->cpuset
, c2c
.nodes
[node
], c2c
.cpus_cnt
);
976 if (!bitmap_weight(set
, c2c
.cpus_cnt
)) {
977 if (c2c
.node_info
== 1) {
978 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%21s", " ");
979 advance_hpp(hpp
, ret
);
985 ret
= scnprintf(hpp
->buf
, hpp
->size
, " ");
986 advance_hpp(hpp
, ret
);
989 switch (c2c
.node_info
) {
991 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d", node
);
992 advance_hpp(hpp
, ret
);
996 int num
= bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
);
997 struct c2c_stats
*stats
= &c2c_he
->node_stats
[node
];
999 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{%2d ", node
, num
);
1000 advance_hpp(hpp
, ret
);
1002 #define DISPLAY_HITM(__h) \
1003 if (c2c_he->stats.__h> 0) { \
1004 ret = scnprintf(hpp->buf, hpp->size, "%5.1f%% ", \
1005 percent(stats->__h, c2c_he->stats.__h));\
1007 ret = scnprintf(hpp->buf, hpp->size, "%6s ", "n/a"); \
1010 switch (c2c
.display
) {
1012 DISPLAY_HITM(rmt_hitm
);
1015 DISPLAY_HITM(lcl_hitm
);
1022 advance_hpp(hpp
, ret
);
1024 if (c2c_he
->stats
.store
> 0) {
1025 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%5.1f%%}",
1026 percent(stats
->store
, c2c_he
->stats
.store
));
1028 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%6s}", "n/a");
1031 advance_hpp(hpp
, ret
);
1035 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{", node
);
1036 advance_hpp(hpp
, ret
);
1038 ret
= bitmap_scnprintf(set
, c2c
.cpus_cnt
, hpp
->buf
, hpp
->size
);
1039 advance_hpp(hpp
, ret
);
1041 ret
= scnprintf(hpp
->buf
, hpp
->size
, "}");
1042 advance_hpp(hpp
, ret
);
1055 mean_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1056 struct hist_entry
*he
, double mean
)
1058 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1061 scnprintf(buf
, 10, "%6.0f", mean
);
1062 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1065 #define MEAN_ENTRY(__func, __val) \
1067 __func(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, struct hist_entry *he) \
1069 struct c2c_hist_entry *c2c_he; \
1070 c2c_he = container_of(he, struct c2c_hist_entry, he); \
1071 return mean_entry(fmt, hpp, he, avg_stats(&c2c_he->cstats.__val)); \
1074 MEAN_ENTRY(mean_rmt_entry
, rmt_hitm
);
1075 MEAN_ENTRY(mean_lcl_entry
, lcl_hitm
);
1076 MEAN_ENTRY(mean_load_entry
, load
);
1079 cpucnt_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
1080 struct hist_entry
*he
)
1082 struct c2c_hist_entry
*c2c_he
;
1083 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1086 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1088 scnprintf(buf
, 10, "%d", bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
));
1089 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1093 cl_idx_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
1094 struct hist_entry
*he
)
1096 struct c2c_hist_entry
*c2c_he
;
1097 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1100 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1102 scnprintf(buf
, 10, "%u", c2c_he
->cacheline_idx
);
1103 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1107 cl_idx_empty_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
1108 struct hist_entry
*he
)
1110 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1112 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, "");
1115 #define HEADER_LOW(__h) \
1122 #define HEADER_BOTH(__h0, __h1) \
1132 #define HEADER_SPAN(__h0, __h1, __s) \
1143 #define HEADER_SPAN_LOW(__h) \
1150 static struct c2c_dimension dim_dcacheline
= {
1151 .header
= HEADER_LOW("Cacheline"),
1152 .name
= "dcacheline",
1153 .cmp
= dcacheline_cmp
,
1154 .entry
= dcacheline_entry
,
1158 static struct c2c_header header_offset_tui
= HEADER_LOW("Off");
1160 static struct c2c_dimension dim_offset
= {
1161 .header
= HEADER_BOTH("Data address", "Offset"),
1164 .entry
= offset_entry
,
1168 static struct c2c_dimension dim_iaddr
= {
1169 .header
= HEADER_LOW("Code address"),
1172 .entry
= iaddr_entry
,
1176 static struct c2c_dimension dim_tot_hitm
= {
1177 .header
= HEADER_SPAN("----- LLC Load Hitm -----", "Total", 2),
1179 .cmp
= tot_hitm_cmp
,
1180 .entry
= tot_hitm_entry
,
1184 static struct c2c_dimension dim_lcl_hitm
= {
1185 .header
= HEADER_SPAN_LOW("Lcl"),
1187 .cmp
= lcl_hitm_cmp
,
1188 .entry
= lcl_hitm_entry
,
1192 static struct c2c_dimension dim_rmt_hitm
= {
1193 .header
= HEADER_SPAN_LOW("Rmt"),
1195 .cmp
= rmt_hitm_cmp
,
1196 .entry
= rmt_hitm_entry
,
1200 static struct c2c_dimension dim_cl_rmt_hitm
= {
1201 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1202 .name
= "cl_rmt_hitm",
1203 .cmp
= rmt_hitm_cmp
,
1204 .entry
= rmt_hitm_entry
,
1208 static struct c2c_dimension dim_cl_lcl_hitm
= {
1209 .header
= HEADER_SPAN_LOW("Lcl"),
1210 .name
= "cl_lcl_hitm",
1211 .cmp
= lcl_hitm_cmp
,
1212 .entry
= lcl_hitm_entry
,
1216 static struct c2c_dimension dim_stores
= {
1217 .header
= HEADER_SPAN("---- Store Reference ----", "Total", 2),
1220 .entry
= store_entry
,
1224 static struct c2c_dimension dim_stores_l1hit
= {
1225 .header
= HEADER_SPAN_LOW("L1Hit"),
1226 .name
= "stores_l1hit",
1227 .cmp
= st_l1hit_cmp
,
1228 .entry
= st_l1hit_entry
,
1232 static struct c2c_dimension dim_stores_l1miss
= {
1233 .header
= HEADER_SPAN_LOW("L1Miss"),
1234 .name
= "stores_l1miss",
1235 .cmp
= st_l1miss_cmp
,
1236 .entry
= st_l1miss_entry
,
1240 static struct c2c_dimension dim_cl_stores_l1hit
= {
1241 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1242 .name
= "cl_stores_l1hit",
1243 .cmp
= st_l1hit_cmp
,
1244 .entry
= st_l1hit_entry
,
1248 static struct c2c_dimension dim_cl_stores_l1miss
= {
1249 .header
= HEADER_SPAN_LOW("L1 Miss"),
1250 .name
= "cl_stores_l1miss",
1251 .cmp
= st_l1miss_cmp
,
1252 .entry
= st_l1miss_entry
,
1256 static struct c2c_dimension dim_ld_fbhit
= {
1257 .header
= HEADER_SPAN("----- Core Load Hit -----", "FB", 2),
1259 .cmp
= ld_fbhit_cmp
,
1260 .entry
= ld_fbhit_entry
,
1264 static struct c2c_dimension dim_ld_l1hit
= {
1265 .header
= HEADER_SPAN_LOW("L1"),
1267 .cmp
= ld_l1hit_cmp
,
1268 .entry
= ld_l1hit_entry
,
1272 static struct c2c_dimension dim_ld_l2hit
= {
1273 .header
= HEADER_SPAN_LOW("L2"),
1275 .cmp
= ld_l2hit_cmp
,
1276 .entry
= ld_l2hit_entry
,
1280 static struct c2c_dimension dim_ld_llchit
= {
1281 .header
= HEADER_SPAN("-- LLC Load Hit --", "Llc", 1),
1282 .name
= "ld_lclhit",
1283 .cmp
= ld_llchit_cmp
,
1284 .entry
= ld_llchit_entry
,
1288 static struct c2c_dimension dim_ld_rmthit
= {
1289 .header
= HEADER_SPAN_LOW("Rmt"),
1290 .name
= "ld_rmthit",
1292 .entry
= rmt_hit_entry
,
1296 static struct c2c_dimension dim_ld_llcmiss
= {
1297 .header
= HEADER_BOTH("LLC", "Ld Miss"),
1298 .name
= "ld_llcmiss",
1299 .cmp
= ld_llcmiss_cmp
,
1300 .entry
= ld_llcmiss_entry
,
1304 static struct c2c_dimension dim_tot_recs
= {
1305 .header
= HEADER_BOTH("Total", "records"),
1307 .cmp
= tot_recs_cmp
,
1308 .entry
= tot_recs_entry
,
1312 static struct c2c_dimension dim_tot_loads
= {
1313 .header
= HEADER_BOTH("Total", "Loads"),
1314 .name
= "tot_loads",
1315 .cmp
= tot_loads_cmp
,
1316 .entry
= tot_loads_entry
,
1320 static struct c2c_header percent_hitm_header
[] = {
1321 [DISPLAY_LCL
] = HEADER_BOTH("Lcl", "Hitm"),
1322 [DISPLAY_RMT
] = HEADER_BOTH("Rmt", "Hitm"),
1325 static struct c2c_dimension dim_percent_hitm
= {
1326 .name
= "percent_hitm",
1327 .cmp
= percent_hitm_cmp
,
1328 .entry
= percent_hitm_entry
,
1329 .color
= percent_hitm_color
,
1333 static struct c2c_dimension dim_percent_rmt_hitm
= {
1334 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1335 .name
= "percent_rmt_hitm",
1336 .cmp
= percent_rmt_hitm_cmp
,
1337 .entry
= percent_rmt_hitm_entry
,
1338 .color
= percent_rmt_hitm_color
,
1342 static struct c2c_dimension dim_percent_lcl_hitm
= {
1343 .header
= HEADER_SPAN_LOW("Lcl"),
1344 .name
= "percent_lcl_hitm",
1345 .cmp
= percent_lcl_hitm_cmp
,
1346 .entry
= percent_lcl_hitm_entry
,
1347 .color
= percent_lcl_hitm_color
,
1351 static struct c2c_dimension dim_percent_stores_l1hit
= {
1352 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1353 .name
= "percent_stores_l1hit",
1354 .cmp
= percent_stores_l1hit_cmp
,
1355 .entry
= percent_stores_l1hit_entry
,
1356 .color
= percent_stores_l1hit_color
,
1360 static struct c2c_dimension dim_percent_stores_l1miss
= {
1361 .header
= HEADER_SPAN_LOW("L1 Miss"),
1362 .name
= "percent_stores_l1miss",
1363 .cmp
= percent_stores_l1miss_cmp
,
1364 .entry
= percent_stores_l1miss_entry
,
1365 .color
= percent_stores_l1miss_color
,
1369 static struct c2c_dimension dim_dram_lcl
= {
1370 .header
= HEADER_SPAN("--- Load Dram ----", "Lcl", 1),
1372 .cmp
= lcl_dram_cmp
,
1373 .entry
= lcl_dram_entry
,
1377 static struct c2c_dimension dim_dram_rmt
= {
1378 .header
= HEADER_SPAN_LOW("Rmt"),
1380 .cmp
= rmt_dram_cmp
,
1381 .entry
= rmt_dram_entry
,
1385 static struct c2c_dimension dim_pid
= {
1386 .header
= HEADER_LOW("Pid"),
1393 static struct c2c_dimension dim_tid
= {
1394 .header
= HEADER_LOW("Tid"),
1399 static struct c2c_dimension dim_symbol
= {
1404 static struct c2c_dimension dim_dso
= {
1405 .header
= HEADER_BOTH("Shared", "Object"),
1410 static struct c2c_header header_node
[3] = {
1412 HEADER_LOW("Node{cpus %hitms %stores}"),
1413 HEADER_LOW("Node{cpu list}"),
1416 static struct c2c_dimension dim_node
= {
1419 .entry
= node_entry
,
1423 static struct c2c_dimension dim_mean_rmt
= {
1424 .header
= HEADER_SPAN("---------- cycles ----------", "rmt hitm", 2),
1427 .entry
= mean_rmt_entry
,
1431 static struct c2c_dimension dim_mean_lcl
= {
1432 .header
= HEADER_SPAN_LOW("lcl hitm"),
1435 .entry
= mean_lcl_entry
,
1439 static struct c2c_dimension dim_mean_load
= {
1440 .header
= HEADER_SPAN_LOW("load"),
1441 .name
= "mean_load",
1443 .entry
= mean_load_entry
,
1447 static struct c2c_dimension dim_cpucnt
= {
1448 .header
= HEADER_BOTH("cpu", "cnt"),
1451 .entry
= cpucnt_entry
,
1455 static struct c2c_dimension dim_srcline
= {
1456 .name
= "cl_srcline",
1457 .se
= &sort_srcline
,
1460 static struct c2c_dimension dim_dcacheline_idx
= {
1461 .header
= HEADER_LOW("Index"),
1464 .entry
= cl_idx_entry
,
1468 static struct c2c_dimension dim_dcacheline_num
= {
1469 .header
= HEADER_LOW("Num"),
1472 .entry
= cl_idx_entry
,
1476 static struct c2c_dimension dim_dcacheline_num_empty
= {
1477 .header
= HEADER_LOW("Num"),
1478 .name
= "cl_num_empty",
1480 .entry
= cl_idx_empty_entry
,
1484 static struct c2c_dimension
*dimensions
[] = {
1496 &dim_cl_stores_l1hit
,
1497 &dim_cl_stores_l1miss
,
1507 &dim_percent_rmt_hitm
,
1508 &dim_percent_lcl_hitm
,
1509 &dim_percent_stores_l1hit
,
1510 &dim_percent_stores_l1miss
,
1523 &dim_dcacheline_idx
,
1524 &dim_dcacheline_num
,
1525 &dim_dcacheline_num_empty
,
1529 static void fmt_free(struct perf_hpp_fmt
*fmt
)
1531 struct c2c_fmt
*c2c_fmt
;
1533 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1537 static bool fmt_equal(struct perf_hpp_fmt
*a
, struct perf_hpp_fmt
*b
)
1539 struct c2c_fmt
*c2c_a
= container_of(a
, struct c2c_fmt
, fmt
);
1540 struct c2c_fmt
*c2c_b
= container_of(b
, struct c2c_fmt
, fmt
);
1542 return c2c_a
->dim
== c2c_b
->dim
;
1545 static struct c2c_dimension
*get_dimension(const char *name
)
1549 for (i
= 0; dimensions
[i
]; i
++) {
1550 struct c2c_dimension
*dim
= dimensions
[i
];
1552 if (!strcmp(dim
->name
, name
))
1559 static int c2c_se_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1560 struct hist_entry
*he
)
1562 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1563 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1564 size_t len
= fmt
->user_len
;
1567 len
= hists__col_len(he
->hists
, dim
->se
->se_width_idx
);
1569 return dim
->se
->se_snprintf(he
, hpp
->buf
, hpp
->size
, len
);
1572 static int64_t c2c_se_cmp(struct perf_hpp_fmt
*fmt
,
1573 struct hist_entry
*a
, struct hist_entry
*b
)
1575 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1576 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1578 return dim
->se
->se_cmp(a
, b
);
1581 static int64_t c2c_se_collapse(struct perf_hpp_fmt
*fmt
,
1582 struct hist_entry
*a
, struct hist_entry
*b
)
1584 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1585 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1586 int64_t (*collapse_fn
)(struct hist_entry
*, struct hist_entry
*);
1588 collapse_fn
= dim
->se
->se_collapse
?: dim
->se
->se_cmp
;
1589 return collapse_fn(a
, b
);
1592 static struct c2c_fmt
*get_format(const char *name
)
1594 struct c2c_dimension
*dim
= get_dimension(name
);
1595 struct c2c_fmt
*c2c_fmt
;
1596 struct perf_hpp_fmt
*fmt
;
1601 c2c_fmt
= zalloc(sizeof(*c2c_fmt
));
1607 fmt
= &c2c_fmt
->fmt
;
1608 INIT_LIST_HEAD(&fmt
->list
);
1609 INIT_LIST_HEAD(&fmt
->sort_list
);
1611 fmt
->cmp
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1612 fmt
->sort
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1613 fmt
->color
= dim
->se
? NULL
: dim
->color
;
1614 fmt
->entry
= dim
->se
? c2c_se_entry
: dim
->entry
;
1615 fmt
->header
= c2c_header
;
1616 fmt
->width
= c2c_width
;
1617 fmt
->collapse
= dim
->se
? c2c_se_collapse
: dim
->cmp
;
1618 fmt
->equal
= fmt_equal
;
1619 fmt
->free
= fmt_free
;
1624 static int c2c_hists__init_output(struct perf_hpp_list
*hpp_list
, char *name
)
1626 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1630 return output_field_add(hpp_list
, name
);
1633 perf_hpp_list__column_register(hpp_list
, &c2c_fmt
->fmt
);
1637 static int c2c_hists__init_sort(struct perf_hpp_list
*hpp_list
, char *name
)
1639 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1640 struct c2c_dimension
*dim
;
1644 return sort_dimension__add(hpp_list
, name
, NULL
, 0);
1648 if (dim
== &dim_dso
)
1651 perf_hpp_list__register_sort_field(hpp_list
, &c2c_fmt
->fmt
);
1655 #define PARSE_LIST(_list, _fn) \
1663 for (tok = strtok_r((char *)_list, ", ", &tmp); \
1664 tok; tok = strtok_r(NULL, ", ", &tmp)) { \
1665 ret = _fn(hpp_list, tok); \
1666 if (ret == -EINVAL) { \
1667 error("Invalid --fields key: `%s'", tok); \
1669 } else if (ret == -ESRCH) { \
1670 error("Unknown --fields key: `%s'", tok); \
1676 static int hpp_list__parse(struct perf_hpp_list
*hpp_list
,
1677 const char *output_
,
1680 char *output
= output_
? strdup(output_
) : NULL
;
1681 char *sort
= sort_
? strdup(sort_
) : NULL
;
1684 PARSE_LIST(output
, c2c_hists__init_output
);
1685 PARSE_LIST(sort
, c2c_hists__init_sort
);
1687 /* copy sort keys to output fields */
1688 perf_hpp__setup_output_field(hpp_list
);
1691 * We dont need other sorting keys other than those
1692 * we already specified. It also really slows down
1693 * the processing a lot with big number of output
1694 * fields, so switching this off for c2c.
1698 /* and then copy output fields to sort keys */
1699 perf_hpp__append_sort_keys(&hists
->list
);
1707 static int c2c_hists__init(struct c2c_hists
*hists
,
1709 int nr_header_lines
)
1711 __hists__init(&hists
->hists
, &hists
->list
);
1714 * Initialize only with sort fields, we need to resort
1715 * later anyway, and that's where we add output fields
1718 perf_hpp_list__init(&hists
->list
);
1720 /* Overload number of header lines.*/
1721 hists
->list
.nr_header_lines
= nr_header_lines
;
1723 return hpp_list__parse(&hists
->list
, NULL
, sort
);
1727 static int c2c_hists__reinit(struct c2c_hists
*c2c_hists
,
1731 perf_hpp__reset_output_field(&c2c_hists
->list
);
1732 return hpp_list__parse(&c2c_hists
->list
, output
, sort
);
1735 #define DISPLAY_LINE_LIMIT 0.0005
1737 static bool he__display(struct hist_entry
*he
, struct c2c_stats
*stats
)
1739 struct c2c_hist_entry
*c2c_he
;
1742 /* XXX Disabled for now, till we get a command line switch to control this */
1745 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1747 #define FILTER_HITM(__h) \
1749 ld_dist = ((double)c2c_he->stats.__h / stats->__h); \
1750 if (ld_dist < DISPLAY_LINE_LIMIT) \
1751 he->filtered = HIST_FILTER__C2C; \
1753 he->filtered = HIST_FILTER__C2C; \
1756 switch (c2c
.display
) {
1758 FILTER_HITM(lcl_hitm
);
1761 FILTER_HITM(rmt_hitm
);
1768 return he
->filtered
== 0;
1771 static inline int valid_hitm_or_store(struct hist_entry
*he
)
1773 struct c2c_hist_entry
*c2c_he
;
1776 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1777 has_hitm
= c2c
.display
== DISPLAY_LCL
?
1778 c2c_he
->stats
.lcl_hitm
: c2c_he
->stats
.rmt_hitm
;
1779 return has_hitm
|| c2c_he
->stats
.store
;
1782 static void calc_width(struct hist_entry
*he
)
1784 struct c2c_hists
*c2c_hists
;
1786 c2c_hists
= container_of(he
->hists
, struct c2c_hists
, hists
);
1787 hists__calc_col_len(&c2c_hists
->hists
, he
);
1790 static int filter_cb(struct hist_entry
*he
)
1792 if (c2c
.show_src
&& !he
->srcline
)
1793 he
->srcline
= hist_entry__get_srcline(he
);
1797 if (!valid_hitm_or_store(he
))
1798 he
->filtered
= HIST_FILTER__C2C
;
1803 static int resort_cl_cb(struct hist_entry
*he
)
1805 struct c2c_hist_entry
*c2c_he
;
1806 struct c2c_hists
*c2c_hists
;
1807 bool display
= he__display(he
, &c2c
.hitm_stats
);
1809 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1810 c2c_hists
= c2c_he
->hists
;
1814 if (display
&& c2c_hists
) {
1815 static unsigned int idx
;
1817 c2c_he
->cacheline_idx
= idx
++;
1819 c2c_hists__reinit(c2c_hists
, c2c
.cl_output
, c2c
.cl_resort
);
1821 hists__collapse_resort(&c2c_hists
->hists
, NULL
);
1822 hists__output_resort_cb(&c2c_hists
->hists
, NULL
, filter_cb
);
1828 static void setup_nodes_header(void)
1830 dim_node
.header
= header_node
[c2c
.node_info
];
1833 static int setup_nodes(struct perf_session
*session
)
1835 struct numa_node
*n
;
1836 unsigned long **nodes
;
1840 if (c2c
.node_info
> 2)
1843 c2c
.nodes_cnt
= session
->header
.env
.nr_numa_nodes
;
1844 c2c
.cpus_cnt
= session
->header
.env
.nr_cpus_online
;
1846 n
= session
->header
.env
.numa_nodes
;
1850 nodes
= zalloc(sizeof(unsigned long *) * c2c
.nodes_cnt
);
1856 cpu2node
= zalloc(sizeof(int) * c2c
.cpus_cnt
);
1860 for (cpu
= 0; cpu
< c2c
.cpus_cnt
; cpu
++)
1863 c2c
.cpu2node
= cpu2node
;
1865 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
1866 struct cpu_map
*map
= n
[node
].map
;
1869 set
= bitmap_alloc(c2c
.cpus_cnt
);
1873 for (cpu
= 0; cpu
< map
->nr
; cpu
++) {
1874 set_bit(map
->map
[cpu
], set
);
1876 if (WARN_ONCE(cpu2node
[map
->map
[cpu
]] != -1, "node/cpu topology bug"))
1879 cpu2node
[map
->map
[cpu
]] = node
;
1885 setup_nodes_header();
1889 #define HAS_HITMS(__h) ((__h)->stats.lcl_hitm || (__h)->stats.rmt_hitm)
1891 static int resort_hitm_cb(struct hist_entry
*he
)
1893 struct c2c_hist_entry
*c2c_he
;
1894 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1896 if (HAS_HITMS(c2c_he
)) {
1897 c2c
.shared_clines
++;
1898 c2c_add_stats(&c2c
.hitm_stats
, &c2c_he
->stats
);
1904 static int hists__iterate_cb(struct hists
*hists
, hists__resort_cb_t cb
)
1906 struct rb_node
*next
= rb_first(&hists
->entries
);
1910 struct hist_entry
*he
;
1912 he
= rb_entry(next
, struct hist_entry
, rb_node
);
1916 next
= rb_next(&he
->rb_node
);
1922 static void print_c2c__display_stats(FILE *out
)
1925 struct c2c_stats
*stats
= &c2c
.hists
.stats
;
1927 llc_misses
= stats
->lcl_dram
+
1932 fprintf(out
, "=================================================\n");
1933 fprintf(out
, " Trace Event Information \n");
1934 fprintf(out
, "=================================================\n");
1935 fprintf(out
, " Total records : %10d\n", stats
->nr_entries
);
1936 fprintf(out
, " Locked Load/Store Operations : %10d\n", stats
->locks
);
1937 fprintf(out
, " Load Operations : %10d\n", stats
->load
);
1938 fprintf(out
, " Loads - uncacheable : %10d\n", stats
->ld_uncache
);
1939 fprintf(out
, " Loads - IO : %10d\n", stats
->ld_io
);
1940 fprintf(out
, " Loads - Miss : %10d\n", stats
->ld_miss
);
1941 fprintf(out
, " Loads - no mapping : %10d\n", stats
->ld_noadrs
);
1942 fprintf(out
, " Load Fill Buffer Hit : %10d\n", stats
->ld_fbhit
);
1943 fprintf(out
, " Load L1D hit : %10d\n", stats
->ld_l1hit
);
1944 fprintf(out
, " Load L2D hit : %10d\n", stats
->ld_l2hit
);
1945 fprintf(out
, " Load LLC hit : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
1946 fprintf(out
, " Load Local HITM : %10d\n", stats
->lcl_hitm
);
1947 fprintf(out
, " Load Remote HITM : %10d\n", stats
->rmt_hitm
);
1948 fprintf(out
, " Load Remote HIT : %10d\n", stats
->rmt_hit
);
1949 fprintf(out
, " Load Local DRAM : %10d\n", stats
->lcl_dram
);
1950 fprintf(out
, " Load Remote DRAM : %10d\n", stats
->rmt_dram
);
1951 fprintf(out
, " Load MESI State Exclusive : %10d\n", stats
->ld_excl
);
1952 fprintf(out
, " Load MESI State Shared : %10d\n", stats
->ld_shared
);
1953 fprintf(out
, " Load LLC Misses : %10d\n", llc_misses
);
1954 fprintf(out
, " LLC Misses to Local DRAM : %10.1f%%\n", ((double)stats
->lcl_dram
/(double)llc_misses
) * 100.);
1955 fprintf(out
, " LLC Misses to Remote DRAM : %10.1f%%\n", ((double)stats
->rmt_dram
/(double)llc_misses
) * 100.);
1956 fprintf(out
, " LLC Misses to Remote cache (HIT) : %10.1f%%\n", ((double)stats
->rmt_hit
/(double)llc_misses
) * 100.);
1957 fprintf(out
, " LLC Misses to Remote cache (HITM) : %10.1f%%\n", ((double)stats
->rmt_hitm
/(double)llc_misses
) * 100.);
1958 fprintf(out
, " Store Operations : %10d\n", stats
->store
);
1959 fprintf(out
, " Store - uncacheable : %10d\n", stats
->st_uncache
);
1960 fprintf(out
, " Store - no mapping : %10d\n", stats
->st_noadrs
);
1961 fprintf(out
, " Store L1D Hit : %10d\n", stats
->st_l1hit
);
1962 fprintf(out
, " Store L1D Miss : %10d\n", stats
->st_l1miss
);
1963 fprintf(out
, " No Page Map Rejects : %10d\n", stats
->nomap
);
1964 fprintf(out
, " Unable to parse data source : %10d\n", stats
->noparse
);
1967 static void print_shared_cacheline_info(FILE *out
)
1969 struct c2c_stats
*stats
= &c2c
.hitm_stats
;
1970 int hitm_cnt
= stats
->lcl_hitm
+ stats
->rmt_hitm
;
1972 fprintf(out
, "=================================================\n");
1973 fprintf(out
, " Global Shared Cache Line Event Information \n");
1974 fprintf(out
, "=================================================\n");
1975 fprintf(out
, " Total Shared Cache Lines : %10d\n", c2c
.shared_clines
);
1976 fprintf(out
, " Load HITs on shared lines : %10d\n", stats
->load
);
1977 fprintf(out
, " Fill Buffer Hits on shared lines : %10d\n", stats
->ld_fbhit
);
1978 fprintf(out
, " L1D hits on shared lines : %10d\n", stats
->ld_l1hit
);
1979 fprintf(out
, " L2D hits on shared lines : %10d\n", stats
->ld_l2hit
);
1980 fprintf(out
, " LLC hits on shared lines : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
1981 fprintf(out
, " Locked Access on shared lines : %10d\n", stats
->locks
);
1982 fprintf(out
, " Store HITs on shared lines : %10d\n", stats
->store
);
1983 fprintf(out
, " Store L1D hits on shared lines : %10d\n", stats
->st_l1hit
);
1984 fprintf(out
, " Total Merged records : %10d\n", hitm_cnt
+ stats
->store
);
1987 static void print_cacheline(struct c2c_hists
*c2c_hists
,
1988 struct hist_entry
*he_cl
,
1989 struct perf_hpp_list
*hpp_list
,
1993 struct perf_hpp hpp
= {
2000 hists__fprintf_headers(&c2c_hists
->hists
, out
);
2006 fprintf(out
, " -------------------------------------------------------------\n");
2007 __hist_entry__snprintf(he_cl
, &hpp
, hpp_list
);
2008 fprintf(out
, "%s\n", bf
);
2009 fprintf(out
, " -------------------------------------------------------------\n");
2011 hists__fprintf(&c2c_hists
->hists
, false, 0, 0, 0, out
, true);
2014 static void print_pareto(FILE *out
)
2016 struct perf_hpp_list hpp_list
;
2020 perf_hpp_list__init(&hpp_list
);
2021 ret
= hpp_list__parse(&hpp_list
,
2030 if (WARN_ONCE(ret
, "failed to setup sort entries\n"))
2033 nd
= rb_first(&c2c
.hists
.hists
.entries
);
2035 for (; nd
; nd
= rb_next(nd
)) {
2036 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2037 struct c2c_hist_entry
*c2c_he
;
2042 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2043 print_cacheline(c2c_he
->hists
, he
, &hpp_list
, out
);
2047 static void print_c2c_info(FILE *out
, struct perf_session
*session
)
2049 struct perf_evlist
*evlist
= session
->evlist
;
2050 struct perf_evsel
*evsel
;
2053 fprintf(out
, "=================================================\n");
2054 fprintf(out
, " c2c details \n");
2055 fprintf(out
, "=================================================\n");
2057 evlist__for_each_entry(evlist
, evsel
) {
2058 fprintf(out
, "%-36s: %s\n", first
? " Events" : "",
2059 perf_evsel__name(evsel
));
2062 fprintf(out
, " Cachelines sort on : %s HITMs\n",
2063 c2c
.display
== DISPLAY_LCL
? "Local" : "Remote");
2064 fprintf(out
, " Cacheline data grouping : %s\n", c2c
.cl_sort
);
2067 static void perf_c2c__hists_fprintf(FILE *out
, struct perf_session
*session
)
2071 print_c2c__display_stats(out
);
2073 print_shared_cacheline_info(out
);
2075 print_c2c_info(out
, session
);
2081 fprintf(out
, "=================================================\n");
2082 fprintf(out
, " Shared Data Cache Line Table \n");
2083 fprintf(out
, "=================================================\n");
2084 fprintf(out
, "#\n");
2086 hists__fprintf(&c2c
.hists
.hists
, true, 0, 0, 0, stdout
, false);
2089 fprintf(out
, "=================================================\n");
2090 fprintf(out
, " Shared Cache Line Distribution Pareto \n");
2091 fprintf(out
, "=================================================\n");
2092 fprintf(out
, "#\n");
2097 #ifdef HAVE_SLANG_SUPPORT
2098 static void c2c_browser__update_nr_entries(struct hist_browser
*hb
)
2101 struct rb_node
*nd
= rb_first(&hb
->hists
->entries
);
2104 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2112 hb
->nr_non_filtered_entries
= nr_entries
;
2115 struct c2c_cacheline_browser
{
2116 struct hist_browser hb
;
2117 struct hist_entry
*he
;
2121 perf_c2c_cacheline_browser__title(struct hist_browser
*browser
,
2122 char *bf
, size_t size
)
2124 struct c2c_cacheline_browser
*cl_browser
;
2125 struct hist_entry
*he
;
2128 cl_browser
= container_of(browser
, struct c2c_cacheline_browser
, hb
);
2129 he
= cl_browser
->he
;
2132 addr
= cl_address(he
->mem_info
->daddr
.addr
);
2134 scnprintf(bf
, size
, "Cacheline 0x%lx", addr
);
2138 static struct c2c_cacheline_browser
*
2139 c2c_cacheline_browser__new(struct hists
*hists
, struct hist_entry
*he
)
2141 struct c2c_cacheline_browser
*browser
;
2143 browser
= zalloc(sizeof(*browser
));
2145 hist_browser__init(&browser
->hb
, hists
);
2146 browser
->hb
.c2c_filter
= true;
2147 browser
->hb
.title
= perf_c2c_cacheline_browser__title
;
2154 static int perf_c2c__browse_cacheline(struct hist_entry
*he
)
2156 struct c2c_hist_entry
*c2c_he
;
2157 struct c2c_hists
*c2c_hists
;
2158 struct c2c_cacheline_browser
*cl_browser
;
2159 struct hist_browser
*browser
;
2162 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2163 c2c_hists
= c2c_he
->hists
;
2165 cl_browser
= c2c_cacheline_browser__new(&c2c_hists
->hists
, he
);
2166 if (cl_browser
== NULL
)
2169 browser
= &cl_browser
->hb
;
2171 /* reset abort key so that it can get Ctrl-C as a key */
2173 SLang_init_tty(0, 0, 0);
2175 c2c_browser__update_nr_entries(browser
);
2178 key
= hist_browser__run(browser
, "help");
2193 static int perf_c2c_browser__title(struct hist_browser
*browser
,
2194 char *bf
, size_t size
)
2197 "Shared Data Cache Line Table "
2198 "(%lu entries, sorted on %s HITMs)",
2199 browser
->nr_non_filtered_entries
,
2200 c2c
.display
== DISPLAY_LCL
? "local" : "remote");
2204 static struct hist_browser
*
2205 perf_c2c_browser__new(struct hists
*hists
)
2207 struct hist_browser
*browser
= hist_browser__new(hists
);
2210 browser
->title
= perf_c2c_browser__title
;
2211 browser
->c2c_filter
= true;
2217 static int perf_c2c__hists_browse(struct hists
*hists
)
2219 struct hist_browser
*browser
;
2222 browser
= perf_c2c_browser__new(hists
);
2223 if (browser
== NULL
)
2226 /* reset abort key so that it can get Ctrl-C as a key */
2228 SLang_init_tty(0, 0, 0);
2230 c2c_browser__update_nr_entries(browser
);
2233 key
= hist_browser__run(browser
, "help");
2239 perf_c2c__browse_cacheline(browser
->he_selection
);
2247 hist_browser__delete(browser
);
2251 static void perf_c2c_display(struct perf_session
*session
)
2254 perf_c2c__hists_fprintf(stdout
, session
);
2256 perf_c2c__hists_browse(&c2c
.hists
.hists
);
2259 static void perf_c2c_display(struct perf_session
*session
)
2262 perf_c2c__hists_fprintf(stdout
, session
);
2264 #endif /* HAVE_SLANG_SUPPORT */
2266 static void ui_quirks(void)
2268 if (!c2c
.use_stdio
) {
2269 dim_offset
.width
= 5;
2270 dim_offset
.header
= header_offset_tui
;
2273 dim_percent_hitm
.header
= percent_hitm_header
[c2c
.display
];
2276 #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
2278 const char callchain_help
[] = "Display call graph (stack chain/backtrace):\n\n"
2279 CALLCHAIN_REPORT_HELP
2280 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT
;
2283 parse_callchain_opt(const struct option
*opt
, const char *arg
, int unset
)
2285 struct callchain_param
*callchain
= opt
->value
;
2287 callchain
->enabled
= !unset
;
2292 symbol_conf
.use_callchain
= false;
2293 callchain
->mode
= CHAIN_NONE
;
2297 return parse_callchain_report_opt(arg
);
2300 static int setup_callchain(struct perf_evlist
*evlist
)
2302 u64 sample_type
= perf_evlist__combined_sample_type(evlist
);
2303 enum perf_call_graph_mode mode
= CALLCHAIN_NONE
;
2305 if ((sample_type
& PERF_SAMPLE_REGS_USER
) &&
2306 (sample_type
& PERF_SAMPLE_STACK_USER
))
2307 mode
= CALLCHAIN_DWARF
;
2308 else if (sample_type
& PERF_SAMPLE_BRANCH_STACK
)
2309 mode
= CALLCHAIN_LBR
;
2310 else if (sample_type
& PERF_SAMPLE_CALLCHAIN
)
2311 mode
= CALLCHAIN_FP
;
2313 if (!callchain_param
.enabled
&&
2314 callchain_param
.mode
!= CHAIN_NONE
&&
2315 mode
!= CALLCHAIN_NONE
) {
2316 symbol_conf
.use_callchain
= true;
2317 if (callchain_register_param(&callchain_param
) < 0) {
2318 ui__error("Can't register callchain params.\n");
2323 callchain_param
.record_mode
= mode
;
2324 callchain_param
.min_percent
= 0;
2328 static int setup_display(const char *str
)
2330 const char *display
= str
?: "rmt";
2332 if (!strcmp(display
, "rmt"))
2333 c2c
.display
= DISPLAY_RMT
;
2334 else if (!strcmp(display
, "lcl"))
2335 c2c
.display
= DISPLAY_LCL
;
2337 pr_err("failed: unknown display type: %s\n", str
);
2344 #define for_each_token(__tok, __buf, __sep, __tmp) \
2345 for (__tok = strtok_r(__buf, __sep, &__tmp); __tok; \
2346 __tok = strtok_r(NULL, __sep, &__tmp))
2348 static int build_cl_output(char *cl_sort
)
2350 char *tok
, *tmp
, *buf
= strdup(cl_sort
);
2351 bool add_pid
= false;
2352 bool add_tid
= false;
2353 bool add_iaddr
= false;
2354 bool add_sym
= false;
2355 bool add_dso
= false;
2356 bool add_src
= false;
2361 for_each_token(tok
, buf
, ",", tmp
) {
2362 if (!strcmp(tok
, "tid")) {
2364 } else if (!strcmp(tok
, "pid")) {
2366 } else if (!strcmp(tok
, "iaddr")) {
2371 } else if (!strcmp(tok
, "dso")) {
2373 } else if (strcmp(tok
, "offset")) {
2374 pr_err("unrecognized sort token: %s\n", tok
);
2379 if (asprintf(&c2c
.cl_output
,
2380 "%s%s%s%s%s%s%s%s%s%s",
2381 c2c
.use_stdio
? "cl_num_empty," : "",
2384 "percent_stores_l1hit,"
2385 "percent_stores_l1miss,"
2387 add_pid
? "pid," : "",
2388 add_tid
? "tid," : "",
2389 add_iaddr
? "iaddr," : "",
2394 add_sym
? "symbol," : "",
2395 add_dso
? "dso," : "",
2396 add_src
? "cl_srcline," : "",
2400 c2c
.show_src
= add_src
;
2406 static int setup_coalesce(const char *coalesce
)
2408 const char *c
= coalesce
?: coalesce_default
;
2410 if (asprintf(&c2c
.cl_sort
, "offset,%s", c
) < 0)
2413 if (build_cl_output(c2c
.cl_sort
))
2416 if (asprintf(&c2c
.cl_resort
, "offset,%s",
2417 c2c
.display
== DISPLAY_RMT
?
2418 "rmt_hitm,lcl_hitm" :
2419 "lcl_hitm,rmt_hitm") < 0)
2422 pr_debug("coalesce sort fields: %s\n", c2c
.cl_sort
);
2423 pr_debug("coalesce resort fields: %s\n", c2c
.cl_resort
);
2424 pr_debug("coalesce output fields: %s\n", c2c
.cl_output
);
2428 static int perf_c2c__report(int argc
, const char **argv
)
2430 struct perf_session
*session
;
2431 struct ui_progress prog
;
2432 struct perf_data_file file
= {
2433 .mode
= PERF_DATA_MODE_READ
,
2435 char callchain_default_opt
[] = CALLCHAIN_DEFAULT_OPT
;
2436 const char *display
= NULL
;
2437 const char *coalesce
= NULL
;
2438 const struct option c2c_options
[] = {
2439 OPT_STRING('k', "vmlinux", &symbol_conf
.vmlinux_name
,
2440 "file", "vmlinux pathname"),
2441 OPT_INCR('v', "verbose", &verbose
,
2442 "be more verbose (show counter open errors, etc)"),
2443 OPT_STRING('i', "input", &input_name
, "file",
2444 "the input file to process"),
2445 OPT_INCR('N', "node-info", &c2c
.node_info
,
2446 "show extra node info in report (repeat for more info)"),
2447 #ifdef HAVE_SLANG_SUPPORT
2448 OPT_BOOLEAN(0, "stdio", &c2c
.use_stdio
, "Use the stdio interface"),
2450 OPT_BOOLEAN(0, "stats", &c2c
.stats_only
,
2451 "Use the stdio interface"),
2452 OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param
,
2453 "print_type,threshold[,print_limit],order,sort_key[,branch],value",
2454 callchain_help
, &parse_callchain_opt
,
2455 callchain_default_opt
),
2456 OPT_STRING('d', "display", &display
, NULL
, "lcl,rmt"),
2457 OPT_STRING('c', "coalesce", &coalesce
, "coalesce fields",
2458 "coalesce fields: pid,tid,iaddr,dso"),
2463 argc
= parse_options(argc
, argv
, c2c_options
, report_c2c_usage
,
2464 PARSE_OPT_STOP_AT_NON_OPTION
);
2466 usage_with_options(report_c2c_usage
, c2c_options
);
2469 c2c
.use_stdio
= true;
2476 setup_browser(false);
2478 if (!input_name
|| !strlen(input_name
))
2479 input_name
= "perf.data";
2481 file
.path
= input_name
;
2483 err
= setup_display(display
);
2487 err
= setup_coalesce(coalesce
);
2489 pr_debug("Failed to initialize hists\n");
2493 err
= c2c_hists__init(&c2c
.hists
, "dcacheline", 2);
2495 pr_debug("Failed to initialize hists\n");
2499 session
= perf_session__new(&file
, 0, &c2c
.tool
);
2500 if (session
== NULL
) {
2501 pr_debug("No memory for session\n");
2504 err
= setup_nodes(session
);
2506 pr_err("Failed setup nodes\n");
2510 err
= setup_callchain(session
->evlist
);
2514 if (symbol__init(&session
->header
.env
) < 0)
2517 /* No pipe support at the moment. */
2518 if (perf_data_file__is_pipe(session
->file
)) {
2519 pr_debug("No pipe support at the moment.\n");
2523 err
= perf_session__process_events(session
);
2525 pr_err("failed to process sample\n");
2529 c2c_hists__reinit(&c2c
.hists
,
2534 "tot_hitm,lcl_hitm,rmt_hitm,"
2535 "stores,stores_l1hit,stores_l1miss,"
2536 "dram_lcl,dram_rmt,"
2539 "ld_fbhit,ld_l1hit,ld_l2hit,"
2540 "ld_lclhit,ld_rmthit",
2541 c2c
.display
== DISPLAY_LCL
? "lcl_hitm" : "rmt_hitm"
2544 ui_progress__init(&prog
, c2c
.hists
.hists
.nr_entries
, "Sorting...");
2546 hists__collapse_resort(&c2c
.hists
.hists
, NULL
);
2547 hists__output_resort_cb(&c2c
.hists
.hists
, &prog
, resort_hitm_cb
);
2548 hists__iterate_cb(&c2c
.hists
.hists
, resort_cl_cb
);
2550 ui_progress__finish();
2554 perf_c2c_display(session
);
2557 perf_session__delete(session
);
2562 static int parse_record_events(const struct option
*opt __maybe_unused
,
2563 const char *str
, int unset __maybe_unused
)
2565 bool *event_set
= (bool *) opt
->value
;
2568 return perf_mem_events__parse(str
);
2572 static const char * const __usage_record
[] = {
2573 "perf c2c record [<options>] [<command>]",
2574 "perf c2c record [<options>] -- <command> [<options>]",
2578 static const char * const *record_mem_usage
= __usage_record
;
2580 static int perf_c2c__record(int argc
, const char **argv
)
2582 int rec_argc
, i
= 0, j
;
2583 const char **rec_argv
;
2585 bool all_user
= false, all_kernel
= false;
2586 bool event_set
= false;
2587 struct option options
[] = {
2588 OPT_CALLBACK('e', "event", &event_set
, "event",
2589 "event selector. Use 'perf mem record -e list' to list available events",
2590 parse_record_events
),
2591 OPT_INCR('v', "verbose", &verbose
,
2592 "be more verbose (show counter open errors, etc)"),
2593 OPT_BOOLEAN('u', "all-user", &all_user
, "collect only user level data"),
2594 OPT_BOOLEAN('k', "all-kernel", &all_kernel
, "collect only kernel level data"),
2595 OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat
, "setup mem-loads latency"),
2599 if (perf_mem_events__init()) {
2600 pr_err("failed: memory events not supported\n");
2604 argc
= parse_options(argc
, argv
, options
, record_mem_usage
,
2605 PARSE_OPT_KEEP_UNKNOWN
);
2607 rec_argc
= argc
+ 10; /* max number of arguments */
2608 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
2612 rec_argv
[i
++] = "record";
2615 perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
= true;
2616 perf_mem_events
[PERF_MEM_EVENTS__STORE
].record
= true;
2619 if (perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
)
2620 rec_argv
[i
++] = "-W";
2622 rec_argv
[i
++] = "-d";
2623 rec_argv
[i
++] = "--sample-cpu";
2625 for (j
= 0; j
< PERF_MEM_EVENTS__MAX
; j
++) {
2626 if (!perf_mem_events
[j
].record
)
2629 if (!perf_mem_events
[j
].supported
) {
2630 pr_err("failed: event '%s' not supported\n",
2631 perf_mem_events
[j
].name
);
2635 rec_argv
[i
++] = "-e";
2636 rec_argv
[i
++] = perf_mem_events__name(j
);
2640 rec_argv
[i
++] = "--all-user";
2643 rec_argv
[i
++] = "--all-kernel";
2645 for (j
= 0; j
< argc
; j
++, i
++)
2646 rec_argv
[i
] = argv
[j
];
2649 pr_debug("calling: ");
2653 while (rec_argv
[j
]) {
2654 pr_debug("%s ", rec_argv
[j
]);
2660 ret
= cmd_record(i
, rec_argv
, NULL
);
2665 int cmd_c2c(int argc
, const char **argv
, const char *prefix __maybe_unused
)
2667 const struct option c2c_options
[] = {
2668 OPT_INCR('v', "verbose", &verbose
, "be more verbose"),
2672 argc
= parse_options(argc
, argv
, c2c_options
, c2c_usage
,
2673 PARSE_OPT_STOP_AT_NON_OPTION
);
2676 usage_with_options(c2c_usage
, c2c_options
);
2678 if (!strncmp(argv
[0], "rec", 3)) {
2679 return perf_c2c__record(argc
, argv
);
2680 } else if (!strncmp(argv
[0], "rep", 3)) {
2681 return perf_c2c__report(argc
, argv
);
2683 usage_with_options(c2c_usage
, c2c_options
);