^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/zalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include "block-info.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "sort.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "annotate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "symbol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "dso.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "srcline.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "evlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "hist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "ui/browsers/hists.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static struct block_header_column {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) int width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) } block_columns[PERF_HPP_REPORT__BLOCK_MAX_INDEX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) [PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) .name = "Sampled Cycles%",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .width = 15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) [PERF_HPP_REPORT__BLOCK_LBR_CYCLES] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .name = "Sampled Cycles",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) .width = 14,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) [PERF_HPP_REPORT__BLOCK_CYCLES_PCT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .name = "Avg Cycles%",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .width = 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) [PERF_HPP_REPORT__BLOCK_AVG_CYCLES] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .name = "Avg Cycles",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .width = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) [PERF_HPP_REPORT__BLOCK_RANGE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .name = "[Program Block Range]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .width = 70,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) [PERF_HPP_REPORT__BLOCK_DSO] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .name = "Shared Object",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .width = 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct block_info *block_info__get(struct block_info *bi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (bi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) refcount_inc(&bi->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return bi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) void block_info__put(struct block_info *bi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (bi && refcount_dec_and_test(&bi->refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) free(bi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct block_info *block_info__new(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct block_info *bi = zalloc(sizeof(*bi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (bi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) refcount_set(&bi->refcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return bi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int64_t __block_info__cmp(struct hist_entry *left, struct hist_entry *right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct block_info *bi_l = left->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct block_info *bi_r = right->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (!bi_l->sym || !bi_r->sym) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (!bi_l->sym && !bi_r->sym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) else if (!bi_l->sym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) cmp = strcmp(bi_l->sym->name, bi_r->sym->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (bi_l->start != bi_r->start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return (int64_t)(bi_r->start - bi_l->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return (int64_t)(bi_r->end - bi_l->end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int64_t block_info__cmp(struct perf_hpp_fmt *fmt __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct hist_entry *left, struct hist_entry *right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return __block_info__cmp(left, right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static void init_block_info(struct block_info *bi, struct symbol *sym,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct cyc_hist *ch, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) u64 total_cycles)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) bi->sym = sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) bi->start = ch->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) bi->end = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) bi->cycles = ch->cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) bi->cycles_aggr = ch->cycles_aggr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bi->num = ch->num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) bi->num_aggr = ch->num_aggr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) bi->total_cycles = total_cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) memcpy(bi->cycles_spark, ch->cycles_spark,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) NUM_SPARKS * sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int block_info__process_sym(struct hist_entry *he, struct block_hist *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) u64 *block_cycles_aggr, u64 total_cycles)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct annotation *notes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct cyc_hist *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static struct addr_location al;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) u64 cycles = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!he->ms.map || !he->ms.sym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) memset(&al, 0, sizeof(al));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) al.map = he->ms.map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) al.sym = he->ms.sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) notes = symbol__annotation(he->ms.sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!notes || !notes->src || !notes->src->cycles_hist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ch = notes->src->cycles_hist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) for (unsigned int i = 0; i < symbol__size(he->ms.sym); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (ch[i].num_aggr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct block_info *bi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct hist_entry *he_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) bi = block_info__new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (!bi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) init_block_info(bi, he->ms.sym, &ch[i], i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) total_cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) cycles += bi->cycles_aggr / bi->num_aggr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) he_block = hists__add_entry_block(&bh->block_hists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) &al, bi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (!he_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) block_info__put(bi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (block_cycles_aggr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) *block_cycles_aggr += cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int block_column_header(struct perf_hpp_fmt *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct perf_hpp *hpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct hists *hists __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int line __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int *span __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) block_fmt->header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int block_column_width(struct perf_hpp_fmt *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct perf_hpp *hpp __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct hists *hists __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return block_fmt->width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int color_pct(struct perf_hpp *hpp, int width, double pct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #ifdef HAVE_SLANG_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (use_browser) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return __hpp__slsmg_color_printf(hpp, "%*.2f%%",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) width - 1, pct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return hpp_color_scnprintf(hpp, "%*.2f%%", width - 1, pct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static int block_total_cycles_pct_entry(struct perf_hpp_fmt *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct perf_hpp *hpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct block_info *bi = he->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) double ratio = 0.0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (block_fmt->total_cycles)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ratio = (double)bi->cycles_aggr / (double)block_fmt->total_cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return color_pct(hpp, block_fmt->width, 100.0 * ratio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int64_t block_total_cycles_pct_sort(struct perf_hpp_fmt *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct hist_entry *left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct hist_entry *right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct block_info *bi_l = left->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct block_info *bi_r = right->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) double l, r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (block_fmt->total_cycles) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) l = ((double)bi_l->cycles_aggr /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) (double)block_fmt->total_cycles) * 100000.0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) r = ((double)bi_r->cycles_aggr /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) (double)block_fmt->total_cycles) * 100000.0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return (int64_t)l - (int64_t)r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static void cycles_string(u64 cycles, char *buf, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (cycles >= 1000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) scnprintf(buf, size, "%.1fM", (double)cycles / 1000000.0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) else if (cycles >= 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) scnprintf(buf, size, "%.1fK", (double)cycles / 1000.0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) scnprintf(buf, size, "%1d", cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static int block_cycles_lbr_entry(struct perf_hpp_fmt *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct perf_hpp *hpp, struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct block_info *bi = he->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) char cycles_buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) cycles_string(bi->cycles_aggr, cycles_buf, sizeof(cycles_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) cycles_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int block_cycles_pct_entry(struct perf_hpp_fmt *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct perf_hpp *hpp, struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct block_info *bi = he->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) double ratio = 0.0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) u64 avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (block_fmt->block_cycles && bi->num_aggr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) avg = bi->cycles_aggr / bi->num_aggr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ratio = (double)avg / (double)block_fmt->block_cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return color_pct(hpp, block_fmt->width, 100.0 * ratio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static int block_avg_cycles_entry(struct perf_hpp_fmt *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct perf_hpp *hpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct block_info *bi = he->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) char cycles_buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) cycles_string(bi->cycles_aggr / bi->num_aggr, cycles_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) sizeof(cycles_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) cycles_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int block_range_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct block_info *bi = he->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) char buf[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) char *start_line, *end_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) symbol_conf.disable_add2line_warn = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) start_line = map__srcline(he->ms.map, bi->sym->start + bi->start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) he->ms.sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) end_line = map__srcline(he->ms.map, bi->sym->start + bi->end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) he->ms.sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if ((strncmp(start_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) (strncmp(end_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) scnprintf(buf, sizeof(buf), "[%s -> %s]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) start_line, end_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) scnprintf(buf, sizeof(buf), "[%7lx -> %7lx]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) bi->start, bi->end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) free_srcline(start_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) free_srcline(end_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int block_dso_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct map *map = he->ms.map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (map && map->dso) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) map->dso->short_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) "[unknown]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static void init_block_header(struct block_fmt *block_fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct perf_hpp_fmt *fmt = &block_fmt->fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) BUG_ON(block_fmt->idx >= PERF_HPP_REPORT__BLOCK_MAX_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) block_fmt->header = block_columns[block_fmt->idx].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) block_fmt->width = block_columns[block_fmt->idx].width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) fmt->header = block_column_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) fmt->width = block_column_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static void hpp_register(struct block_fmt *block_fmt, int idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct perf_hpp_list *hpp_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct perf_hpp_fmt *fmt = &block_fmt->fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) block_fmt->idx = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) INIT_LIST_HEAD(&fmt->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) INIT_LIST_HEAD(&fmt->sort_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) switch (idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) case PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) fmt->color = block_total_cycles_pct_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) fmt->cmp = block_info__cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) fmt->sort = block_total_cycles_pct_sort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) case PERF_HPP_REPORT__BLOCK_LBR_CYCLES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) fmt->entry = block_cycles_lbr_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) case PERF_HPP_REPORT__BLOCK_CYCLES_PCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) fmt->color = block_cycles_pct_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) case PERF_HPP_REPORT__BLOCK_AVG_CYCLES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) fmt->entry = block_avg_cycles_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) case PERF_HPP_REPORT__BLOCK_RANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) fmt->entry = block_range_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) case PERF_HPP_REPORT__BLOCK_DSO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) fmt->entry = block_dso_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) init_block_header(block_fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) perf_hpp_list__column_register(hpp_list, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static void register_block_columns(struct perf_hpp_list *hpp_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct block_fmt *block_fmts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) int *block_hpps, int nr_hpps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) for (int i = 0; i < nr_hpps; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) hpp_register(&block_fmts[i], block_hpps[i], hpp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static void init_block_hist(struct block_hist *bh, struct block_fmt *block_fmts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int *block_hpps, int nr_hpps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) __hists__init(&bh->block_hists, &bh->block_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) perf_hpp_list__init(&bh->block_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) bh->block_list.nr_header_lines = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) register_block_columns(&bh->block_list, block_fmts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) block_hpps, nr_hpps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* Sort by the first fmt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) perf_hpp_list__register_sort_field(&bh->block_list, &block_fmts[0].fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static int process_block_report(struct hists *hists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct block_report *block_report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) u64 total_cycles, int *block_hpps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) int nr_hpps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct rb_node *next = rb_first_cached(&hists->entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct block_hist *bh = &block_report->hist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (nr_hpps > PERF_HPP_REPORT__BLOCK_MAX_INDEX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) block_report->nr_fmts = nr_hpps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) init_block_hist(bh, block_report->fmts, block_hpps, nr_hpps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) while (next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) he = rb_entry(next, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) block_info__process_sym(he, bh, &block_report->cycles,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) total_cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) next = rb_next(&he->rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) for (int i = 0; i < nr_hpps; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) block_report->fmts[i].total_cycles = total_cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) block_report->fmts[i].block_cycles = block_report->cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) hists__output_resort(&bh->block_hists, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct block_report *block_info__create_report(struct evlist *evlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) u64 total_cycles,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) int *block_hpps, int nr_hpps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) int *nr_reps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct block_report *block_reports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) int nr_hists = evlist->core.nr_entries, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct evsel *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) block_reports = calloc(nr_hists, sizeof(struct block_report));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (!block_reports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) evlist__for_each_entry(evlist, pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct hists *hists = evsel__hists(pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) process_block_report(hists, &block_reports[i], total_cycles,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) block_hpps, nr_hpps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) *nr_reps = nr_hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return block_reports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) void block_info__free_report(struct block_report *reps, int nr_reps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) for (int i = 0; i < nr_reps; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) hists__delete_entries(&reps[i].hist.block_hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) free(reps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) int report__browse_block_hists(struct block_hist *bh, float min_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) struct evsel *evsel, struct perf_env *env,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct annotation_options *annotation_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) switch (use_browser) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) symbol_conf.report_individual_block = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) hists__fprintf(&bh->block_hists, true, 0, 0, min_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) stdout, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) symbol_conf.report_individual_block = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) ret = block_hists_tui_browse(bh, evsel, min_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) env, annotation_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) float block_info__total_cycles_percent(struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct block_info *bi = he->block_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (bi->total_cycles)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return bi->cycles * 100.0 / bi->total_cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) return 0.0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }