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
;
67 /* HITM shared clines stats */
68 struct c2c_stats hitm_stats
;
84 static struct perf_c2c c2c
;
86 static void *c2c_he_zalloc(size_t size
)
88 struct c2c_hist_entry
*c2c_he
;
90 c2c_he
= zalloc(size
+ sizeof(*c2c_he
));
94 c2c_he
->cpuset
= bitmap_alloc(c2c
.cpus_cnt
);
98 c2c_he
->node_stats
= zalloc(c2c
.nodes_cnt
* sizeof(*c2c_he
->node_stats
));
99 if (!c2c_he
->node_stats
)
102 init_stats(&c2c_he
->cstats
.lcl_hitm
);
103 init_stats(&c2c_he
->cstats
.rmt_hitm
);
104 init_stats(&c2c_he
->cstats
.load
);
109 static void c2c_he_free(void *he
)
111 struct c2c_hist_entry
*c2c_he
;
113 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
115 hists__delete_entries(&c2c_he
->hists
->hists
);
119 free(c2c_he
->cpuset
);
120 free(c2c_he
->node_stats
);
124 static struct hist_entry_ops c2c_entry_ops
= {
125 .new = c2c_he_zalloc
,
129 static int c2c_hists__init(struct c2c_hists
*hists
,
131 int nr_header_lines
);
133 static struct c2c_hists
*
134 he__get_c2c_hists(struct hist_entry
*he
,
138 struct c2c_hist_entry
*c2c_he
;
139 struct c2c_hists
*hists
;
142 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
144 return c2c_he
->hists
;
146 hists
= c2c_he
->hists
= zalloc(sizeof(*hists
));
150 ret
= c2c_hists__init(hists
, sort
, nr_header_lines
);
159 static void c2c_he__set_cpu(struct c2c_hist_entry
*c2c_he
,
160 struct perf_sample
*sample
)
162 if (WARN_ONCE(sample
->cpu
== (unsigned int) -1,
163 "WARNING: no sample cpu value"))
166 set_bit(sample
->cpu
, c2c_he
->cpuset
);
169 static void compute_stats(struct c2c_hist_entry
*c2c_he
,
170 struct c2c_stats
*stats
,
173 struct compute_stats
*cstats
= &c2c_he
->cstats
;
176 update_stats(&cstats
->rmt_hitm
, weight
);
177 else if (stats
->lcl_hitm
)
178 update_stats(&cstats
->lcl_hitm
, weight
);
179 else if (stats
->load
)
180 update_stats(&cstats
->load
, weight
);
183 static int process_sample_event(struct perf_tool
*tool __maybe_unused
,
184 union perf_event
*event
,
185 struct perf_sample
*sample
,
186 struct perf_evsel
*evsel __maybe_unused
,
187 struct machine
*machine
)
189 struct c2c_hists
*c2c_hists
= &c2c
.hists
;
190 struct c2c_hist_entry
*c2c_he
;
191 struct c2c_stats stats
= { .nr_entries
= 0, };
192 struct hist_entry
*he
;
193 struct addr_location al
;
194 struct mem_info
*mi
, *mi_dup
;
197 if (machine__resolve(machine
, &al
, sample
) < 0) {
198 pr_debug("problem processing %d event, skipping it.\n",
203 ret
= sample__resolve_callchain(sample
, &callchain_cursor
, NULL
,
204 evsel
, &al
, sysctl_perf_event_max_stack
);
208 mi
= sample__resolve_mem(sample
, &al
);
212 mi_dup
= memdup(mi
, sizeof(*mi
));
216 c2c_decode_stats(&stats
, mi
);
218 he
= hists__add_entry_ops(&c2c_hists
->hists
, &c2c_entry_ops
,
224 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
225 c2c_add_stats(&c2c_he
->stats
, &stats
);
226 c2c_add_stats(&c2c_hists
->stats
, &stats
);
228 c2c_he__set_cpu(c2c_he
, sample
);
230 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
231 ret
= hist_entry__append_callchain(he
, sample
);
235 * There's already been warning about missing
236 * sample's cpu value. Let's account all to
237 * node 0 in this case, without any further
240 * Doing node stats only for single callchain data.
242 int cpu
= sample
->cpu
== (unsigned int) -1 ? 0 : sample
->cpu
;
243 int node
= c2c
.cpu2node
[cpu
];
247 mi_dup
= memdup(mi
, sizeof(*mi
));
251 c2c_hists
= he__get_c2c_hists(he
, c2c
.cl_sort
, 2);
255 he
= hists__add_entry_ops(&c2c_hists
->hists
, &c2c_entry_ops
,
261 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
262 c2c_add_stats(&c2c_he
->stats
, &stats
);
263 c2c_add_stats(&c2c_hists
->stats
, &stats
);
264 c2c_add_stats(&c2c_he
->node_stats
[node
], &stats
);
266 compute_stats(c2c_he
, &stats
, sample
->weight
);
268 c2c_he__set_cpu(c2c_he
, sample
);
270 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
271 ret
= hist_entry__append_callchain(he
, sample
);
275 addr_location__put(&al
);
286 static struct perf_c2c c2c
= {
288 .sample
= process_sample_event
,
289 .mmap
= perf_event__process_mmap
,
290 .mmap2
= perf_event__process_mmap2
,
291 .comm
= perf_event__process_comm
,
292 .exit
= perf_event__process_exit
,
293 .fork
= perf_event__process_fork
,
294 .lost
= perf_event__process_lost
,
295 .ordered_events
= true,
296 .ordering_requires_timestamps
= true,
300 static const char * const c2c_usage
[] = {
301 "perf c2c {record|report}",
305 static const char * const __usage_report
[] = {
310 static const char * const *report_c2c_usage
= __usage_report
;
312 #define C2C_HEADER_MAX 2
318 } line
[C2C_HEADER_MAX
];
321 struct c2c_dimension
{
322 struct c2c_header header
;
325 struct sort_entry
*se
;
327 int64_t (*cmp
)(struct perf_hpp_fmt
*fmt
,
328 struct hist_entry
*, struct hist_entry
*);
329 int (*entry
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
330 struct hist_entry
*he
);
331 int (*color
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
332 struct hist_entry
*he
);
336 struct perf_hpp_fmt fmt
;
337 struct c2c_dimension
*dim
;
340 #define SYMBOL_WIDTH 30
342 static struct c2c_dimension dim_symbol
;
343 static struct c2c_dimension dim_srcline
;
345 static int symbol_width(struct hists
*hists
, struct sort_entry
*se
)
347 int width
= hists__col_len(hists
, se
->se_width_idx
);
349 if (!c2c
.symbol_full
)
350 width
= MIN(width
, SYMBOL_WIDTH
);
355 static int c2c_width(struct perf_hpp_fmt
*fmt
,
356 struct perf_hpp
*hpp __maybe_unused
,
357 struct hists
*hists __maybe_unused
)
359 struct c2c_fmt
*c2c_fmt
;
360 struct c2c_dimension
*dim
;
362 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
365 if (dim
== &dim_symbol
|| dim
== &dim_srcline
)
366 return symbol_width(hists
, dim
->se
);
368 return dim
->se
? hists__col_len(hists
, dim
->se
->se_width_idx
) :
372 static int c2c_header(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
373 struct hists
*hists
, int line
, int *span
)
375 struct perf_hpp_list
*hpp_list
= hists
->hpp_list
;
376 struct c2c_fmt
*c2c_fmt
;
377 struct c2c_dimension
*dim
;
378 const char *text
= NULL
;
379 int width
= c2c_width(fmt
, hpp
, hists
);
381 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
385 text
= dim
->header
.line
[line
].text
;
386 /* Use the last line from sort_entry if not defined. */
387 if (!text
&& (line
== hpp_list
->nr_header_lines
- 1))
388 text
= dim
->se
->se_header
;
390 text
= dim
->header
.line
[line
].text
;
396 *span
= dim
->header
.line
[line
].span
;
403 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, text
);
406 #define HEX_STR(__s, __v) \
408 scnprintf(__s, sizeof(__s), "0x%" PRIx64, __v); \
413 dcacheline_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
414 struct hist_entry
*left
, struct hist_entry
*right
)
416 return sort__dcacheline_cmp(left
, right
);
419 static int dcacheline_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
420 struct hist_entry
*he
)
423 int width
= c2c_width(fmt
, hpp
, he
->hists
);
427 addr
= cl_address(he
->mem_info
->daddr
.addr
);
429 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
432 static int offset_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
433 struct hist_entry
*he
)
436 int width
= c2c_width(fmt
, hpp
, he
->hists
);
440 addr
= cl_offset(he
->mem_info
->daddr
.al_addr
);
442 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
446 offset_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
447 struct hist_entry
*left
, struct hist_entry
*right
)
449 uint64_t l
= 0, r
= 0;
452 l
= cl_offset(left
->mem_info
->daddr
.addr
);
454 r
= cl_offset(right
->mem_info
->daddr
.addr
);
456 return (int64_t)(r
- l
);
460 iaddr_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
461 struct hist_entry
*he
)
464 int width
= c2c_width(fmt
, hpp
, he
->hists
);
468 addr
= he
->mem_info
->iaddr
.addr
;
470 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
474 iaddr_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
475 struct hist_entry
*left
, struct hist_entry
*right
)
477 return sort__iaddr_cmp(left
, right
);
481 tot_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
482 struct hist_entry
*he
)
484 struct c2c_hist_entry
*c2c_he
;
485 int width
= c2c_width(fmt
, hpp
, he
->hists
);
486 unsigned int tot_hitm
;
488 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
489 tot_hitm
= c2c_he
->stats
.lcl_hitm
+ c2c_he
->stats
.rmt_hitm
;
491 return scnprintf(hpp
->buf
, hpp
->size
, "%*u", width
, tot_hitm
);
495 tot_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
496 struct hist_entry
*left
, struct hist_entry
*right
)
498 struct c2c_hist_entry
*c2c_left
;
499 struct c2c_hist_entry
*c2c_right
;
500 unsigned int tot_hitm_left
;
501 unsigned int tot_hitm_right
;
503 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
504 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
506 tot_hitm_left
= c2c_left
->stats
.lcl_hitm
+ c2c_left
->stats
.rmt_hitm
;
507 tot_hitm_right
= c2c_right
->stats
.lcl_hitm
+ c2c_right
->stats
.rmt_hitm
;
509 return tot_hitm_left
- tot_hitm_right
;
512 #define STAT_FN_ENTRY(__f) \
514 __f ## _entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, \
515 struct hist_entry *he) \
517 struct c2c_hist_entry *c2c_he; \
518 int width = c2c_width(fmt, hpp, he->hists); \
520 c2c_he = container_of(he, struct c2c_hist_entry, he); \
521 return scnprintf(hpp->buf, hpp->size, "%*u", width, \
522 c2c_he->stats.__f); \
525 #define STAT_FN_CMP(__f) \
527 __f ## _cmp(struct perf_hpp_fmt *fmt __maybe_unused, \
528 struct hist_entry *left, struct hist_entry *right) \
530 struct c2c_hist_entry *c2c_left, *c2c_right; \
532 c2c_left = container_of(left, struct c2c_hist_entry, he); \
533 c2c_right = container_of(right, struct c2c_hist_entry, he); \
534 return c2c_left->stats.__f - c2c_right->stats.__f; \
537 #define STAT_FN(__f) \
552 static uint64_t llc_miss(struct c2c_stats
*stats
)
556 llcmiss
= stats
->lcl_dram
+
565 ld_llcmiss_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
);
571 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
573 return scnprintf(hpp
->buf
, hpp
->size
, "%*lu", width
,
574 llc_miss(&c2c_he
->stats
));
578 ld_llcmiss_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
579 struct hist_entry
*left
, struct hist_entry
*right
)
581 struct c2c_hist_entry
*c2c_left
;
582 struct c2c_hist_entry
*c2c_right
;
584 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
585 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
587 return llc_miss(&c2c_left
->stats
) - llc_miss(&c2c_right
->stats
);
590 static uint64_t total_records(struct c2c_stats
*stats
)
592 uint64_t lclmiss
, ldcnt
, total
;
594 lclmiss
= stats
->lcl_dram
+
614 tot_recs_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
615 struct hist_entry
*he
)
617 struct c2c_hist_entry
*c2c_he
;
618 int width
= c2c_width(fmt
, hpp
, he
->hists
);
621 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
622 tot_recs
= total_records(&c2c_he
->stats
);
624 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
628 tot_recs_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
629 struct hist_entry
*left
, struct hist_entry
*right
)
631 struct c2c_hist_entry
*c2c_left
;
632 struct c2c_hist_entry
*c2c_right
;
633 uint64_t tot_recs_left
;
634 uint64_t tot_recs_right
;
636 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
637 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
639 tot_recs_left
= total_records(&c2c_left
->stats
);
640 tot_recs_right
= total_records(&c2c_right
->stats
);
642 return tot_recs_left
- tot_recs_right
;
645 static uint64_t total_loads(struct c2c_stats
*stats
)
647 uint64_t lclmiss
, ldcnt
;
649 lclmiss
= stats
->lcl_dram
+
665 tot_loads_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
666 struct hist_entry
*he
)
668 struct c2c_hist_entry
*c2c_he
;
669 int width
= c2c_width(fmt
, hpp
, he
->hists
);
672 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
673 tot_recs
= total_loads(&c2c_he
->stats
);
675 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
679 tot_loads_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
680 struct hist_entry
*left
, struct hist_entry
*right
)
682 struct c2c_hist_entry
*c2c_left
;
683 struct c2c_hist_entry
*c2c_right
;
684 uint64_t tot_recs_left
;
685 uint64_t tot_recs_right
;
687 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
688 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
690 tot_recs_left
= total_loads(&c2c_left
->stats
);
691 tot_recs_right
= total_loads(&c2c_right
->stats
);
693 return tot_recs_left
- tot_recs_right
;
696 typedef double (get_percent_cb
)(struct c2c_hist_entry
*);
699 percent_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
700 struct hist_entry
*he
, get_percent_cb get_percent
)
702 struct c2c_hist_entry
*c2c_he
;
703 int width
= c2c_width(fmt
, hpp
, he
->hists
);
706 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
707 per
= get_percent(c2c_he
);
709 #ifdef HAVE_SLANG_SUPPORT
711 return __hpp__slsmg_color_printf(hpp
, "%*.2f%%", width
- 1, per
);
713 return hpp_color_scnprintf(hpp
, "%*.2f%%", width
- 1, per
);
716 static double percent_hitm(struct c2c_hist_entry
*c2c_he
)
718 struct c2c_hists
*hists
;
719 struct c2c_stats
*stats
;
720 struct c2c_stats
*total
;
724 hists
= container_of(c2c_he
->he
.hists
, struct c2c_hists
, hists
);
725 stats
= &c2c_he
->stats
;
726 total
= &hists
->stats
;
728 switch (c2c
.display
) {
730 st
= stats
->rmt_hitm
;
731 tot
= total
->rmt_hitm
;
734 st
= stats
->lcl_hitm
;
735 tot
= total
->lcl_hitm
;
740 p
= tot
? (double) st
/ tot
: 0;
745 #define PERC_STR(__s, __v) \
747 scnprintf(__s, sizeof(__s), "%.2F%%", __v); \
752 percent_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
753 struct hist_entry
*he
)
755 struct c2c_hist_entry
*c2c_he
;
756 int width
= c2c_width(fmt
, hpp
, he
->hists
);
760 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
761 per
= percent_hitm(c2c_he
);
762 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
766 percent_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
767 struct hist_entry
*he
)
769 return percent_color(fmt
, hpp
, he
, percent_hitm
);
773 percent_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
774 struct hist_entry
*left
, struct hist_entry
*right
)
776 struct c2c_hist_entry
*c2c_left
;
777 struct c2c_hist_entry
*c2c_right
;
781 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
782 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
784 per_left
= percent_hitm(c2c_left
);
785 per_right
= percent_hitm(c2c_right
);
787 return per_left
- per_right
;
790 static struct c2c_stats
*he_stats(struct hist_entry
*he
)
792 struct c2c_hist_entry
*c2c_he
;
794 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
795 return &c2c_he
->stats
;
798 static struct c2c_stats
*total_stats(struct hist_entry
*he
)
800 struct c2c_hists
*hists
;
802 hists
= container_of(he
->hists
, struct c2c_hists
, hists
);
803 return &hists
->stats
;
806 static double percent(int st
, int tot
)
808 return tot
? 100. * (double) st
/ (double) tot
: 0;
811 #define PERCENT(__h, __f) percent(he_stats(__h)->__f, total_stats(__h)->__f)
813 #define PERCENT_FN(__f) \
814 static double percent_ ## __f(struct c2c_hist_entry *c2c_he) \
816 struct c2c_hists *hists; \
818 hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); \
819 return percent(c2c_he->stats.__f, hists->stats.__f); \
825 PERCENT_FN(st_l1miss
)
828 percent_rmt_hitm_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
, rmt_hitm
);
835 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
839 percent_rmt_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
840 struct hist_entry
*he
)
842 return percent_color(fmt
, hpp
, he
, percent_rmt_hitm
);
846 percent_rmt_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
847 struct hist_entry
*left
, struct hist_entry
*right
)
852 per_left
= PERCENT(left
, lcl_hitm
);
853 per_right
= PERCENT(right
, lcl_hitm
);
855 return per_left
- per_right
;
859 percent_lcl_hitm_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
, lcl_hitm
);
866 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
870 percent_lcl_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
871 struct hist_entry
*he
)
873 return percent_color(fmt
, hpp
, he
, percent_lcl_hitm
);
877 percent_lcl_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
878 struct hist_entry
*left
, struct hist_entry
*right
)
883 per_left
= PERCENT(left
, lcl_hitm
);
884 per_right
= PERCENT(right
, lcl_hitm
);
886 return per_left
- per_right
;
890 percent_stores_l1hit_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
891 struct hist_entry
*he
)
893 int width
= c2c_width(fmt
, hpp
, he
->hists
);
894 double per
= PERCENT(he
, st_l1hit
);
897 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
901 percent_stores_l1hit_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
902 struct hist_entry
*he
)
904 return percent_color(fmt
, hpp
, he
, percent_st_l1hit
);
908 percent_stores_l1hit_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
909 struct hist_entry
*left
, struct hist_entry
*right
)
914 per_left
= PERCENT(left
, st_l1hit
);
915 per_right
= PERCENT(right
, st_l1hit
);
917 return per_left
- per_right
;
921 percent_stores_l1miss_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
922 struct hist_entry
*he
)
924 int width
= c2c_width(fmt
, hpp
, he
->hists
);
925 double per
= PERCENT(he
, st_l1miss
);
928 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
932 percent_stores_l1miss_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
933 struct hist_entry
*he
)
935 return percent_color(fmt
, hpp
, he
, percent_st_l1miss
);
939 percent_stores_l1miss_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
940 struct hist_entry
*left
, struct hist_entry
*right
)
945 per_left
= PERCENT(left
, st_l1miss
);
946 per_right
= PERCENT(right
, st_l1miss
);
948 return per_left
- per_right
;
955 pid_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
956 struct hist_entry
*he
)
958 int width
= c2c_width(fmt
, hpp
, he
->hists
);
960 return scnprintf(hpp
->buf
, hpp
->size
, "%*d", width
, he
->thread
->pid_
);
964 pid_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
965 struct hist_entry
*left
, struct hist_entry
*right
)
967 return left
->thread
->pid_
- right
->thread
->pid_
;
971 empty_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
972 struct hist_entry
*left __maybe_unused
,
973 struct hist_entry
*right __maybe_unused
)
979 node_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
980 struct hist_entry
*he
)
982 struct c2c_hist_entry
*c2c_he
;
987 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
989 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
990 DECLARE_BITMAP(set
, c2c
.cpus_cnt
);
992 bitmap_zero(set
, c2c
.cpus_cnt
);
993 bitmap_and(set
, c2c_he
->cpuset
, c2c
.nodes
[node
], c2c
.cpus_cnt
);
995 if (!bitmap_weight(set
, c2c
.cpus_cnt
)) {
996 if (c2c
.node_info
== 1) {
997 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%21s", " ");
998 advance_hpp(hpp
, ret
);
1004 ret
= scnprintf(hpp
->buf
, hpp
->size
, " ");
1005 advance_hpp(hpp
, ret
);
1008 switch (c2c
.node_info
) {
1010 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d", node
);
1011 advance_hpp(hpp
, ret
);
1015 int num
= bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
);
1016 struct c2c_stats
*stats
= &c2c_he
->node_stats
[node
];
1018 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{%2d ", node
, num
);
1019 advance_hpp(hpp
, ret
);
1021 #define DISPLAY_HITM(__h) \
1022 if (c2c_he->stats.__h> 0) { \
1023 ret = scnprintf(hpp->buf, hpp->size, "%5.1f%% ", \
1024 percent(stats->__h, c2c_he->stats.__h));\
1026 ret = scnprintf(hpp->buf, hpp->size, "%6s ", "n/a"); \
1029 switch (c2c
.display
) {
1031 DISPLAY_HITM(rmt_hitm
);
1034 DISPLAY_HITM(lcl_hitm
);
1041 advance_hpp(hpp
, ret
);
1043 if (c2c_he
->stats
.store
> 0) {
1044 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%5.1f%%}",
1045 percent(stats
->store
, c2c_he
->stats
.store
));
1047 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%6s}", "n/a");
1050 advance_hpp(hpp
, ret
);
1054 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{", node
);
1055 advance_hpp(hpp
, ret
);
1057 ret
= bitmap_scnprintf(set
, c2c
.cpus_cnt
, hpp
->buf
, hpp
->size
);
1058 advance_hpp(hpp
, ret
);
1060 ret
= scnprintf(hpp
->buf
, hpp
->size
, "}");
1061 advance_hpp(hpp
, ret
);
1074 mean_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1075 struct hist_entry
*he
, double mean
)
1077 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1080 scnprintf(buf
, 10, "%6.0f", mean
);
1081 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1084 #define MEAN_ENTRY(__func, __val) \
1086 __func(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, struct hist_entry *he) \
1088 struct c2c_hist_entry *c2c_he; \
1089 c2c_he = container_of(he, struct c2c_hist_entry, he); \
1090 return mean_entry(fmt, hpp, he, avg_stats(&c2c_he->cstats.__val)); \
1093 MEAN_ENTRY(mean_rmt_entry
, rmt_hitm
);
1094 MEAN_ENTRY(mean_lcl_entry
, lcl_hitm
);
1095 MEAN_ENTRY(mean_load_entry
, load
);
1098 cpucnt_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
1099 struct hist_entry
*he
)
1101 struct c2c_hist_entry
*c2c_he
;
1102 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1105 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1107 scnprintf(buf
, 10, "%d", bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
));
1108 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1112 cl_idx_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
1113 struct hist_entry
*he
)
1115 struct c2c_hist_entry
*c2c_he
;
1116 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1119 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1121 scnprintf(buf
, 10, "%u", c2c_he
->cacheline_idx
);
1122 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1126 cl_idx_empty_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
1127 struct hist_entry
*he
)
1129 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1131 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, "");
1134 #define HEADER_LOW(__h) \
1141 #define HEADER_BOTH(__h0, __h1) \
1151 #define HEADER_SPAN(__h0, __h1, __s) \
1162 #define HEADER_SPAN_LOW(__h) \
1169 static struct c2c_dimension dim_dcacheline
= {
1170 .header
= HEADER_LOW("Cacheline"),
1171 .name
= "dcacheline",
1172 .cmp
= dcacheline_cmp
,
1173 .entry
= dcacheline_entry
,
1177 static struct c2c_header header_offset_tui
= HEADER_LOW("Off");
1179 static struct c2c_dimension dim_offset
= {
1180 .header
= HEADER_BOTH("Data address", "Offset"),
1183 .entry
= offset_entry
,
1187 static struct c2c_dimension dim_iaddr
= {
1188 .header
= HEADER_LOW("Code address"),
1191 .entry
= iaddr_entry
,
1195 static struct c2c_dimension dim_tot_hitm
= {
1196 .header
= HEADER_SPAN("----- LLC Load Hitm -----", "Total", 2),
1198 .cmp
= tot_hitm_cmp
,
1199 .entry
= tot_hitm_entry
,
1203 static struct c2c_dimension dim_lcl_hitm
= {
1204 .header
= HEADER_SPAN_LOW("Lcl"),
1206 .cmp
= lcl_hitm_cmp
,
1207 .entry
= lcl_hitm_entry
,
1211 static struct c2c_dimension dim_rmt_hitm
= {
1212 .header
= HEADER_SPAN_LOW("Rmt"),
1214 .cmp
= rmt_hitm_cmp
,
1215 .entry
= rmt_hitm_entry
,
1219 static struct c2c_dimension dim_cl_rmt_hitm
= {
1220 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1221 .name
= "cl_rmt_hitm",
1222 .cmp
= rmt_hitm_cmp
,
1223 .entry
= rmt_hitm_entry
,
1227 static struct c2c_dimension dim_cl_lcl_hitm
= {
1228 .header
= HEADER_SPAN_LOW("Lcl"),
1229 .name
= "cl_lcl_hitm",
1230 .cmp
= lcl_hitm_cmp
,
1231 .entry
= lcl_hitm_entry
,
1235 static struct c2c_dimension dim_stores
= {
1236 .header
= HEADER_SPAN("---- Store Reference ----", "Total", 2),
1239 .entry
= store_entry
,
1243 static struct c2c_dimension dim_stores_l1hit
= {
1244 .header
= HEADER_SPAN_LOW("L1Hit"),
1245 .name
= "stores_l1hit",
1246 .cmp
= st_l1hit_cmp
,
1247 .entry
= st_l1hit_entry
,
1251 static struct c2c_dimension dim_stores_l1miss
= {
1252 .header
= HEADER_SPAN_LOW("L1Miss"),
1253 .name
= "stores_l1miss",
1254 .cmp
= st_l1miss_cmp
,
1255 .entry
= st_l1miss_entry
,
1259 static struct c2c_dimension dim_cl_stores_l1hit
= {
1260 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1261 .name
= "cl_stores_l1hit",
1262 .cmp
= st_l1hit_cmp
,
1263 .entry
= st_l1hit_entry
,
1267 static struct c2c_dimension dim_cl_stores_l1miss
= {
1268 .header
= HEADER_SPAN_LOW("L1 Miss"),
1269 .name
= "cl_stores_l1miss",
1270 .cmp
= st_l1miss_cmp
,
1271 .entry
= st_l1miss_entry
,
1275 static struct c2c_dimension dim_ld_fbhit
= {
1276 .header
= HEADER_SPAN("----- Core Load Hit -----", "FB", 2),
1278 .cmp
= ld_fbhit_cmp
,
1279 .entry
= ld_fbhit_entry
,
1283 static struct c2c_dimension dim_ld_l1hit
= {
1284 .header
= HEADER_SPAN_LOW("L1"),
1286 .cmp
= ld_l1hit_cmp
,
1287 .entry
= ld_l1hit_entry
,
1291 static struct c2c_dimension dim_ld_l2hit
= {
1292 .header
= HEADER_SPAN_LOW("L2"),
1294 .cmp
= ld_l2hit_cmp
,
1295 .entry
= ld_l2hit_entry
,
1299 static struct c2c_dimension dim_ld_llchit
= {
1300 .header
= HEADER_SPAN("-- LLC Load Hit --", "Llc", 1),
1301 .name
= "ld_lclhit",
1302 .cmp
= ld_llchit_cmp
,
1303 .entry
= ld_llchit_entry
,
1307 static struct c2c_dimension dim_ld_rmthit
= {
1308 .header
= HEADER_SPAN_LOW("Rmt"),
1309 .name
= "ld_rmthit",
1311 .entry
= rmt_hit_entry
,
1315 static struct c2c_dimension dim_ld_llcmiss
= {
1316 .header
= HEADER_BOTH("LLC", "Ld Miss"),
1317 .name
= "ld_llcmiss",
1318 .cmp
= ld_llcmiss_cmp
,
1319 .entry
= ld_llcmiss_entry
,
1323 static struct c2c_dimension dim_tot_recs
= {
1324 .header
= HEADER_BOTH("Total", "records"),
1326 .cmp
= tot_recs_cmp
,
1327 .entry
= tot_recs_entry
,
1331 static struct c2c_dimension dim_tot_loads
= {
1332 .header
= HEADER_BOTH("Total", "Loads"),
1333 .name
= "tot_loads",
1334 .cmp
= tot_loads_cmp
,
1335 .entry
= tot_loads_entry
,
1339 static struct c2c_header percent_hitm_header
[] = {
1340 [DISPLAY_LCL
] = HEADER_BOTH("Lcl", "Hitm"),
1341 [DISPLAY_RMT
] = HEADER_BOTH("Rmt", "Hitm"),
1344 static struct c2c_dimension dim_percent_hitm
= {
1345 .name
= "percent_hitm",
1346 .cmp
= percent_hitm_cmp
,
1347 .entry
= percent_hitm_entry
,
1348 .color
= percent_hitm_color
,
1352 static struct c2c_dimension dim_percent_rmt_hitm
= {
1353 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1354 .name
= "percent_rmt_hitm",
1355 .cmp
= percent_rmt_hitm_cmp
,
1356 .entry
= percent_rmt_hitm_entry
,
1357 .color
= percent_rmt_hitm_color
,
1361 static struct c2c_dimension dim_percent_lcl_hitm
= {
1362 .header
= HEADER_SPAN_LOW("Lcl"),
1363 .name
= "percent_lcl_hitm",
1364 .cmp
= percent_lcl_hitm_cmp
,
1365 .entry
= percent_lcl_hitm_entry
,
1366 .color
= percent_lcl_hitm_color
,
1370 static struct c2c_dimension dim_percent_stores_l1hit
= {
1371 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1372 .name
= "percent_stores_l1hit",
1373 .cmp
= percent_stores_l1hit_cmp
,
1374 .entry
= percent_stores_l1hit_entry
,
1375 .color
= percent_stores_l1hit_color
,
1379 static struct c2c_dimension dim_percent_stores_l1miss
= {
1380 .header
= HEADER_SPAN_LOW("L1 Miss"),
1381 .name
= "percent_stores_l1miss",
1382 .cmp
= percent_stores_l1miss_cmp
,
1383 .entry
= percent_stores_l1miss_entry
,
1384 .color
= percent_stores_l1miss_color
,
1388 static struct c2c_dimension dim_dram_lcl
= {
1389 .header
= HEADER_SPAN("--- Load Dram ----", "Lcl", 1),
1391 .cmp
= lcl_dram_cmp
,
1392 .entry
= lcl_dram_entry
,
1396 static struct c2c_dimension dim_dram_rmt
= {
1397 .header
= HEADER_SPAN_LOW("Rmt"),
1399 .cmp
= rmt_dram_cmp
,
1400 .entry
= rmt_dram_entry
,
1404 static struct c2c_dimension dim_pid
= {
1405 .header
= HEADER_LOW("Pid"),
1412 static struct c2c_dimension dim_tid
= {
1413 .header
= HEADER_LOW("Tid"),
1418 static struct c2c_dimension dim_symbol
= {
1423 static struct c2c_dimension dim_dso
= {
1424 .header
= HEADER_BOTH("Shared", "Object"),
1429 static struct c2c_header header_node
[3] = {
1431 HEADER_LOW("Node{cpus %hitms %stores}"),
1432 HEADER_LOW("Node{cpu list}"),
1435 static struct c2c_dimension dim_node
= {
1438 .entry
= node_entry
,
1442 static struct c2c_dimension dim_mean_rmt
= {
1443 .header
= HEADER_SPAN("---------- cycles ----------", "rmt hitm", 2),
1446 .entry
= mean_rmt_entry
,
1450 static struct c2c_dimension dim_mean_lcl
= {
1451 .header
= HEADER_SPAN_LOW("lcl hitm"),
1454 .entry
= mean_lcl_entry
,
1458 static struct c2c_dimension dim_mean_load
= {
1459 .header
= HEADER_SPAN_LOW("load"),
1460 .name
= "mean_load",
1462 .entry
= mean_load_entry
,
1466 static struct c2c_dimension dim_cpucnt
= {
1467 .header
= HEADER_BOTH("cpu", "cnt"),
1470 .entry
= cpucnt_entry
,
1474 static struct c2c_dimension dim_srcline
= {
1475 .name
= "cl_srcline",
1476 .se
= &sort_srcline
,
1479 static struct c2c_dimension dim_dcacheline_idx
= {
1480 .header
= HEADER_LOW("Index"),
1483 .entry
= cl_idx_entry
,
1487 static struct c2c_dimension dim_dcacheline_num
= {
1488 .header
= HEADER_LOW("Num"),
1491 .entry
= cl_idx_entry
,
1495 static struct c2c_dimension dim_dcacheline_num_empty
= {
1496 .header
= HEADER_LOW("Num"),
1497 .name
= "cl_num_empty",
1499 .entry
= cl_idx_empty_entry
,
1503 static struct c2c_dimension
*dimensions
[] = {
1515 &dim_cl_stores_l1hit
,
1516 &dim_cl_stores_l1miss
,
1526 &dim_percent_rmt_hitm
,
1527 &dim_percent_lcl_hitm
,
1528 &dim_percent_stores_l1hit
,
1529 &dim_percent_stores_l1miss
,
1542 &dim_dcacheline_idx
,
1543 &dim_dcacheline_num
,
1544 &dim_dcacheline_num_empty
,
1548 static void fmt_free(struct perf_hpp_fmt
*fmt
)
1550 struct c2c_fmt
*c2c_fmt
;
1552 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1556 static bool fmt_equal(struct perf_hpp_fmt
*a
, struct perf_hpp_fmt
*b
)
1558 struct c2c_fmt
*c2c_a
= container_of(a
, struct c2c_fmt
, fmt
);
1559 struct c2c_fmt
*c2c_b
= container_of(b
, struct c2c_fmt
, fmt
);
1561 return c2c_a
->dim
== c2c_b
->dim
;
1564 static struct c2c_dimension
*get_dimension(const char *name
)
1568 for (i
= 0; dimensions
[i
]; i
++) {
1569 struct c2c_dimension
*dim
= dimensions
[i
];
1571 if (!strcmp(dim
->name
, name
))
1578 static int c2c_se_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1579 struct hist_entry
*he
)
1581 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1582 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1583 size_t len
= fmt
->user_len
;
1586 len
= hists__col_len(he
->hists
, dim
->se
->se_width_idx
);
1588 if (dim
== &dim_symbol
|| dim
== &dim_srcline
)
1589 len
= symbol_width(he
->hists
, dim
->se
);
1592 return dim
->se
->se_snprintf(he
, hpp
->buf
, hpp
->size
, len
);
1595 static int64_t c2c_se_cmp(struct perf_hpp_fmt
*fmt
,
1596 struct hist_entry
*a
, struct hist_entry
*b
)
1598 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1599 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1601 return dim
->se
->se_cmp(a
, b
);
1604 static int64_t c2c_se_collapse(struct perf_hpp_fmt
*fmt
,
1605 struct hist_entry
*a
, struct hist_entry
*b
)
1607 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1608 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1609 int64_t (*collapse_fn
)(struct hist_entry
*, struct hist_entry
*);
1611 collapse_fn
= dim
->se
->se_collapse
?: dim
->se
->se_cmp
;
1612 return collapse_fn(a
, b
);
1615 static struct c2c_fmt
*get_format(const char *name
)
1617 struct c2c_dimension
*dim
= get_dimension(name
);
1618 struct c2c_fmt
*c2c_fmt
;
1619 struct perf_hpp_fmt
*fmt
;
1624 c2c_fmt
= zalloc(sizeof(*c2c_fmt
));
1630 fmt
= &c2c_fmt
->fmt
;
1631 INIT_LIST_HEAD(&fmt
->list
);
1632 INIT_LIST_HEAD(&fmt
->sort_list
);
1634 fmt
->cmp
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1635 fmt
->sort
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1636 fmt
->color
= dim
->se
? NULL
: dim
->color
;
1637 fmt
->entry
= dim
->se
? c2c_se_entry
: dim
->entry
;
1638 fmt
->header
= c2c_header
;
1639 fmt
->width
= c2c_width
;
1640 fmt
->collapse
= dim
->se
? c2c_se_collapse
: dim
->cmp
;
1641 fmt
->equal
= fmt_equal
;
1642 fmt
->free
= fmt_free
;
1647 static int c2c_hists__init_output(struct perf_hpp_list
*hpp_list
, char *name
)
1649 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1653 return output_field_add(hpp_list
, name
);
1656 perf_hpp_list__column_register(hpp_list
, &c2c_fmt
->fmt
);
1660 static int c2c_hists__init_sort(struct perf_hpp_list
*hpp_list
, char *name
)
1662 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1663 struct c2c_dimension
*dim
;
1667 return sort_dimension__add(hpp_list
, name
, NULL
, 0);
1671 if (dim
== &dim_dso
)
1674 perf_hpp_list__register_sort_field(hpp_list
, &c2c_fmt
->fmt
);
1678 #define PARSE_LIST(_list, _fn) \
1686 for (tok = strtok_r((char *)_list, ", ", &tmp); \
1687 tok; tok = strtok_r(NULL, ", ", &tmp)) { \
1688 ret = _fn(hpp_list, tok); \
1689 if (ret == -EINVAL) { \
1690 error("Invalid --fields key: `%s'", tok); \
1692 } else if (ret == -ESRCH) { \
1693 error("Unknown --fields key: `%s'", tok); \
1699 static int hpp_list__parse(struct perf_hpp_list
*hpp_list
,
1700 const char *output_
,
1703 char *output
= output_
? strdup(output_
) : NULL
;
1704 char *sort
= sort_
? strdup(sort_
) : NULL
;
1707 PARSE_LIST(output
, c2c_hists__init_output
);
1708 PARSE_LIST(sort
, c2c_hists__init_sort
);
1710 /* copy sort keys to output fields */
1711 perf_hpp__setup_output_field(hpp_list
);
1714 * We dont need other sorting keys other than those
1715 * we already specified. It also really slows down
1716 * the processing a lot with big number of output
1717 * fields, so switching this off for c2c.
1721 /* and then copy output fields to sort keys */
1722 perf_hpp__append_sort_keys(&hists
->list
);
1730 static int c2c_hists__init(struct c2c_hists
*hists
,
1732 int nr_header_lines
)
1734 __hists__init(&hists
->hists
, &hists
->list
);
1737 * Initialize only with sort fields, we need to resort
1738 * later anyway, and that's where we add output fields
1741 perf_hpp_list__init(&hists
->list
);
1743 /* Overload number of header lines.*/
1744 hists
->list
.nr_header_lines
= nr_header_lines
;
1746 return hpp_list__parse(&hists
->list
, NULL
, sort
);
1750 static int c2c_hists__reinit(struct c2c_hists
*c2c_hists
,
1754 perf_hpp__reset_output_field(&c2c_hists
->list
);
1755 return hpp_list__parse(&c2c_hists
->list
, output
, sort
);
1758 #define DISPLAY_LINE_LIMIT 0.0005
1760 static bool he__display(struct hist_entry
*he
, struct c2c_stats
*stats
)
1762 struct c2c_hist_entry
*c2c_he
;
1765 /* XXX Disabled for now, till we get a command line switch to control this */
1768 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1770 #define FILTER_HITM(__h) \
1772 ld_dist = ((double)c2c_he->stats.__h / stats->__h); \
1773 if (ld_dist < DISPLAY_LINE_LIMIT) \
1774 he->filtered = HIST_FILTER__C2C; \
1776 he->filtered = HIST_FILTER__C2C; \
1779 switch (c2c
.display
) {
1781 FILTER_HITM(lcl_hitm
);
1784 FILTER_HITM(rmt_hitm
);
1791 return he
->filtered
== 0;
1794 static inline int valid_hitm_or_store(struct hist_entry
*he
)
1796 struct c2c_hist_entry
*c2c_he
;
1799 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1800 has_hitm
= c2c
.display
== DISPLAY_LCL
?
1801 c2c_he
->stats
.lcl_hitm
: c2c_he
->stats
.rmt_hitm
;
1802 return has_hitm
|| c2c_he
->stats
.store
;
1805 static void calc_width(struct hist_entry
*he
)
1807 struct c2c_hists
*c2c_hists
;
1809 c2c_hists
= container_of(he
->hists
, struct c2c_hists
, hists
);
1810 hists__calc_col_len(&c2c_hists
->hists
, he
);
1813 static int filter_cb(struct hist_entry
*he
)
1815 if (c2c
.show_src
&& !he
->srcline
)
1816 he
->srcline
= hist_entry__get_srcline(he
);
1820 if (!valid_hitm_or_store(he
))
1821 he
->filtered
= HIST_FILTER__C2C
;
1826 static int resort_cl_cb(struct hist_entry
*he
)
1828 struct c2c_hist_entry
*c2c_he
;
1829 struct c2c_hists
*c2c_hists
;
1830 bool display
= he__display(he
, &c2c
.hitm_stats
);
1832 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1833 c2c_hists
= c2c_he
->hists
;
1837 if (display
&& c2c_hists
) {
1838 static unsigned int idx
;
1840 c2c_he
->cacheline_idx
= idx
++;
1842 c2c_hists__reinit(c2c_hists
, c2c
.cl_output
, c2c
.cl_resort
);
1844 hists__collapse_resort(&c2c_hists
->hists
, NULL
);
1845 hists__output_resort_cb(&c2c_hists
->hists
, NULL
, filter_cb
);
1851 static void setup_nodes_header(void)
1853 dim_node
.header
= header_node
[c2c
.node_info
];
1856 static int setup_nodes(struct perf_session
*session
)
1858 struct numa_node
*n
;
1859 unsigned long **nodes
;
1863 if (c2c
.node_info
> 2)
1866 c2c
.nodes_cnt
= session
->header
.env
.nr_numa_nodes
;
1867 c2c
.cpus_cnt
= session
->header
.env
.nr_cpus_online
;
1869 n
= session
->header
.env
.numa_nodes
;
1873 nodes
= zalloc(sizeof(unsigned long *) * c2c
.nodes_cnt
);
1879 cpu2node
= zalloc(sizeof(int) * c2c
.cpus_cnt
);
1883 for (cpu
= 0; cpu
< c2c
.cpus_cnt
; cpu
++)
1886 c2c
.cpu2node
= cpu2node
;
1888 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
1889 struct cpu_map
*map
= n
[node
].map
;
1892 set
= bitmap_alloc(c2c
.cpus_cnt
);
1896 for (cpu
= 0; cpu
< map
->nr
; cpu
++) {
1897 set_bit(map
->map
[cpu
], set
);
1899 if (WARN_ONCE(cpu2node
[map
->map
[cpu
]] != -1, "node/cpu topology bug"))
1902 cpu2node
[map
->map
[cpu
]] = node
;
1908 setup_nodes_header();
1912 #define HAS_HITMS(__h) ((__h)->stats.lcl_hitm || (__h)->stats.rmt_hitm)
1914 static int resort_hitm_cb(struct hist_entry
*he
)
1916 struct c2c_hist_entry
*c2c_he
;
1917 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1919 if (HAS_HITMS(c2c_he
)) {
1920 c2c
.shared_clines
++;
1921 c2c_add_stats(&c2c
.hitm_stats
, &c2c_he
->stats
);
1927 static int hists__iterate_cb(struct hists
*hists
, hists__resort_cb_t cb
)
1929 struct rb_node
*next
= rb_first(&hists
->entries
);
1933 struct hist_entry
*he
;
1935 he
= rb_entry(next
, struct hist_entry
, rb_node
);
1939 next
= rb_next(&he
->rb_node
);
1945 static void print_c2c__display_stats(FILE *out
)
1948 struct c2c_stats
*stats
= &c2c
.hists
.stats
;
1950 llc_misses
= stats
->lcl_dram
+
1955 fprintf(out
, "=================================================\n");
1956 fprintf(out
, " Trace Event Information \n");
1957 fprintf(out
, "=================================================\n");
1958 fprintf(out
, " Total records : %10d\n", stats
->nr_entries
);
1959 fprintf(out
, " Locked Load/Store Operations : %10d\n", stats
->locks
);
1960 fprintf(out
, " Load Operations : %10d\n", stats
->load
);
1961 fprintf(out
, " Loads - uncacheable : %10d\n", stats
->ld_uncache
);
1962 fprintf(out
, " Loads - IO : %10d\n", stats
->ld_io
);
1963 fprintf(out
, " Loads - Miss : %10d\n", stats
->ld_miss
);
1964 fprintf(out
, " Loads - no mapping : %10d\n", stats
->ld_noadrs
);
1965 fprintf(out
, " Load Fill Buffer Hit : %10d\n", stats
->ld_fbhit
);
1966 fprintf(out
, " Load L1D hit : %10d\n", stats
->ld_l1hit
);
1967 fprintf(out
, " Load L2D hit : %10d\n", stats
->ld_l2hit
);
1968 fprintf(out
, " Load LLC hit : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
1969 fprintf(out
, " Load Local HITM : %10d\n", stats
->lcl_hitm
);
1970 fprintf(out
, " Load Remote HITM : %10d\n", stats
->rmt_hitm
);
1971 fprintf(out
, " Load Remote HIT : %10d\n", stats
->rmt_hit
);
1972 fprintf(out
, " Load Local DRAM : %10d\n", stats
->lcl_dram
);
1973 fprintf(out
, " Load Remote DRAM : %10d\n", stats
->rmt_dram
);
1974 fprintf(out
, " Load MESI State Exclusive : %10d\n", stats
->ld_excl
);
1975 fprintf(out
, " Load MESI State Shared : %10d\n", stats
->ld_shared
);
1976 fprintf(out
, " Load LLC Misses : %10d\n", llc_misses
);
1977 fprintf(out
, " LLC Misses to Local DRAM : %10.1f%%\n", ((double)stats
->lcl_dram
/(double)llc_misses
) * 100.);
1978 fprintf(out
, " LLC Misses to Remote DRAM : %10.1f%%\n", ((double)stats
->rmt_dram
/(double)llc_misses
) * 100.);
1979 fprintf(out
, " LLC Misses to Remote cache (HIT) : %10.1f%%\n", ((double)stats
->rmt_hit
/(double)llc_misses
) * 100.);
1980 fprintf(out
, " LLC Misses to Remote cache (HITM) : %10.1f%%\n", ((double)stats
->rmt_hitm
/(double)llc_misses
) * 100.);
1981 fprintf(out
, " Store Operations : %10d\n", stats
->store
);
1982 fprintf(out
, " Store - uncacheable : %10d\n", stats
->st_uncache
);
1983 fprintf(out
, " Store - no mapping : %10d\n", stats
->st_noadrs
);
1984 fprintf(out
, " Store L1D Hit : %10d\n", stats
->st_l1hit
);
1985 fprintf(out
, " Store L1D Miss : %10d\n", stats
->st_l1miss
);
1986 fprintf(out
, " No Page Map Rejects : %10d\n", stats
->nomap
);
1987 fprintf(out
, " Unable to parse data source : %10d\n", stats
->noparse
);
1990 static void print_shared_cacheline_info(FILE *out
)
1992 struct c2c_stats
*stats
= &c2c
.hitm_stats
;
1993 int hitm_cnt
= stats
->lcl_hitm
+ stats
->rmt_hitm
;
1995 fprintf(out
, "=================================================\n");
1996 fprintf(out
, " Global Shared Cache Line Event Information \n");
1997 fprintf(out
, "=================================================\n");
1998 fprintf(out
, " Total Shared Cache Lines : %10d\n", c2c
.shared_clines
);
1999 fprintf(out
, " Load HITs on shared lines : %10d\n", stats
->load
);
2000 fprintf(out
, " Fill Buffer Hits on shared lines : %10d\n", stats
->ld_fbhit
);
2001 fprintf(out
, " L1D hits on shared lines : %10d\n", stats
->ld_l1hit
);
2002 fprintf(out
, " L2D hits on shared lines : %10d\n", stats
->ld_l2hit
);
2003 fprintf(out
, " LLC hits on shared lines : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
2004 fprintf(out
, " Locked Access on shared lines : %10d\n", stats
->locks
);
2005 fprintf(out
, " Store HITs on shared lines : %10d\n", stats
->store
);
2006 fprintf(out
, " Store L1D hits on shared lines : %10d\n", stats
->st_l1hit
);
2007 fprintf(out
, " Total Merged records : %10d\n", hitm_cnt
+ stats
->store
);
2010 static void print_cacheline(struct c2c_hists
*c2c_hists
,
2011 struct hist_entry
*he_cl
,
2012 struct perf_hpp_list
*hpp_list
,
2016 struct perf_hpp hpp
= {
2023 hists__fprintf_headers(&c2c_hists
->hists
, out
);
2029 fprintf(out
, " -------------------------------------------------------------\n");
2030 __hist_entry__snprintf(he_cl
, &hpp
, hpp_list
);
2031 fprintf(out
, "%s\n", bf
);
2032 fprintf(out
, " -------------------------------------------------------------\n");
2034 hists__fprintf(&c2c_hists
->hists
, false, 0, 0, 0, out
, true);
2037 static void print_pareto(FILE *out
)
2039 struct perf_hpp_list hpp_list
;
2043 perf_hpp_list__init(&hpp_list
);
2044 ret
= hpp_list__parse(&hpp_list
,
2053 if (WARN_ONCE(ret
, "failed to setup sort entries\n"))
2056 nd
= rb_first(&c2c
.hists
.hists
.entries
);
2058 for (; nd
; nd
= rb_next(nd
)) {
2059 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2060 struct c2c_hist_entry
*c2c_he
;
2065 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2066 print_cacheline(c2c_he
->hists
, he
, &hpp_list
, out
);
2070 static void print_c2c_info(FILE *out
, struct perf_session
*session
)
2072 struct perf_evlist
*evlist
= session
->evlist
;
2073 struct perf_evsel
*evsel
;
2076 fprintf(out
, "=================================================\n");
2077 fprintf(out
, " c2c details \n");
2078 fprintf(out
, "=================================================\n");
2080 evlist__for_each_entry(evlist
, evsel
) {
2081 fprintf(out
, "%-36s: %s\n", first
? " Events" : "",
2082 perf_evsel__name(evsel
));
2085 fprintf(out
, " Cachelines sort on : %s HITMs\n",
2086 c2c
.display
== DISPLAY_LCL
? "Local" : "Remote");
2087 fprintf(out
, " Cacheline data grouping : %s\n", c2c
.cl_sort
);
2090 static void perf_c2c__hists_fprintf(FILE *out
, struct perf_session
*session
)
2094 print_c2c__display_stats(out
);
2096 print_shared_cacheline_info(out
);
2098 print_c2c_info(out
, session
);
2104 fprintf(out
, "=================================================\n");
2105 fprintf(out
, " Shared Data Cache Line Table \n");
2106 fprintf(out
, "=================================================\n");
2107 fprintf(out
, "#\n");
2109 hists__fprintf(&c2c
.hists
.hists
, true, 0, 0, 0, stdout
, false);
2112 fprintf(out
, "=================================================\n");
2113 fprintf(out
, " Shared Cache Line Distribution Pareto \n");
2114 fprintf(out
, "=================================================\n");
2115 fprintf(out
, "#\n");
2120 #ifdef HAVE_SLANG_SUPPORT
2121 static void c2c_browser__update_nr_entries(struct hist_browser
*hb
)
2124 struct rb_node
*nd
= rb_first(&hb
->hists
->entries
);
2127 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2135 hb
->nr_non_filtered_entries
= nr_entries
;
2138 struct c2c_cacheline_browser
{
2139 struct hist_browser hb
;
2140 struct hist_entry
*he
;
2144 perf_c2c_cacheline_browser__title(struct hist_browser
*browser
,
2145 char *bf
, size_t size
)
2147 struct c2c_cacheline_browser
*cl_browser
;
2148 struct hist_entry
*he
;
2151 cl_browser
= container_of(browser
, struct c2c_cacheline_browser
, hb
);
2152 he
= cl_browser
->he
;
2155 addr
= cl_address(he
->mem_info
->daddr
.addr
);
2157 scnprintf(bf
, size
, "Cacheline 0x%lx", addr
);
2161 static struct c2c_cacheline_browser
*
2162 c2c_cacheline_browser__new(struct hists
*hists
, struct hist_entry
*he
)
2164 struct c2c_cacheline_browser
*browser
;
2166 browser
= zalloc(sizeof(*browser
));
2168 hist_browser__init(&browser
->hb
, hists
);
2169 browser
->hb
.c2c_filter
= true;
2170 browser
->hb
.title
= perf_c2c_cacheline_browser__title
;
2177 static int perf_c2c__browse_cacheline(struct hist_entry
*he
)
2179 struct c2c_hist_entry
*c2c_he
;
2180 struct c2c_hists
*c2c_hists
;
2181 struct c2c_cacheline_browser
*cl_browser
;
2182 struct hist_browser
*browser
;
2185 " ENTER Togle callchains (if present) \n"
2186 " n Togle Node details info \n"
2187 " s Togle full lenght of symbol and source line columns \n"
2188 " q Return back to cacheline list \n";
2190 /* Display compact version first. */
2191 c2c
.symbol_full
= false;
2193 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2194 c2c_hists
= c2c_he
->hists
;
2196 cl_browser
= c2c_cacheline_browser__new(&c2c_hists
->hists
, he
);
2197 if (cl_browser
== NULL
)
2200 browser
= &cl_browser
->hb
;
2202 /* reset abort key so that it can get Ctrl-C as a key */
2204 SLang_init_tty(0, 0, 0);
2206 c2c_browser__update_nr_entries(browser
);
2209 key
= hist_browser__run(browser
, "? - help");
2213 c2c
.symbol_full
= !c2c
.symbol_full
;
2216 c2c
.node_info
= (c2c
.node_info
+ 1) % 3;
2217 setup_nodes_header();
2222 ui_browser__help_window(&browser
->b
, help
);
2234 static int perf_c2c_browser__title(struct hist_browser
*browser
,
2235 char *bf
, size_t size
)
2238 "Shared Data Cache Line Table "
2239 "(%lu entries, sorted on %s HITMs)",
2240 browser
->nr_non_filtered_entries
,
2241 c2c
.display
== DISPLAY_LCL
? "local" : "remote");
2245 static struct hist_browser
*
2246 perf_c2c_browser__new(struct hists
*hists
)
2248 struct hist_browser
*browser
= hist_browser__new(hists
);
2251 browser
->title
= perf_c2c_browser__title
;
2252 browser
->c2c_filter
= true;
2258 static int perf_c2c__hists_browse(struct hists
*hists
)
2260 struct hist_browser
*browser
;
2263 " d Display cacheline details \n"
2264 " ENTER Togle callchains (if present) \n"
2267 browser
= perf_c2c_browser__new(hists
);
2268 if (browser
== NULL
)
2271 /* reset abort key so that it can get Ctrl-C as a key */
2273 SLang_init_tty(0, 0, 0);
2275 c2c_browser__update_nr_entries(browser
);
2278 key
= hist_browser__run(browser
, "? - help");
2284 perf_c2c__browse_cacheline(browser
->he_selection
);
2287 ui_browser__help_window(&browser
->b
, help
);
2295 hist_browser__delete(browser
);
2299 static void perf_c2c_display(struct perf_session
*session
)
2302 perf_c2c__hists_fprintf(stdout
, session
);
2304 perf_c2c__hists_browse(&c2c
.hists
.hists
);
2307 static void perf_c2c_display(struct perf_session
*session
)
2310 perf_c2c__hists_fprintf(stdout
, session
);
2312 #endif /* HAVE_SLANG_SUPPORT */
2314 static void ui_quirks(void)
2316 if (!c2c
.use_stdio
) {
2317 dim_offset
.width
= 5;
2318 dim_offset
.header
= header_offset_tui
;
2321 dim_percent_hitm
.header
= percent_hitm_header
[c2c
.display
];
2324 #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
2326 const char callchain_help
[] = "Display call graph (stack chain/backtrace):\n\n"
2327 CALLCHAIN_REPORT_HELP
2328 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT
;
2331 parse_callchain_opt(const struct option
*opt
, const char *arg
, int unset
)
2333 struct callchain_param
*callchain
= opt
->value
;
2335 callchain
->enabled
= !unset
;
2340 symbol_conf
.use_callchain
= false;
2341 callchain
->mode
= CHAIN_NONE
;
2345 return parse_callchain_report_opt(arg
);
2348 static int setup_callchain(struct perf_evlist
*evlist
)
2350 u64 sample_type
= perf_evlist__combined_sample_type(evlist
);
2351 enum perf_call_graph_mode mode
= CALLCHAIN_NONE
;
2353 if ((sample_type
& PERF_SAMPLE_REGS_USER
) &&
2354 (sample_type
& PERF_SAMPLE_STACK_USER
))
2355 mode
= CALLCHAIN_DWARF
;
2356 else if (sample_type
& PERF_SAMPLE_BRANCH_STACK
)
2357 mode
= CALLCHAIN_LBR
;
2358 else if (sample_type
& PERF_SAMPLE_CALLCHAIN
)
2359 mode
= CALLCHAIN_FP
;
2361 if (!callchain_param
.enabled
&&
2362 callchain_param
.mode
!= CHAIN_NONE
&&
2363 mode
!= CALLCHAIN_NONE
) {
2364 symbol_conf
.use_callchain
= true;
2365 if (callchain_register_param(&callchain_param
) < 0) {
2366 ui__error("Can't register callchain params.\n");
2371 callchain_param
.record_mode
= mode
;
2372 callchain_param
.min_percent
= 0;
2376 static int setup_display(const char *str
)
2378 const char *display
= str
?: "rmt";
2380 if (!strcmp(display
, "rmt"))
2381 c2c
.display
= DISPLAY_RMT
;
2382 else if (!strcmp(display
, "lcl"))
2383 c2c
.display
= DISPLAY_LCL
;
2385 pr_err("failed: unknown display type: %s\n", str
);
2392 #define for_each_token(__tok, __buf, __sep, __tmp) \
2393 for (__tok = strtok_r(__buf, __sep, &__tmp); __tok; \
2394 __tok = strtok_r(NULL, __sep, &__tmp))
2396 static int build_cl_output(char *cl_sort
)
2398 char *tok
, *tmp
, *buf
= strdup(cl_sort
);
2399 bool add_pid
= false;
2400 bool add_tid
= false;
2401 bool add_iaddr
= false;
2402 bool add_sym
= false;
2403 bool add_dso
= false;
2404 bool add_src
= false;
2409 for_each_token(tok
, buf
, ",", tmp
) {
2410 if (!strcmp(tok
, "tid")) {
2412 } else if (!strcmp(tok
, "pid")) {
2414 } else if (!strcmp(tok
, "iaddr")) {
2419 } else if (!strcmp(tok
, "dso")) {
2421 } else if (strcmp(tok
, "offset")) {
2422 pr_err("unrecognized sort token: %s\n", tok
);
2427 if (asprintf(&c2c
.cl_output
,
2428 "%s%s%s%s%s%s%s%s%s%s",
2429 c2c
.use_stdio
? "cl_num_empty," : "",
2432 "percent_stores_l1hit,"
2433 "percent_stores_l1miss,"
2435 add_pid
? "pid," : "",
2436 add_tid
? "tid," : "",
2437 add_iaddr
? "iaddr," : "",
2442 add_sym
? "symbol," : "",
2443 add_dso
? "dso," : "",
2444 add_src
? "cl_srcline," : "",
2448 c2c
.show_src
= add_src
;
2454 static int setup_coalesce(const char *coalesce
)
2456 const char *c
= coalesce
?: coalesce_default
;
2458 if (asprintf(&c2c
.cl_sort
, "offset,%s", c
) < 0)
2461 if (build_cl_output(c2c
.cl_sort
))
2464 if (asprintf(&c2c
.cl_resort
, "offset,%s",
2465 c2c
.display
== DISPLAY_RMT
?
2466 "rmt_hitm,lcl_hitm" :
2467 "lcl_hitm,rmt_hitm") < 0)
2470 pr_debug("coalesce sort fields: %s\n", c2c
.cl_sort
);
2471 pr_debug("coalesce resort fields: %s\n", c2c
.cl_resort
);
2472 pr_debug("coalesce output fields: %s\n", c2c
.cl_output
);
2476 static int perf_c2c__report(int argc
, const char **argv
)
2478 struct perf_session
*session
;
2479 struct ui_progress prog
;
2480 struct perf_data_file file
= {
2481 .mode
= PERF_DATA_MODE_READ
,
2483 char callchain_default_opt
[] = CALLCHAIN_DEFAULT_OPT
;
2484 const char *display
= NULL
;
2485 const char *coalesce
= NULL
;
2486 const struct option c2c_options
[] = {
2487 OPT_STRING('k', "vmlinux", &symbol_conf
.vmlinux_name
,
2488 "file", "vmlinux pathname"),
2489 OPT_INCR('v', "verbose", &verbose
,
2490 "be more verbose (show counter open errors, etc)"),
2491 OPT_STRING('i', "input", &input_name
, "file",
2492 "the input file to process"),
2493 OPT_INCR('N', "node-info", &c2c
.node_info
,
2494 "show extra node info in report (repeat for more info)"),
2495 #ifdef HAVE_SLANG_SUPPORT
2496 OPT_BOOLEAN(0, "stdio", &c2c
.use_stdio
, "Use the stdio interface"),
2498 OPT_BOOLEAN(0, "stats", &c2c
.stats_only
,
2499 "Use the stdio interface"),
2500 OPT_BOOLEAN(0, "full-symbols", &c2c
.symbol_full
,
2501 "Display full length of symbols"),
2502 OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param
,
2503 "print_type,threshold[,print_limit],order,sort_key[,branch],value",
2504 callchain_help
, &parse_callchain_opt
,
2505 callchain_default_opt
),
2506 OPT_STRING('d', "display", &display
, NULL
, "lcl,rmt"),
2507 OPT_STRING('c', "coalesce", &coalesce
, "coalesce fields",
2508 "coalesce fields: pid,tid,iaddr,dso"),
2513 argc
= parse_options(argc
, argv
, c2c_options
, report_c2c_usage
,
2514 PARSE_OPT_STOP_AT_NON_OPTION
);
2516 usage_with_options(report_c2c_usage
, c2c_options
);
2519 c2c
.use_stdio
= true;
2526 setup_browser(false);
2528 if (!input_name
|| !strlen(input_name
))
2529 input_name
= "perf.data";
2531 file
.path
= input_name
;
2533 err
= setup_display(display
);
2537 err
= setup_coalesce(coalesce
);
2539 pr_debug("Failed to initialize hists\n");
2543 err
= c2c_hists__init(&c2c
.hists
, "dcacheline", 2);
2545 pr_debug("Failed to initialize hists\n");
2549 session
= perf_session__new(&file
, 0, &c2c
.tool
);
2550 if (session
== NULL
) {
2551 pr_debug("No memory for session\n");
2554 err
= setup_nodes(session
);
2556 pr_err("Failed setup nodes\n");
2560 err
= setup_callchain(session
->evlist
);
2564 if (symbol__init(&session
->header
.env
) < 0)
2567 /* No pipe support at the moment. */
2568 if (perf_data_file__is_pipe(session
->file
)) {
2569 pr_debug("No pipe support at the moment.\n");
2573 err
= perf_session__process_events(session
);
2575 pr_err("failed to process sample\n");
2579 c2c_hists__reinit(&c2c
.hists
,
2584 "tot_hitm,lcl_hitm,rmt_hitm,"
2585 "stores,stores_l1hit,stores_l1miss,"
2586 "dram_lcl,dram_rmt,"
2589 "ld_fbhit,ld_l1hit,ld_l2hit,"
2590 "ld_lclhit,ld_rmthit",
2591 c2c
.display
== DISPLAY_LCL
? "lcl_hitm" : "rmt_hitm"
2594 ui_progress__init(&prog
, c2c
.hists
.hists
.nr_entries
, "Sorting...");
2596 hists__collapse_resort(&c2c
.hists
.hists
, NULL
);
2597 hists__output_resort_cb(&c2c
.hists
.hists
, &prog
, resort_hitm_cb
);
2598 hists__iterate_cb(&c2c
.hists
.hists
, resort_cl_cb
);
2600 ui_progress__finish();
2604 perf_c2c_display(session
);
2607 perf_session__delete(session
);
2612 static int parse_record_events(const struct option
*opt __maybe_unused
,
2613 const char *str
, int unset __maybe_unused
)
2615 bool *event_set
= (bool *) opt
->value
;
2618 return perf_mem_events__parse(str
);
2622 static const char * const __usage_record
[] = {
2623 "perf c2c record [<options>] [<command>]",
2624 "perf c2c record [<options>] -- <command> [<options>]",
2628 static const char * const *record_mem_usage
= __usage_record
;
2630 static int perf_c2c__record(int argc
, const char **argv
)
2632 int rec_argc
, i
= 0, j
;
2633 const char **rec_argv
;
2635 bool all_user
= false, all_kernel
= false;
2636 bool event_set
= false;
2637 struct option options
[] = {
2638 OPT_CALLBACK('e', "event", &event_set
, "event",
2639 "event selector. Use 'perf mem record -e list' to list available events",
2640 parse_record_events
),
2641 OPT_INCR('v', "verbose", &verbose
,
2642 "be more verbose (show counter open errors, etc)"),
2643 OPT_BOOLEAN('u', "all-user", &all_user
, "collect only user level data"),
2644 OPT_BOOLEAN('k', "all-kernel", &all_kernel
, "collect only kernel level data"),
2645 OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat
, "setup mem-loads latency"),
2649 if (perf_mem_events__init()) {
2650 pr_err("failed: memory events not supported\n");
2654 argc
= parse_options(argc
, argv
, options
, record_mem_usage
,
2655 PARSE_OPT_KEEP_UNKNOWN
);
2657 rec_argc
= argc
+ 10; /* max number of arguments */
2658 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
2662 rec_argv
[i
++] = "record";
2665 perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
= true;
2666 perf_mem_events
[PERF_MEM_EVENTS__STORE
].record
= true;
2669 if (perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
)
2670 rec_argv
[i
++] = "-W";
2672 rec_argv
[i
++] = "-d";
2673 rec_argv
[i
++] = "--sample-cpu";
2675 for (j
= 0; j
< PERF_MEM_EVENTS__MAX
; j
++) {
2676 if (!perf_mem_events
[j
].record
)
2679 if (!perf_mem_events
[j
].supported
) {
2680 pr_err("failed: event '%s' not supported\n",
2681 perf_mem_events
[j
].name
);
2685 rec_argv
[i
++] = "-e";
2686 rec_argv
[i
++] = perf_mem_events__name(j
);
2690 rec_argv
[i
++] = "--all-user";
2693 rec_argv
[i
++] = "--all-kernel";
2695 for (j
= 0; j
< argc
; j
++, i
++)
2696 rec_argv
[i
] = argv
[j
];
2699 pr_debug("calling: ");
2703 while (rec_argv
[j
]) {
2704 pr_debug("%s ", rec_argv
[j
]);
2710 ret
= cmd_record(i
, rec_argv
, NULL
);
2715 int cmd_c2c(int argc
, const char **argv
, const char *prefix __maybe_unused
)
2717 const struct option c2c_options
[] = {
2718 OPT_INCR('v', "verbose", &verbose
, "be more verbose"),
2722 argc
= parse_options(argc
, argv
, c2c_options
, c2c_usage
,
2723 PARSE_OPT_STOP_AT_NON_OPTION
);
2726 usage_with_options(c2c_usage
, c2c_options
);
2728 if (!strncmp(argv
[0], "rec", 3)) {
2729 return perf_c2c__record(argc
, argv
);
2730 } else if (!strncmp(argv
[0], "rep", 3)) {
2731 return perf_c2c__report(argc
, argv
);
2733 usage_with_options(c2c_usage
, c2c_options
);