^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 <dirent.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <inttypes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sys/ttydefaults.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/time64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/zalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "../../util/debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "../../util/dso.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "../../util/callchain.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "../../util/evsel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "../../util/evlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "../../util/header.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "../../util/hist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "../../util/machine.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "../../util/map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "../../util/maps.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "../../util/symbol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "../../util/map_symbol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "../../util/branch.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "../../util/pstack.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "../../util/sort.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "../../util/top.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "../../util/thread.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "../../util/block-info.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "../../arch/common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "../../perf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "../browsers/hists.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "../helpline.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "../util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include "../ui.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "annotate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "srcline.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "string2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "units.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include "time-utils.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) extern void hist_browser__init_hpp(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int hists_browser__scnprintf_title(struct hist_browser *browser, char *bf, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static void hist_browser__update_nr_entries(struct hist_browser *hb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static struct rb_node *hists__filter_entries(struct rb_node *nd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) float min_pcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static bool hist_browser__has_filter(struct hist_browser *hb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return hists__has_filter(hb->hists) || hb->min_pcnt || symbol_conf.has_filter || hb->c2c_filter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static int hist_browser__get_folding(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct hists *hists = browser->hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int unfolded_rows = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) for (nd = rb_first_cached(&hists->entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) (nd = hists__filter_entries(nd, browser->min_pcnt)) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) nd = rb_hierarchy_next(nd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct hist_entry *he =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (he->leaf && he->unfolded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) unfolded_rows += he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return unfolded_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static void hist_browser__set_title_space(struct hist_browser *hb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct ui_browser *browser = &hb->b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct hists *hists = hb->hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct perf_hpp_list *hpp_list = hists->hpp_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) browser->extra_title_lines = hb->show_headers ? hpp_list->nr_header_lines : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static u32 hist_browser__nr_entries(struct hist_browser *hb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u32 nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (symbol_conf.report_hierarchy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) nr_entries = hb->nr_hierarchy_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) else if (hist_browser__has_filter(hb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) nr_entries = hb->nr_non_filtered_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) nr_entries = hb->hists->nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) hb->nr_callchain_rows = hist_browser__get_folding(hb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return nr_entries + hb->nr_callchain_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static void hist_browser__update_rows(struct hist_browser *hb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct ui_browser *browser = &hb->b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct hists *hists = hb->hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct perf_hpp_list *hpp_list = hists->hpp_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) u16 index_row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (!hb->show_headers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) browser->rows += browser->extra_title_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) browser->extra_title_lines = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return;
^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) browser->extra_title_lines = hpp_list->nr_header_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) browser->rows -= browser->extra_title_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Verify if we were at the last line and that line isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * visibe because we now show the header line(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) index_row = browser->index - browser->top_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (index_row >= browser->rows)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) browser->index -= index_row - browser->rows + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static void hist_browser__refresh_dimensions(struct ui_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct hist_browser *hb = container_of(browser, struct hist_browser, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* 3 == +/- toggle symbol before actual hist_entry rendering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) browser->width = 3 + (hists__sort_list_width(hb->hists) + sizeof("[k]"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * FIXME: Just keeping existing behaviour, but this really should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * before updating browser->width, as it will invalidate the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * calculation above. Fix this and the fallout in another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * changeset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ui_browser__refresh_dimensions(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void hist_browser__reset(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * The hists__remove_entry_filter() already folds non-filtered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * entries so we can assume it has 0 callchain rows.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) browser->nr_callchain_rows = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) hist_browser__update_nr_entries(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) browser->b.nr_entries = hist_browser__nr_entries(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) hist_browser__refresh_dimensions(&browser->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ui_browser__reset_index(&browser->b);
^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) static char tree__folded_sign(bool unfolded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return unfolded ? '-' : '+';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static char hist_entry__folded(const struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return he->has_children ? tree__folded_sign(he->unfolded) : ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static char callchain_list__folded(const struct callchain_list *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return cl->has_children ? tree__folded_sign(cl->unfolded) : ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static void callchain_list__set_folding(struct callchain_list *cl, bool unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) cl->unfolded = unfold ? cl->has_children : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int callchain_node__count_rows_rb_tree(struct callchain_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) char folded_sign = ' '; /* No children */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) list_for_each_entry(chain, &child->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ++n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* We need this because we may not have children */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) folded_sign = callchain_list__folded(chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (folded_sign == '+')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) break;
^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) if (folded_sign == '-') /* Have children and they're unfolded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) n += callchain_node__count_rows_rb_tree(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static int callchain_node__count_flat_rows(struct callchain_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) char folded_sign = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) list_for_each_entry(chain, &node->parent_val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!folded_sign) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* only check first chain list entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) folded_sign = callchain_list__folded(chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (folded_sign == '+')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) list_for_each_entry(chain, &node->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (!folded_sign) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* node->parent_val list might be empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) folded_sign = callchain_list__folded(chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (folded_sign == '+')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static int callchain_node__count_folded_rows(struct callchain_node *node __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static int callchain_node__count_rows(struct callchain_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) bool unfolded = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (callchain_param.mode == CHAIN_FLAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return callchain_node__count_flat_rows(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) else if (callchain_param.mode == CHAIN_FOLDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return callchain_node__count_folded_rows(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) list_for_each_entry(chain, &node->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ++n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) unfolded = chain->unfolded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (unfolded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) n += callchain_node__count_rows_rb_tree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static int callchain__count_rows(struct rb_root *chain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) for (nd = rb_first(chain); nd; nd = rb_next(nd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) n += callchain_node__count_rows(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static int hierarchy_count_rows(struct hist_browser *hb, struct hist_entry *he,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) bool include_children)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct hist_entry *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (he->leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return callchain__count_rows(&he->sorted_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (he->has_no_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) node = rb_first_cached(&he->hroot_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) while (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) float percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) child = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) percent = hist_entry__get_percent_limit(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (!child->filtered && percent >= hb->min_pcnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (include_children && child->unfolded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) count += hierarchy_count_rows(hb, child, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static bool hist_entry__toggle_fold(struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (!he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (!he->has_children)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) he->unfolded = !he->unfolded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static bool callchain_list__toggle_fold(struct callchain_list *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (!cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (!cl->has_children)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) cl->unfolded = !cl->unfolded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static void callchain_node__init_have_children_rb_tree(struct callchain_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct rb_node *nd = rb_first(&node->rb_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) list_for_each_entry(chain, &child->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) chain->has_children = chain->list.next != &child->val ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) !RB_EMPTY_ROOT(&child->rb_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) chain->has_children = chain->list.next == &child->val &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) !RB_EMPTY_ROOT(&child->rb_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) callchain_node__init_have_children_rb_tree(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static void callchain_node__init_have_children(struct callchain_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) bool has_sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) chain = list_entry(node->val.next, struct callchain_list, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) chain->has_children = has_sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (!list_empty(&node->val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) chain = list_entry(node->val.prev, struct callchain_list, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) chain->has_children = !RB_EMPTY_ROOT(&node->rb_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) callchain_node__init_have_children_rb_tree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static void callchain__init_have_children(struct rb_root *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct rb_node *nd = rb_first(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) bool has_sibling = nd && rb_next(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) for (nd = rb_first(root); nd; nd = rb_next(nd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) callchain_node__init_have_children(node, has_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (callchain_param.mode == CHAIN_FLAT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) callchain_param.mode == CHAIN_FOLDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) callchain_node__make_parent_list(node);
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static void hist_entry__init_have_children(struct hist_entry *he)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (he->init_have_children)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (he->leaf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) he->has_children = !RB_EMPTY_ROOT(&he->sorted_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) callchain__init_have_children(&he->sorted_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) he->has_children = !RB_EMPTY_ROOT(&he->hroot_out.rb_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) he->init_have_children = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static bool hist_browser__selection_has_children(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) struct hist_entry *he = browser->he_selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct map_symbol *ms = browser->selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (!he || !ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (ms == &he->ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return he->has_children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return container_of(ms, struct callchain_list, ms)->has_children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static bool hist_browser__he_selection_unfolded(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return browser->he_selection ? browser->he_selection->unfolded : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static bool hist_browser__selection_unfolded(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct hist_entry *he = browser->he_selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct map_symbol *ms = browser->selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (!he || !ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (ms == &he->ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return he->unfolded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return container_of(ms, struct callchain_list, ms)->unfolded;
^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) static char *hist_browser__selection_sym_name(struct hist_browser *browser, char *bf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct hist_entry *he = browser->he_selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct map_symbol *ms = browser->selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct callchain_list *callchain_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (!he || !ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (ms == &he->ms) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) hist_entry__sym_snprintf(he, bf, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return bf + 4; // skip the level, e.g. '[k] '
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) callchain_entry = container_of(ms, struct callchain_list, ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) return callchain_list__sym_name(callchain_entry, bf, size, browser->show_dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) static bool hist_browser__toggle_fold(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct hist_entry *he = browser->he_selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) struct map_symbol *ms = browser->selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct callchain_list *cl = container_of(ms, struct callchain_list, ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) bool has_children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (!he || !ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (ms == &he->ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) has_children = hist_entry__toggle_fold(he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) has_children = callchain_list__toggle_fold(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) if (has_children) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) int child_rows = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) hist_entry__init_have_children(he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) browser->b.nr_entries -= he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (he->leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) browser->nr_callchain_rows -= he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) browser->nr_hierarchy_entries -= he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (symbol_conf.report_hierarchy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) child_rows = hierarchy_count_rows(browser, he, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (he->unfolded) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (he->leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) he->nr_rows = callchain__count_rows(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) &he->sorted_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) he->nr_rows = hierarchy_count_rows(browser, he, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /* account grand children */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (symbol_conf.report_hierarchy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) browser->b.nr_entries += child_rows - he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (!he->leaf && he->nr_rows == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) he->has_no_entry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) he->nr_rows = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (symbol_conf.report_hierarchy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) browser->b.nr_entries -= child_rows - he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (he->has_no_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) he->has_no_entry = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) he->nr_rows = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) browser->b.nr_entries += he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (he->leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) browser->nr_callchain_rows += he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) browser->nr_hierarchy_entries += he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /* If it doesn't have children, no toggling performed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static int callchain_node__set_folding_rb_tree(struct callchain_node *node, bool unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) bool has_children = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) list_for_each_entry(chain, &child->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) ++n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) callchain_list__set_folding(chain, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) has_children = chain->has_children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (has_children)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) n += callchain_node__set_folding_rb_tree(child, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static int callchain_node__set_folding(struct callchain_node *node, bool unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) bool has_children = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) list_for_each_entry(chain, &node->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) ++n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) callchain_list__set_folding(chain, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) has_children = chain->has_children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (has_children)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) n += callchain_node__set_folding_rb_tree(node, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static int callchain__set_folding(struct rb_root *chain, bool unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) for (nd = rb_first(chain); nd; nd = rb_next(nd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) n += callchain_node__set_folding(node, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static int hierarchy_set_folding(struct hist_browser *hb, struct hist_entry *he,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) bool unfold __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) float percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct hist_entry *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) for (nd = rb_first_cached(&he->hroot_out); nd; nd = rb_next(nd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) child = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) percent = hist_entry__get_percent_limit(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!child->filtered && percent >= hb->min_pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static void __hist_entry__set_folding(struct hist_entry *he,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) struct hist_browser *hb, bool unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) hist_entry__init_have_children(he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) he->unfolded = unfold ? he->has_children : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (he->has_children) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (he->leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) n = callchain__set_folding(&he->sorted_chain, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) n = hierarchy_set_folding(hb, he, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) he->nr_rows = unfold ? n : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) he->nr_rows = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) static void hist_entry__set_folding(struct hist_entry *he,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) struct hist_browser *browser, bool unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) double percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) percent = hist_entry__get_percent_limit(he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (he->filtered || percent < browser->min_pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) __hist_entry__set_folding(he, browser, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (!he->depth || unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) browser->nr_hierarchy_entries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) if (he->leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) browser->nr_callchain_rows += he->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) else if (unfold && !hist_entry__has_hierarchy_children(he, browser->min_pcnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) browser->nr_hierarchy_entries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) he->has_no_entry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) he->nr_rows = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) he->has_no_entry = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) __hist_browser__set_folding(struct hist_browser *browser, bool unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) nd = rb_first_cached(&browser->hists->entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) while (nd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) he = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) /* set folding state even if it's currently folded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) nd = __rb_hierarchy_next(nd, HMD_FORCE_CHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) hist_entry__set_folding(he, browser, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static void hist_browser__set_folding(struct hist_browser *browser, bool unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) browser->nr_hierarchy_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) browser->nr_callchain_rows = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) __hist_browser__set_folding(browser, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) browser->b.nr_entries = hist_browser__nr_entries(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) /* Go to the start, we may be way after valid entries after a collapse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) ui_browser__reset_index(&browser->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static void hist_browser__set_folding_selected(struct hist_browser *browser, bool unfold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (!browser->he_selection)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) hist_entry__set_folding(browser->he_selection, browser, unfold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) browser->b.nr_entries = hist_browser__nr_entries(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) static void ui_browser__warn_lost_events(struct ui_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) ui_browser__warning(browser, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) "Events are being lost, check IO/CPU overload!\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) "You may want to run 'perf' using a RT scheduler policy:\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) " perf top -r 80\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) "Or reduce the sampling frequency.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) static int hist_browser__title(struct hist_browser *browser, char *bf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) return browser->title ? browser->title(browser, bf, size) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) static int hist_browser__handle_hotkey(struct hist_browser *browser, bool warn_lost_event, char *title, size_t size, int key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) case K_TIMER: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) struct hist_browser_timer *hbt = browser->hbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) u64 nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) WARN_ON_ONCE(!hbt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (hbt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) hbt->timer(hbt->arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (hist_browser__has_filter(browser) || symbol_conf.report_hierarchy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) hist_browser__update_nr_entries(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) nr_entries = hist_browser__nr_entries(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) ui_browser__update_nr_entries(&browser->b, nr_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (warn_lost_event &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) (browser->hists->stats.nr_lost_warned !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) browser->hists->stats.nr_events[PERF_RECORD_LOST])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) browser->hists->stats.nr_lost_warned =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) browser->hists->stats.nr_events[PERF_RECORD_LOST];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) ui_browser__warn_lost_events(&browser->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) hist_browser__title(browser, title, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) ui_browser__show_title(&browser->b, title);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) case 'D': { /* Debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) struct hist_entry *h = rb_entry(browser->b.top, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static int seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) ui_helpline__pop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) ui_helpline__fpush("%d: nr_ent=(%d,%d), etl: %d, rows=%d, idx=%d, fve: idx=%d, row_off=%d, nrows=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) seq++, browser->b.nr_entries, browser->hists->nr_entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) browser->b.extra_title_lines, browser->b.rows,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) browser->b.index, browser->b.top_idx, h->row_offset, h->nr_rows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) case 'C':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /* Collapse the whole world. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) hist_browser__set_folding(browser, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) case 'c':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) /* Collapse the selected entry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) hist_browser__set_folding_selected(browser, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) case 'E':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /* Expand the whole world. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) hist_browser__set_folding(browser, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) case 'e':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) /* Expand the selected entry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) hist_browser__set_folding_selected(browser, !hist_browser__he_selection_unfolded(browser));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) case 'H':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) browser->show_headers = !browser->show_headers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) hist_browser__update_rows(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) case '+':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (hist_browser__toggle_fold(browser))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /* fall thru */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) int hist_browser__run(struct hist_browser *browser, const char *help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) bool warn_lost_event, int key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) char title[160];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) struct hist_browser_timer *hbt = browser->hbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) int delay_secs = hbt ? hbt->refresh : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) browser->b.entries = &browser->hists->entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) browser->b.nr_entries = hist_browser__nr_entries(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) hist_browser__title(browser, title, sizeof(title));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (ui_browser__show(&browser->b, title, "%s", help) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (key && hist_browser__handle_hotkey(browser, warn_lost_event, title, sizeof(title), key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) key = ui_browser__run(&browser->b, delay_secs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (hist_browser__handle_hotkey(browser, warn_lost_event, title, sizeof(title), key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) ui_browser__hide(&browser->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) struct callchain_print_arg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) /* for hists browser */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) off_t row_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) bool is_current_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) /* for file dump */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) FILE *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) int printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) typedef void (*print_callchain_entry_fn)(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) struct callchain_list *chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) const char *str, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) unsigned short row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct callchain_print_arg *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) static void hist_browser__show_callchain_entry(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) struct callchain_list *chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) const char *str, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) unsigned short row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) struct callchain_print_arg *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) int color, width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) char folded_sign = callchain_list__folded(chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) bool show_annotated = browser->show_dso && chain->ms.sym && symbol__annotation(chain->ms.sym)->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) color = HE_COLORSET_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) width = browser->b.width - (offset + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (ui_browser__is_current_entry(&browser->b, row)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) browser->selection = &chain->ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) color = HE_COLORSET_SELECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) arg->is_current_entry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) ui_browser__set_color(&browser->b, color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) ui_browser__gotorc(&browser->b, row, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) ui_browser__write_nstring(&browser->b, " ", offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) ui_browser__printf(&browser->b, "%c", folded_sign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) ui_browser__write_graph(&browser->b, show_annotated ? SLSMG_RARROW_CHAR : ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) ui_browser__write_nstring(&browser->b, str, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) static void hist_browser__fprintf_callchain_entry(struct hist_browser *b __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) struct callchain_list *chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) const char *str, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) unsigned short row __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) struct callchain_print_arg *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) char folded_sign = callchain_list__folded(chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) arg->printed += fprintf(arg->fp, "%*s%c %s\n", offset, " ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) folded_sign, str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) typedef bool (*check_output_full_fn)(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) unsigned short row);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) static bool hist_browser__check_output_full(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) unsigned short row)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) return browser->b.rows == row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) static bool hist_browser__check_dump_full(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) unsigned short row __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) #define LEVEL_OFFSET_STEP 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) static int hist_browser__show_callchain_list(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct callchain_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct callchain_list *chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) unsigned short row, u64 total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) bool need_percent, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) print_callchain_entry_fn print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) struct callchain_print_arg *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) char bf[1024], *alloc_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) char buf[64], *alloc_str2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) const char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) int ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (arg->row_offset != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) arg->row_offset--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) alloc_str = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) alloc_str2 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) str = callchain_list__sym_name(chain, bf, sizeof(bf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) browser->show_dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (symbol_conf.show_branchflag_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) callchain_list_counts__printf_value(chain, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (asprintf(&alloc_str2, "%s%s", str, buf) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) str = "Not enough memory!";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) str = alloc_str2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) if (need_percent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) callchain_node__scnprintf_value(node, buf, sizeof(buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if (asprintf(&alloc_str, "%s %s", buf, str) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) str = "Not enough memory!";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) str = alloc_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) print(browser, chain, str, offset, row, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) free(alloc_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) free(alloc_str2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) static bool check_percent_display(struct rb_node *node, u64 parent_total)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) struct callchain_node *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) if (node == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (rb_next(node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) child = rb_entry(node, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) return callchain_cumul_hits(child) != parent_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) static int hist_browser__show_callchain_flat(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) struct rb_root *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) unsigned short row, u64 total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) u64 parent_total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) print_callchain_entry_fn print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) struct callchain_print_arg *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) check_output_full_fn is_output_full)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) int first_row = row, offset = LEVEL_OFFSET_STEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) bool need_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) node = rb_first(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) need_percent = check_percent_display(node, parent_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) while (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct rb_node *next = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) char folded_sign = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) int first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) int extra_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) list_for_each_entry(chain, &child->parent_val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) bool was_first = first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) if (first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) else if (need_percent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) extra_offset = LEVEL_OFFSET_STEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) folded_sign = callchain_list__folded(chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) row += hist_browser__show_callchain_list(browser, child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) chain, row, total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) was_first && need_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) offset + extra_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) print, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) if (is_output_full(browser, row))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (folded_sign == '+')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) list_for_each_entry(chain, &child->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) bool was_first = first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) else if (need_percent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) extra_offset = LEVEL_OFFSET_STEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) folded_sign = callchain_list__folded(chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) row += hist_browser__show_callchain_list(browser, child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) chain, row, total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) was_first && need_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) offset + extra_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) print, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) if (is_output_full(browser, row))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) if (folded_sign == '+')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) if (is_output_full(browser, row))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) node = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) return row - first_row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) static char *hist_browser__folded_callchain_str(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) struct callchain_list *chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) char *value_str, char *old_str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) char bf[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) const char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) char *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) str = callchain_list__sym_name(chain, bf, sizeof(bf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) browser->show_dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (old_str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (asprintf(&new, "%s%s%s", old_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) symbol_conf.field_sep ?: ";", str) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) new = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) if (value_str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) if (asprintf(&new, "%s %s", value_str, str) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) new = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) if (asprintf(&new, "%s", str) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) new = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) return new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) static int hist_browser__show_callchain_folded(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) struct rb_root *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) unsigned short row, u64 total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) u64 parent_total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) print_callchain_entry_fn print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) struct callchain_print_arg *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) check_output_full_fn is_output_full)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) int first_row = row, offset = LEVEL_OFFSET_STEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) bool need_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) node = rb_first(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) need_percent = check_percent_display(node, parent_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) while (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) struct rb_node *next = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) struct callchain_list *chain, *first_chain = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) int first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) char *value_str = NULL, *value_str_alloc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) char *chain_str = NULL, *chain_str_alloc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (arg->row_offset != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) arg->row_offset--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (need_percent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) char buf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) callchain_node__scnprintf_value(child, buf, sizeof(buf), total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) if (asprintf(&value_str, "%s", buf) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) value_str = (char *)"<...>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) goto do_print;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) value_str_alloc = value_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) list_for_each_entry(chain, &child->parent_val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) chain_str = hist_browser__folded_callchain_str(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) chain, value_str, chain_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) first_chain = chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) if (chain_str == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) chain_str = (char *)"Not enough memory!";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) goto do_print;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) chain_str_alloc = chain_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) list_for_each_entry(chain, &child->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) chain_str = hist_browser__folded_callchain_str(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) chain, value_str, chain_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) first_chain = chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) if (chain_str == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) chain_str = (char *)"Not enough memory!";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) goto do_print;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) chain_str_alloc = chain_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) do_print:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) print(browser, first_chain, chain_str, offset, row++, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) free(value_str_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) free(chain_str_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (is_output_full(browser, row))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) node = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) return row - first_row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) static int hist_browser__show_callchain_graph(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) struct rb_root *root, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) unsigned short row, u64 total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) u64 parent_total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) print_callchain_entry_fn print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) struct callchain_print_arg *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) check_output_full_fn is_output_full)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) int first_row = row, offset = level * LEVEL_OFFSET_STEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) bool need_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) u64 percent_total = total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) if (callchain_param.mode == CHAIN_GRAPH_REL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) percent_total = parent_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) node = rb_first(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) need_percent = check_percent_display(node, parent_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) while (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) struct rb_node *next = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) char folded_sign = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) int first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) int extra_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) list_for_each_entry(chain, &child->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) bool was_first = first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) if (first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) else if (need_percent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) extra_offset = LEVEL_OFFSET_STEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) folded_sign = callchain_list__folded(chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) row += hist_browser__show_callchain_list(browser, child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) chain, row, percent_total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) was_first && need_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) offset + extra_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) print, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) if (is_output_full(browser, row))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) if (folded_sign == '+')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) if (folded_sign == '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) const int new_level = level + (extra_offset ? 2 : 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) row += hist_browser__show_callchain_graph(browser, &child->rb_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) new_level, row, total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) child->children_hit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) print, arg, is_output_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) if (is_output_full(browser, row))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) node = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) return row - first_row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) static int hist_browser__show_callchain(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) struct hist_entry *entry, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) unsigned short row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) print_callchain_entry_fn print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) struct callchain_print_arg *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) check_output_full_fn is_output_full)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) u64 total = hists__total_period(entry->hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) u64 parent_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) int printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) if (symbol_conf.cumulate_callchain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) parent_total = entry->stat_acc->period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) parent_total = entry->stat.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) if (callchain_param.mode == CHAIN_FLAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) printed = hist_browser__show_callchain_flat(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) &entry->sorted_chain, row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) total, parent_total, print, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) is_output_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) } else if (callchain_param.mode == CHAIN_FOLDED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) printed = hist_browser__show_callchain_folded(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) &entry->sorted_chain, row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) total, parent_total, print, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) is_output_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) printed = hist_browser__show_callchain_graph(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) &entry->sorted_chain, level, row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) total, parent_total, print, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) is_output_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) if (arg->is_current_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) browser->he_selection = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) return printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) struct hpp_arg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) struct ui_browser *b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) char folded_sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) bool current_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) struct hpp_arg *arg = hpp->ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) int ret, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) double percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) len = va_arg(args, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) percent = va_arg(args, double);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) ui_browser__set_percent_color(arg->b, percent, arg->current_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) ret = scnprintf(hpp->buf, hpp->size, fmt, len, percent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) ui_browser__printf(arg->b, "%s", hpp->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) #define __HPP_COLOR_PERCENT_FN(_type, _field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) static u64 __hpp_get_##_field(struct hist_entry *he) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) return he->stat._field; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) static int \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) struct perf_hpp *hpp, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) struct hist_entry *he) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) return hpp__fmt(fmt, hpp, he, __hpp_get_##_field, " %*.2f%%", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) __hpp__slsmg_color_printf, true); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) static u64 __hpp_get_acc_##_field(struct hist_entry *he) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) return he->stat_acc->_field; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) static int \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) struct perf_hpp *hpp, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) struct hist_entry *he) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) if (!symbol_conf.cumulate_callchain) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) struct hpp_arg *arg = hpp->ptr; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) int len = fmt->user_len ?: fmt->len; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) int ret = scnprintf(hpp->buf, hpp->size, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) "%*s", len, "N/A"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) ui_browser__printf(arg->b, "%s", hpp->buf); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) return ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) return hpp__fmt(fmt, hpp, he, __hpp_get_acc_##_field, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) " %*.2f%%", __hpp__slsmg_color_printf, true); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) __HPP_COLOR_PERCENT_FN(overhead, period)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) __HPP_COLOR_PERCENT_FN(overhead_us, period_us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) __HPP_COLOR_ACC_PERCENT_FN(overhead_acc, period)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) #undef __HPP_COLOR_PERCENT_FN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) #undef __HPP_COLOR_ACC_PERCENT_FN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) void hist_browser__init_hpp(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) perf_hpp__format[PERF_HPP__OVERHEAD].color =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) hist_browser__hpp_color_overhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) hist_browser__hpp_color_overhead_sys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) perf_hpp__format[PERF_HPP__OVERHEAD_US].color =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) hist_browser__hpp_color_overhead_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) hist_browser__hpp_color_overhead_guest_sys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) hist_browser__hpp_color_overhead_guest_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) perf_hpp__format[PERF_HPP__OVERHEAD_ACC].color =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) hist_browser__hpp_color_overhead_acc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) res_sample_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) static int hist_browser__show_entry(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) struct hist_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) unsigned short row)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) int printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) int width = browser->b.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) char folded_sign = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) bool current_entry = ui_browser__is_current_entry(&browser->b, row);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) bool use_callchain = hist_entry__has_callchains(entry) && symbol_conf.use_callchain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) off_t row_offset = entry->row_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) if (current_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) browser->he_selection = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) browser->selection = &entry->ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (use_callchain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) hist_entry__init_have_children(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) folded_sign = hist_entry__folded(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) if (row_offset == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) struct hpp_arg arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) .b = &browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) .folded_sign = folded_sign,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) .current_entry = current_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) int column = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) ui_browser__gotorc(&browser->b, row, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) hists__for_each_format(browser->hists, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) char s[2048];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) struct perf_hpp hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) .buf = s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) .size = sizeof(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) .ptr = &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) if (perf_hpp__should_skip(fmt, entry->hists) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) column++ < browser->b.horiz_scroll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) if (current_entry && browser->b.navkeypressed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) ui_browser__set_color(&browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) HE_COLORSET_SELECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) ui_browser__set_color(&browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) HE_COLORSET_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) if (use_callchain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) ui_browser__printf(&browser->b, "%c ", folded_sign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) width -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) ui_browser__printf(&browser->b, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) width -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) if (fmt->color) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) int ret = fmt->color(fmt, &hpp, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) hist_entry__snprintf_alignment(entry, &hpp, fmt, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) * fmt->color() already used ui_browser to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) * print the non alignment bits, skip it (+ret):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) ui_browser__printf(&browser->b, "%s", s + ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) hist_entry__snprintf_alignment(entry, &hpp, fmt, fmt->entry(fmt, &hpp, entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) ui_browser__printf(&browser->b, "%s", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) width -= hpp.buf - s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) /* The scroll bar isn't being used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) if (!browser->b.navkeypressed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) width += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) ui_browser__write_nstring(&browser->b, "", width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) ++row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) ++printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) --row_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) if (folded_sign == '-' && row != browser->b.rows) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) struct callchain_print_arg arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) .row_offset = row_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) .is_current_entry = current_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) printed += hist_browser__show_callchain(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) entry, 1, row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) hist_browser__show_callchain_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) hist_browser__check_output_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) return printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) static int hist_browser__show_hierarchy_entry(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) struct hist_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) unsigned short row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) int printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) int width = browser->b.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) char folded_sign = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) bool current_entry = ui_browser__is_current_entry(&browser->b, row);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) off_t row_offset = entry->row_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) struct perf_hpp_list_node *fmt_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) struct hpp_arg arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) .b = &browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) .current_entry = current_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) int column = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) int hierarchy_indent = (entry->hists->nr_hpp_node - 2) * HIERARCHY_INDENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) if (current_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) browser->he_selection = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) browser->selection = &entry->ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) hist_entry__init_have_children(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) folded_sign = hist_entry__folded(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) arg.folded_sign = folded_sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) if (entry->leaf && row_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) row_offset--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) goto show_callchain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) ui_browser__gotorc(&browser->b, row, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) if (current_entry && browser->b.navkeypressed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) ui_browser__set_color(&browser->b, HE_COLORSET_SELECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) ui_browser__write_nstring(&browser->b, "", level * HIERARCHY_INDENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) width -= level * HIERARCHY_INDENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) /* the first hpp_list_node is for overhead columns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) fmt_node = list_first_entry(&entry->hists->hpp_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) struct perf_hpp_list_node, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) char s[2048];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) struct perf_hpp hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) .buf = s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) .size = sizeof(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) .ptr = &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) if (perf_hpp__should_skip(fmt, entry->hists) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) column++ < browser->b.horiz_scroll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) if (current_entry && browser->b.navkeypressed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) ui_browser__set_color(&browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) HE_COLORSET_SELECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) ui_browser__set_color(&browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) HE_COLORSET_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) ui_browser__printf(&browser->b, "%c ", folded_sign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) width -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) ui_browser__printf(&browser->b, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) width -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) if (fmt->color) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) int ret = fmt->color(fmt, &hpp, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) hist_entry__snprintf_alignment(entry, &hpp, fmt, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) * fmt->color() already used ui_browser to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) * print the non alignment bits, skip it (+ret):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) ui_browser__printf(&browser->b, "%s", s + ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) int ret = fmt->entry(fmt, &hpp, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) hist_entry__snprintf_alignment(entry, &hpp, fmt, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) ui_browser__printf(&browser->b, "%s", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) width -= hpp.buf - s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) if (!first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) ui_browser__write_nstring(&browser->b, "", hierarchy_indent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) width -= hierarchy_indent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) if (column >= browser->b.horiz_scroll) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) char s[2048];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) struct perf_hpp hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) .buf = s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) .size = sizeof(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) .ptr = &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) if (current_entry && browser->b.navkeypressed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) ui_browser__set_color(&browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) HE_COLORSET_SELECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) ui_browser__set_color(&browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) HE_COLORSET_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) perf_hpp_list__for_each_format(entry->hpp_list, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) ui_browser__printf(&browser->b, "%c ", folded_sign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) ui_browser__write_nstring(&browser->b, "", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) width -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) * No need to call hist_entry__snprintf_alignment()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) * since this fmt is always the last column in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) * hierarchy mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) if (fmt->color) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) width -= fmt->color(fmt, &hpp, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) width -= fmt->entry(fmt, &hpp, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) ui_browser__printf(&browser->b, "%s", skip_spaces(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) while (isspace(s[i++]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) width++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) /* The scroll bar isn't being used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) if (!browser->b.navkeypressed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) width += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) ui_browser__write_nstring(&browser->b, "", width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) ++row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) ++printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) show_callchain:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) if (entry->leaf && folded_sign == '-' && row != browser->b.rows) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) struct callchain_print_arg carg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) .row_offset = row_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) printed += hist_browser__show_callchain(browser, entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) level + 1, row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) hist_browser__show_callchain_entry, &carg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) hist_browser__check_output_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) return printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) static int hist_browser__show_no_entry(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) unsigned short row, int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) int width = browser->b.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) bool current_entry = ui_browser__is_current_entry(&browser->b, row);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) int column = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) struct perf_hpp_list_node *fmt_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) int indent = browser->hists->nr_hpp_node - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) if (current_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) browser->he_selection = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) browser->selection = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) ui_browser__gotorc(&browser->b, row, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) if (current_entry && browser->b.navkeypressed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) ui_browser__set_color(&browser->b, HE_COLORSET_SELECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) ui_browser__write_nstring(&browser->b, "", level * HIERARCHY_INDENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) width -= level * HIERARCHY_INDENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) /* the first hpp_list_node is for overhead columns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) fmt_node = list_first_entry(&browser->hists->hpp_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) struct perf_hpp_list_node, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) if (perf_hpp__should_skip(fmt, browser->hists) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) column++ < browser->b.horiz_scroll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) ret = fmt->width(fmt, NULL, browser->hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) /* for folded sign */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) ret++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) /* space between columns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) ret += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) ui_browser__write_nstring(&browser->b, "", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) width -= ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) ui_browser__write_nstring(&browser->b, "", indent * HIERARCHY_INDENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) width -= indent * HIERARCHY_INDENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) if (column >= browser->b.horiz_scroll) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) char buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) ret = snprintf(buf, sizeof(buf), "no entry >= %.2f%%", browser->min_pcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) ui_browser__printf(&browser->b, " %s", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) width -= ret + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) /* The scroll bar isn't being used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) if (!browser->b.navkeypressed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) width += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) ui_browser__write_nstring(&browser->b, "", width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) static int advance_hpp_check(struct perf_hpp *hpp, int inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) advance_hpp(hpp, inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) return hpp->size <= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) hists_browser__scnprintf_headers(struct hist_browser *browser, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) size_t size, int line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) struct hists *hists = browser->hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) struct perf_hpp dummy_hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) .buf = buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) .size = size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) int column = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) int span = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) if (hists__has_callchains(hists) && symbol_conf.use_callchain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) ret = scnprintf(buf, size, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) hists__for_each_format(browser->hists, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) if (perf_hpp__should_skip(fmt, hists) || column++ < browser->b.horiz_scroll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) ret = fmt->header(fmt, &dummy_hpp, hists, line, &span);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) if (span)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) static int hists_browser__scnprintf_hierarchy_headers(struct hist_browser *browser, char *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) struct hists *hists = browser->hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) struct perf_hpp dummy_hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) .buf = buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) .size = size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) struct perf_hpp_list_node *fmt_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) int column = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) int indent = hists->nr_hpp_node - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) bool first_node, first_col;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) ret = scnprintf(buf, size, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) first_node = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) /* the first hpp_list_node is for overhead columns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) fmt_node = list_first_entry(&hists->hpp_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) struct perf_hpp_list_node, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) if (column++ < browser->b.horiz_scroll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) ret = fmt->header(fmt, &dummy_hpp, hists, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) first_node = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) if (!first_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, "%*s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) indent * HIERARCHY_INDENT, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) first_node = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) list_for_each_entry_continue(fmt_node, &hists->hpp_formats, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) if (!first_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, " / ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) first_node = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) first_col = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) char *start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) if (perf_hpp__should_skip(fmt, hists))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) if (!first_col) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, "+");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) first_col = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) ret = fmt->header(fmt, &dummy_hpp, hists, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) dummy_hpp.buf[ret] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) start = strim(dummy_hpp.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) ret = strlen(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) if (start != dummy_hpp.buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) memmove(dummy_hpp.buf, start, ret + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) if (advance_hpp_check(&dummy_hpp, ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) static void hists_browser__hierarchy_headers(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) char headers[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) hists_browser__scnprintf_hierarchy_headers(browser, headers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) sizeof(headers));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) ui_browser__gotorc(&browser->b, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) ui_browser__set_color(&browser->b, HE_COLORSET_ROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) ui_browser__write_nstring(&browser->b, headers, browser->b.width + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) static void hists_browser__headers(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) struct hists *hists = browser->hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) struct perf_hpp_list *hpp_list = hists->hpp_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) int line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) for (line = 0; line < hpp_list->nr_header_lines; line++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) char headers[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) hists_browser__scnprintf_headers(browser, headers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) sizeof(headers), line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) ui_browser__gotorc_title(&browser->b, line, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) ui_browser__set_color(&browser->b, HE_COLORSET_ROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) ui_browser__write_nstring(&browser->b, headers, browser->b.width + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) static void hist_browser__show_headers(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) if (symbol_conf.report_hierarchy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) hists_browser__hierarchy_headers(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) hists_browser__headers(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) static void ui_browser__hists_init_top(struct ui_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) if (browser->top == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) struct hist_browser *hb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) hb = container_of(browser, struct hist_browser, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) browser->top = rb_first_cached(&hb->hists->entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) static unsigned int hist_browser__refresh(struct ui_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) unsigned row = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) struct hist_browser *hb = container_of(browser, struct hist_browser, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) if (hb->show_headers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) hist_browser__show_headers(hb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) ui_browser__hists_init_top(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) hb->he_selection = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) hb->selection = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) for (nd = browser->top; nd; nd = rb_hierarchy_next(nd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) float percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) if (h->filtered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) /* let it move to sibling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) h->unfolded = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) if (symbol_conf.report_individual_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) percent = block_info__total_cycles_percent(h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) percent = hist_entry__get_percent_limit(h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) if (percent < hb->min_pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) if (symbol_conf.report_hierarchy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) row += hist_browser__show_hierarchy_entry(hb, h, row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) h->depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) if (row == browser->rows)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) if (h->has_no_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) hist_browser__show_no_entry(hb, row, h->depth + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) row++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) row += hist_browser__show_entry(hb, h, row);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) if (row == browser->rows)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) return row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) static struct rb_node *hists__filter_entries(struct rb_node *nd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) float min_pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) while (nd != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) float percent = hist_entry__get_percent_limit(h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) if (!h->filtered && percent >= min_pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) return nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) * If it's filtered, its all children also were filtered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) * So move to sibling node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) if (rb_next(nd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) nd = rb_next(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) nd = rb_hierarchy_next(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) static struct rb_node *hists__filter_prev_entries(struct rb_node *nd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) float min_pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) while (nd != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) float percent = hist_entry__get_percent_limit(h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) if (!h->filtered && percent >= min_pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) return nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) nd = rb_hierarchy_prev(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) static void ui_browser__hists_seek(struct ui_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) off_t offset, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) struct hist_entry *h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) struct hist_browser *hb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) hb = container_of(browser, struct hist_browser, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (browser->nr_entries == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) ui_browser__hists_init_top(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) switch (whence) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) case SEEK_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) nd = hists__filter_entries(rb_first(browser->entries),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) hb->min_pcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) case SEEK_CUR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) nd = browser->top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) goto do_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) case SEEK_END:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) nd = rb_hierarchy_last(rb_last(browser->entries));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) nd = hists__filter_prev_entries(nd, hb->min_pcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) * Moves not relative to the first visible entry invalidates its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) * row_offset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) h = rb_entry(browser->top, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) h->row_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) * Here we have to check if nd is expanded (+), if it is we can't go
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) * the next top level hist_entry, instead we must compute an offset of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) * what _not_ to show and not change the first visible entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) * This offset increments when we are going from top to bottom and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) * decreases when we're going from bottom to top.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) * As we don't have backpointers to the top level in the callchains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) * structure, we need to always print the whole hist_entry callchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) * skipping the first ones that are before the first visible entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) * and stop when we printed enough lines to fill the screen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) do_offset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) if (!nd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) if (offset > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) h = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) if (h->unfolded && h->leaf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) u16 remaining = h->nr_rows - h->row_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) if (offset > remaining) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) offset -= remaining;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) h->row_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) h->row_offset += offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) browser->top = nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) nd = hists__filter_entries(rb_hierarchy_next(nd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) hb->min_pcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) if (nd == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) --offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) browser->top = nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) } while (offset != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) } else if (offset < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) h = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) if (h->unfolded && h->leaf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) if (-offset > h->row_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) offset += h->row_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) h->row_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) h->row_offset += offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) browser->top = nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (-offset > h->nr_rows) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) offset += h->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) h->row_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) h->row_offset = h->nr_rows + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) browser->top = nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) nd = hists__filter_prev_entries(rb_hierarchy_prev(nd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) hb->min_pcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) if (nd == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) ++offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) browser->top = nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) if (offset == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) * Last unfiltered hist_entry, check if it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) * unfolded, if it is then we should have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) * row_offset at its last entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) h = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) if (h->unfolded && h->leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) h->row_offset = h->nr_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) browser->top = nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) h = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) h->row_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) static int hist_browser__fprintf_callchain(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) struct hist_entry *he, FILE *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) struct callchain_print_arg arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) .fp = fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) hist_browser__show_callchain(browser, he, level, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) hist_browser__fprintf_callchain_entry, &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) hist_browser__check_dump_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) return arg.printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) static int hist_browser__fprintf_entry(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) struct hist_entry *he, FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) char s[8192];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) int printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) char folded_sign = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) struct perf_hpp hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) .buf = s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) .size = sizeof(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) if (hist_entry__has_callchains(he) && symbol_conf.use_callchain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) folded_sign = hist_entry__folded(he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) printed += fprintf(fp, "%c ", folded_sign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) hists__for_each_format(browser->hists, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) if (perf_hpp__should_skip(fmt, he->hists))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) if (!first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) ret = scnprintf(hpp.buf, hpp.size, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) advance_hpp(&hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) ret = fmt->entry(fmt, &hpp, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) ret = hist_entry__snprintf_alignment(he, &hpp, fmt, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) advance_hpp(&hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) printed += fprintf(fp, "%s\n", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) if (folded_sign == '-')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) printed += hist_browser__fprintf_callchain(browser, he, fp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) return printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) static int hist_browser__fprintf_hierarchy_entry(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) struct hist_entry *he,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) FILE *fp, int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) char s[8192];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) int printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) char folded_sign = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) struct perf_hpp hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) .buf = s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) .size = sizeof(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) struct perf_hpp_list_node *fmt_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) int hierarchy_indent = (he->hists->nr_hpp_node - 2) * HIERARCHY_INDENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) printed = fprintf(fp, "%*s", level * HIERARCHY_INDENT, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) folded_sign = hist_entry__folded(he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) printed += fprintf(fp, "%c", folded_sign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) /* the first hpp_list_node is for overhead columns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) fmt_node = list_first_entry(&he->hists->hpp_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) struct perf_hpp_list_node, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) if (!first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) ret = scnprintf(hpp.buf, hpp.size, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) advance_hpp(&hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) ret = fmt->entry(fmt, &hpp, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) advance_hpp(&hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) ret = scnprintf(hpp.buf, hpp.size, "%*s", hierarchy_indent, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) advance_hpp(&hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) perf_hpp_list__for_each_format(he->hpp_list, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) ret = scnprintf(hpp.buf, hpp.size, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) advance_hpp(&hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) ret = fmt->entry(fmt, &hpp, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) advance_hpp(&hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) strim(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) printed += fprintf(fp, "%s\n", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) if (he->leaf && folded_sign == '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) printed += hist_browser__fprintf_callchain(browser, he, fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) he->depth + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) return printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) browser->min_pcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) int printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) while (nd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) if (symbol_conf.report_hierarchy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) printed += hist_browser__fprintf_hierarchy_entry(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) h, fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) h->depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) printed += hist_browser__fprintf_entry(browser, h, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) nd = hists__filter_entries(rb_hierarchy_next(nd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) browser->min_pcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) return printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) static int hist_browser__dump(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) char filename[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) FILE *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) scnprintf(filename, sizeof(filename), "perf.hist.%d", browser->print_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) if (access(filename, F_OK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) * XXX: Just an arbitrary lazy upper limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) if (++browser->print_seq == 8192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) ui_helpline__fpush("Too many perf.hist.N files, nothing written!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) fp = fopen(filename, "w");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) if (fp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) char bf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) const char *err = str_error_r(errno, bf, sizeof(bf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) ui_helpline__fpush("Couldn't write to %s: %s", filename, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) ++browser->print_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) hist_browser__fprintf(browser, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) fclose(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) ui_helpline__fpush("%s written!", filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) void hist_browser__init(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) struct hists *hists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) browser->hists = hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) browser->b.refresh = hist_browser__refresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) browser->b.refresh_dimensions = hist_browser__refresh_dimensions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) browser->b.seek = ui_browser__hists_seek;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) browser->b.use_navkeypressed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) browser->show_headers = symbol_conf.show_hist_headers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) hist_browser__set_title_space(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) if (symbol_conf.report_hierarchy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) struct perf_hpp_list_node *fmt_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) /* count overhead columns (in the first node) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) fmt_node = list_first_entry(&hists->hpp_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) struct perf_hpp_list_node, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) perf_hpp_list__for_each_format(&fmt_node->hpp, fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) ++browser->b.columns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) /* add a single column for whole hierarchy sort keys*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) ++browser->b.columns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) hists__for_each_format(hists, fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) ++browser->b.columns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) hists__reset_column_width(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) struct hist_browser *hist_browser__new(struct hists *hists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) struct hist_browser *browser = zalloc(sizeof(*browser));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) if (browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) hist_browser__init(browser, hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) return browser;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) static struct hist_browser *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) perf_evsel_browser__new(struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) struct hist_browser_timer *hbt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) struct perf_env *env,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) struct annotation_options *annotation_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) struct hist_browser *browser = hist_browser__new(evsel__hists(evsel));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) if (browser) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) browser->hbt = hbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) browser->env = env;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) browser->title = hists_browser__scnprintf_title;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) browser->annotation_opts = annotation_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) return browser;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) void hist_browser__delete(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) free(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) static struct hist_entry *hist_browser__selected_entry(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) return browser->he_selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) static struct thread *hist_browser__selected_thread(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) return browser->he_selection->thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) static struct res_sample *hist_browser__selected_res_sample(struct hist_browser *browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) return browser->he_selection ? browser->he_selection->res_samples : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) /* Check whether the browser is for 'top' or 'report' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) static inline bool is_report_browser(void *timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) return timer == NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) static int hists_browser__scnprintf_title(struct hist_browser *browser, char *bf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) struct hist_browser_timer *hbt = browser->hbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) int printed = __hists__scnprintf_title(browser->hists, bf, size, !is_report_browser(hbt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) if (!is_report_browser(hbt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) struct perf_top *top = hbt->arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) printed += scnprintf(bf + printed, size - printed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) " lost: %" PRIu64 "/%" PRIu64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) top->lost, top->lost_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) printed += scnprintf(bf + printed, size - printed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) " drop: %" PRIu64 "/%" PRIu64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) top->drop, top->drop_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) if (top->zero)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) printed += scnprintf(bf + printed, size - printed, " [z]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) perf_top__reset_sample_counters(top);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) return printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) static inline void free_popup_options(char **options, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) for (i = 0; i < n; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) zfree(&options[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) * Only runtime switching of perf data file will make "input_name" point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) * to a malloced buffer. So add "is_input_name_malloced" flag to decide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) * whether we need to call free() for current "input_name" during the switch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) static bool is_input_name_malloced = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) static int switch_data_file(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) char *pwd, *options[32], *abs_path[32], *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) DIR *pwd_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) int nr_options = 0, choice = -1, ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) struct dirent *dent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) pwd = getenv("PWD");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) if (!pwd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) pwd_dir = opendir(pwd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) if (!pwd_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) memset(options, 0, sizeof(options));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) memset(abs_path, 0, sizeof(abs_path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) while ((dent = readdir(pwd_dir))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) char path[PATH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) u64 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) char *name = dent->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) FILE *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) if (!(dent->d_type == DT_REG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) snprintf(path, sizeof(path), "%s/%s", pwd, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) file = fopen(path, "r");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) if (fread(&magic, 1, 8, file) < 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) goto close_file_and_continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) if (is_perf_magic(magic)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) options[nr_options] = strdup(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) if (!options[nr_options])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) goto close_file_and_continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) abs_path[nr_options] = strdup(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) if (!abs_path[nr_options]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) zfree(&options[nr_options]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) ui__warning("Can't search all data files due to memory shortage.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) fclose(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) nr_options++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) close_file_and_continue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) fclose(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) if (nr_options >= 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) ui__warning("Too many perf data files in PWD!\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) "Only the first 32 files will be listed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) closedir(pwd_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) if (nr_options) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) choice = ui__popup_menu(nr_options, options, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) if (choice < nr_options && choice >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) tmp = strdup(abs_path[choice]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) if (tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) if (is_input_name_malloced)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) free((void *)input_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) input_name = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) is_input_name_malloced = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) ui__warning("Data switch failed due to memory shortage!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) free_popup_options(options, nr_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) free_popup_options(abs_path, nr_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) struct popup_action {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) unsigned long time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) struct thread *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) struct map_symbol ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) int socket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) struct evsel *evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) enum rstype rstype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) int (*fn)(struct hist_browser *browser, struct popup_action *act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) do_annotate(struct hist_browser *browser, struct popup_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) struct evsel *evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) struct annotation *notes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) if (!browser->annotation_opts->objdump_path &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) perf_env__lookup_objdump(browser->env, &browser->annotation_opts->objdump_path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) notes = symbol__annotation(act->ms.sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) if (!notes->src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) if (browser->block_evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) evsel = browser->block_evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) evsel = hists_to_evsel(browser->hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) err = map_symbol__tui_annotate(&act->ms, evsel, browser->hbt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) browser->annotation_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) he = hist_browser__selected_entry(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) * offer option to annotate the other branch source or target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) * (if they exists) when returning from annotate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) if ((err == 'q' || err == CTRL('c')) && he->branch_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) ui_browser__handle_resize(&browser->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) static struct symbol *symbol__new_unresolved(u64 addr, struct map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) struct annotated_source *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) struct symbol *sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) char name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) snprintf(name, sizeof(name), "%.*" PRIx64, BITS_PER_LONG / 4, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) sym = symbol__new(addr, ANNOTATION_DUMMY_LEN, 0, 0, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) if (sym) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) src = symbol__hists(sym, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) if (!src) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) symbol__delete(sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) dso__insert_symbol(map->dso, sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) return sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) add_annotate_opt(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) struct popup_action *act, char **optstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) struct map_symbol *ms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) u64 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) if (!ms->map || !ms->map->dso || ms->map->dso->annotate_warned)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) if (!ms->sym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) ms->sym = symbol__new_unresolved(addr, ms->map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) if (ms->sym == NULL || symbol__annotation(ms->sym)->src == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) if (asprintf(optstr, "Annotate %s", ms->sym->name) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) act->ms = *ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) act->fn = do_annotate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) do_zoom_thread(struct hist_browser *browser, struct popup_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) struct thread *thread = act->thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) if ((!hists__has(browser->hists, thread) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) !hists__has(browser->hists, comm)) || thread == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) if (browser->hists->thread_filter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) pstack__remove(browser->pstack, &browser->hists->thread_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) perf_hpp__set_elide(HISTC_THREAD, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) thread__zput(browser->hists->thread_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) ui_helpline__pop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) if (hists__has(browser->hists, thread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) thread->comm_set ? thread__comm_str(thread) : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) thread->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s thread\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) thread->comm_set ? thread__comm_str(thread) : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) browser->hists->thread_filter = thread__get(thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) perf_hpp__set_elide(HISTC_THREAD, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) pstack__push(browser->pstack, &browser->hists->thread_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) hists__filter_by_thread(browser->hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) hist_browser__reset(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) add_thread_opt(struct hist_browser *browser, struct popup_action *act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) char **optstr, struct thread *thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) if ((!hists__has(browser->hists, thread) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) !hists__has(browser->hists, comm)) || thread == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) if (hists__has(browser->hists, thread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) ret = asprintf(optstr, "Zoom %s %s(%d) thread",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) browser->hists->thread_filter ? "out of" : "into",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) thread->comm_set ? thread__comm_str(thread) : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) thread->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) ret = asprintf(optstr, "Zoom %s %s thread",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) browser->hists->thread_filter ? "out of" : "into",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) thread->comm_set ? thread__comm_str(thread) : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) act->thread = thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) act->fn = do_zoom_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) static int hists_browser__zoom_map(struct hist_browser *browser, struct map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) if (!hists__has(browser->hists, dso) || map == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) if (browser->hists->dso_filter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) pstack__remove(browser->pstack, &browser->hists->dso_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) perf_hpp__set_elide(HISTC_DSO, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) browser->hists->dso_filter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) ui_helpline__pop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) __map__is_kernel(map) ? "the Kernel" : map->dso->short_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) browser->hists->dso_filter = map->dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) perf_hpp__set_elide(HISTC_DSO, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) pstack__push(browser->pstack, &browser->hists->dso_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) hists__filter_by_dso(browser->hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) hist_browser__reset(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) do_zoom_dso(struct hist_browser *browser, struct popup_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) return hists_browser__zoom_map(browser, act->ms.map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) add_dso_opt(struct hist_browser *browser, struct popup_action *act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) char **optstr, struct map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) if (!hists__has(browser->hists, dso) || map == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) if (asprintf(optstr, "Zoom %s %s DSO (use the 'k' hotkey to zoom directly into the kernel)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) browser->hists->dso_filter ? "out of" : "into",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) __map__is_kernel(map) ? "the Kernel" : map->dso->short_name) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) act->ms.map = map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) act->fn = do_zoom_dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) static int do_toggle_callchain(struct hist_browser *browser, struct popup_action *act __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) hist_browser__toggle_fold(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) static int add_callchain_toggle_opt(struct hist_browser *browser, struct popup_action *act, char **optstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) char sym_name[512];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) if (!hist_browser__selection_has_children(browser))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) if (asprintf(optstr, "%s [%s] callchain (one level, same as '+' hotkey, use 'e'/'c' for the whole main level entry)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) hist_browser__selection_unfolded(browser) ? "Collapse" : "Expand",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) hist_browser__selection_sym_name(browser, sym_name, sizeof(sym_name))) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) act->fn = do_toggle_callchain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) do_browse_map(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) struct popup_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) map__browse(act->ms.map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) add_map_opt(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) struct popup_action *act, char **optstr, struct map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) if (!hists__has(browser->hists, dso) || map == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) if (asprintf(optstr, "Browse map details") < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) act->ms.map = map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) act->fn = do_browse_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) do_run_script(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) struct popup_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) char *script_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) len = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) if (act->thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) len += strlen(thread__comm_str(act->thread));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) else if (act->ms.sym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) len += strlen(act->ms.sym->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) script_opt = malloc(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) if (!script_opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) script_opt[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) if (act->thread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) n = scnprintf(script_opt, len, " -c %s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) thread__comm_str(act->thread));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) } else if (act->ms.sym) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) n = scnprintf(script_opt, len, " -S %s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) act->ms.sym->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) if (act->time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) char start[32], end[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) unsigned long starttime = act->time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) unsigned long endtime = act->time + symbol_conf.time_quantum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) if (starttime == endtime) { /* Display 1ms as fallback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) starttime -= 1*NSEC_PER_MSEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) endtime += 1*NSEC_PER_MSEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) timestamp__scnprintf_usec(starttime, start, sizeof start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) timestamp__scnprintf_usec(endtime, end, sizeof end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) n += snprintf(script_opt + n, len - n, " --time %s,%s", start, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) script_browse(script_opt, act->evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) free(script_opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) do_res_sample_script(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) struct popup_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) he = hist_browser__selected_entry(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) res_sample_browse(he->res_samples, he->num_res, act->evsel, act->rstype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) add_script_opt_2(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) struct popup_action *act, char **optstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) struct thread *thread, struct symbol *sym,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) struct evsel *evsel, const char *tstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) if (thread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) if (asprintf(optstr, "Run scripts for samples of thread [%s]%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) thread__comm_str(thread), tstr) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) } else if (sym) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) if (asprintf(optstr, "Run scripts for samples of symbol [%s]%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) sym->name, tstr) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) if (asprintf(optstr, "Run scripts for all samples%s", tstr) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) act->thread = thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) act->ms.sym = sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) act->evsel = evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) act->fn = do_run_script;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) add_script_opt(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) struct popup_action *act, char **optstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) struct thread *thread, struct symbol *sym,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) int n, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) n = add_script_opt_2(browser, act, optstr, thread, sym, evsel, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) he = hist_browser__selected_entry(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) if (sort_order && strstr(sort_order, "time")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) char tstr[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) optstr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) act++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) j = sprintf(tstr, " in ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) j += timestamp__scnprintf_usec(he->time, tstr + j,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) sizeof tstr - j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) j += sprintf(tstr + j, "-");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) timestamp__scnprintf_usec(he->time + symbol_conf.time_quantum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) tstr + j, sizeof tstr - j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) n += add_script_opt_2(browser, act, optstr, thread, sym,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) evsel, tstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) act->time = he->time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) add_res_sample_opt(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) struct popup_action *act, char **optstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) struct res_sample *res_sample,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) enum rstype type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) if (!res_sample)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) if (asprintf(optstr, "Show context for individual samples %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) type == A_ASM ? "with assembler" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) type == A_SOURCE ? "with source" : "") < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) act->fn = do_res_sample_script;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) act->evsel = evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) act->rstype = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) do_switch_data(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) struct popup_action *act __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) if (switch_data_file()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) ui__warning("Won't switch the data files due to\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) "no valid data file get selected!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) return K_SWITCH_INPUT_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) add_switch_opt(struct hist_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) struct popup_action *act, char **optstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) if (!is_report_browser(browser->hbt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) if (asprintf(optstr, "Switch to another data file in PWD") < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) act->fn = do_switch_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) do_exit_browser(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) struct popup_action *act __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) add_exit_opt(struct hist_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) struct popup_action *act, char **optstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) if (asprintf(optstr, "Exit") < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) act->fn = do_exit_browser;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) do_zoom_socket(struct hist_browser *browser, struct popup_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) if (!hists__has(browser->hists, socket) || act->socket < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) if (browser->hists->socket_filter > -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) pstack__remove(browser->pstack, &browser->hists->socket_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) browser->hists->socket_filter = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) perf_hpp__set_elide(HISTC_SOCKET, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) browser->hists->socket_filter = act->socket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) perf_hpp__set_elide(HISTC_SOCKET, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) pstack__push(browser->pstack, &browser->hists->socket_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) hists__filter_by_socket(browser->hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) hist_browser__reset(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) add_socket_opt(struct hist_browser *browser, struct popup_action *act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) char **optstr, int socket_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) if (!hists__has(browser->hists, socket) || socket_id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) if (asprintf(optstr, "Zoom %s Processor Socket %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) (browser->hists->socket_filter > -1) ? "out of" : "into",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) socket_id) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) act->socket = socket_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) act->fn = do_zoom_socket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) static void hist_browser__update_nr_entries(struct hist_browser *hb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) u64 nr_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) struct rb_node *nd = rb_first_cached(&hb->hists->entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) if (hb->min_pcnt == 0 && !symbol_conf.report_hierarchy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) hb->nr_non_filtered_entries = hb->hists->nr_non_filtered_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) while ((nd = hists__filter_entries(nd, hb->min_pcnt)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) nr_entries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) nd = rb_hierarchy_next(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) hb->nr_non_filtered_entries = nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) hb->nr_hierarchy_entries = nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) static void hist_browser__update_percent_limit(struct hist_browser *hb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) double percent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) struct rb_node *nd = rb_first_cached(&hb->hists->entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) u64 total = hists__total_period(hb->hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) u64 min_callchain_hits = total * (percent / 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) hb->min_pcnt = callchain_param.min_percent = percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) while ((nd = hists__filter_entries(nd, hb->min_pcnt)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) he = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) if (he->has_no_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) he->has_no_entry = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) he->nr_rows = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) if (!he->leaf || !hist_entry__has_callchains(he) || !symbol_conf.use_callchain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) if (callchain_param.mode == CHAIN_GRAPH_REL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) total = he->stat.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) if (symbol_conf.cumulate_callchain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) total = he->stat_acc->period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) min_callchain_hits = total * (percent / 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) callchain_param.sort(&he->sorted_chain, he->callchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) min_callchain_hits, &callchain_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) nd = __rb_hierarchy_next(nd, HMD_FORCE_CHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) /* force to re-evaluate folding state of callchains */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) he->init_have_children = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) hist_entry__set_folding(he, hb, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) const char *helpline,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) bool left_exits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) struct hist_browser_timer *hbt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) float min_pcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) struct perf_env *env,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) bool warn_lost_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) struct annotation_options *annotation_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) struct hists *hists = evsel__hists(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env, annotation_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) struct branch_info *bi = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) #define MAX_OPTIONS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) char *options[MAX_OPTIONS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) struct popup_action actions[MAX_OPTIONS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) int nr_options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) int key = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) char buf[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) int delay_secs = hbt ? hbt->refresh : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) #define HIST_BROWSER_HELP_COMMON \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) "h/?/F1 Show this window\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) "UP/DOWN/PGUP\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) "PGDN/SPACE Navigate\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) "q/ESC/CTRL+C Exit browser or go back to previous screen\n\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) "For multiple event sessions:\n\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) "TAB/UNTAB Switch events\n\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) "For symbolic views (--sort has sym):\n\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) "ENTER Zoom into DSO/Threads & Annotate current symbol\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) "ESC Zoom out\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) "+ Expand/Collapse one callchain level\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) "a Annotate current symbol\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) "C Collapse all callchains\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) "d Zoom into current DSO\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) "e Expand/Collapse main entry callchains\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) "E Expand all callchains\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) "F Toggle percentage of filtered entries\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) "H Display column headers\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) "k Zoom into the kernel map\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) "L Change percent limit\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) "m Display context menu\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) "S Zoom into current Processor Socket\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) /* help messages are sorted by lexical order of the hotkey */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) static const char report_help[] = HIST_BROWSER_HELP_COMMON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) "i Show header information\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) "P Print histograms to perf.hist.N\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) "r Run available scripts\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) "s Switch to another data file in PWD\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) "t Zoom into current Thread\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) "V Verbose (DSO names in callchains, etc)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) "/ Filter symbol by name\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) "0-9 Sort by event n in group";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) static const char top_help[] = HIST_BROWSER_HELP_COMMON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) "P Print histograms to perf.hist.N\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) "t Zoom into current Thread\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) "V Verbose (DSO names in callchains, etc)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) "z Toggle zeroing of samples\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) "f Enable/Disable events\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) "/ Filter symbol by name";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) if (browser == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) /* reset abort key so that it can get Ctrl-C as a key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) SLang_reset_tty();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) SLang_init_tty(0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) if (min_pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) browser->min_pcnt = min_pcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) hist_browser__update_nr_entries(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) browser->pstack = pstack__new(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) if (browser->pstack == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) ui_helpline__push(helpline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) memset(options, 0, sizeof(options));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) memset(actions, 0, sizeof(actions));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) if (symbol_conf.col_width_list_str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) perf_hpp__set_user_width(symbol_conf.col_width_list_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) if (!is_report_browser(hbt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) browser->b.no_samples_msg = "Collecting samples...";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) struct thread *thread = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) struct map *map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) int choice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) int socked_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) key = 0; // reset key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) do_hotkey: // key came straight from options ui__popup_menu()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) choice = nr_options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) key = hist_browser__run(browser, helpline, warn_lost_event, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) if (browser->he_selection != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) thread = hist_browser__selected_thread(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) map = browser->selection->map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) socked_id = browser->he_selection->socket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) case K_TAB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) case K_UNTAB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) if (nr_events == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) * Exit the browser, let hists__browser_tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) * go to the next or previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) goto out_free_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) case '0' ... '9':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) if (!symbol_conf.event_group ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) evsel->core.nr_members < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) snprintf(buf, sizeof(buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) "Sort by index only available with group events!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) helpline = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) if (key - '0' == symbol_conf.group_sort_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) symbol_conf.group_sort_idx = key - '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) if (symbol_conf.group_sort_idx >= evsel->core.nr_members) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) snprintf(buf, sizeof(buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) "Max event group index to sort is %d (index from 0 to %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) evsel->core.nr_members - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) evsel->core.nr_members - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) helpline = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) key = K_RELOAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) goto out_free_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) case 'a':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) if (!hists__has(hists, sym)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) ui_browser__warning(&browser->b, delay_secs * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) "Annotation is only available for symbolic views, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) "include \"sym*\" in --sort to use it.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) if (!browser->selection ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) !browser->selection->map ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) !browser->selection->map->dso ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) browser->selection->map->dso->annotate_warned) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) if (!browser->selection->sym) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) if (!browser->he_selection)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) if (sort__mode == SORT_MODE__BRANCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) bi = browser->he_selection->branch_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) if (!bi || !bi->to.ms.map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) actions->ms.sym = symbol__new_unresolved(bi->to.al_addr, bi->to.ms.map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) actions->ms.map = bi->to.ms.map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) actions->ms.sym = symbol__new_unresolved(browser->he_selection->ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) browser->selection->map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) actions->ms.map = browser->selection->map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) if (!actions->ms.sym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) if (symbol__annotation(browser->selection->sym)->src == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) ui_browser__warning(&browser->b, delay_secs * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) "No samples for the \"%s\" symbol.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) "Probably appeared just in a callchain",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) browser->selection->sym->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) actions->ms.map = browser->selection->map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) actions->ms.sym = browser->selection->sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) do_annotate(browser, actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) case 'P':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) hist_browser__dump(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) case 'd':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) actions->ms.map = map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) do_zoom_dso(browser, actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) case 'k':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) if (browser->selection != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) hists_browser__zoom_map(browser, browser->selection->maps->machine->vmlinux_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) case 'V':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) verbose = (verbose + 1) % 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) browser->show_dso = verbose > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) ui_helpline__fpush("Verbosity level set to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) verbose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) case 't':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) actions->thread = thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) do_zoom_thread(browser, actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) case 'S':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) actions->socket = socked_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) do_zoom_socket(browser, actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) case '/':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) if (ui_browser__input_window("Symbol to show",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) "Please enter the name of symbol you want to see.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) "To remove the filter later, press / + ENTER.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) buf, "ENTER: OK, ESC: Cancel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) delay_secs * 2) == K_ENTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) hists->symbol_filter_str = *buf ? buf : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) hists__filter_by_symbol(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) hist_browser__reset(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) case 'r':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) if (is_report_browser(hbt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) actions->thread = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) actions->ms.sym = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) do_run_script(browser, actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) case 's':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) if (is_report_browser(hbt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) key = do_switch_data(browser, actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) if (key == K_SWITCH_INPUT_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) goto out_free_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) case 'i':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) /* env->arch is NULL for live-mode (i.e. perf top) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) if (env->arch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) tui__header_window(env);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) case 'F':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) symbol_conf.filter_relative ^= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) case 'z':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) if (!is_report_browser(hbt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) struct perf_top *top = hbt->arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) top->zero = !top->zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) case 'L':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) if (ui_browser__input_window("Percent Limit",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) "Please enter the value you want to hide entries under that percent.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) buf, "ENTER: OK, ESC: Cancel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) delay_secs * 2) == K_ENTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) char *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) double new_percent = strtod(buf, &end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) if (new_percent < 0 || new_percent > 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) ui_browser__warning(&browser->b, delay_secs * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) "Invalid percent: %.2f", new_percent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) hist_browser__update_percent_limit(browser, new_percent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) hist_browser__reset(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) case K_F1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) case 'h':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) case '?':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) ui_browser__help_window(&browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) is_report_browser(hbt) ? report_help : top_help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) case K_ENTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) case K_RIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) case 'm':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) /* menu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) case K_ESC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) case K_LEFT: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) const void *top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) if (pstack__empty(browser->pstack)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) * Go back to the perf_evsel_menu__run or other user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) if (left_exits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) goto out_free_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) if (key == K_ESC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) ui_browser__dialog_yesno(&browser->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) "Do you really want to exit?"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) goto out_free_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) actions->ms.map = map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) top = pstack__peek(browser->pstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) if (top == &browser->hists->dso_filter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) * No need to set actions->dso here since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) * it's just to remove the current filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) * Ditto for thread below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) do_zoom_dso(browser, actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) } else if (top == &browser->hists->thread_filter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) do_zoom_thread(browser, actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) } else if (top == &browser->hists->socket_filter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) do_zoom_socket(browser, actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) case 'q':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) case CTRL('c'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) goto out_free_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) case 'f':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) if (!is_report_browser(hbt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) struct perf_top *top = hbt->arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) perf_evlist__toggle_enable(top->evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) * No need to refresh, resort/decay histogram
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) * entries if we are not collecting samples:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) if (top->evlist->enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) helpline = "Press 'f' to disable the events or 'h' to see other hotkeys";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) hbt->refresh = delay_secs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) helpline = "Press 'f' again to re-enable the events";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) hbt->refresh = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) /* Fall thru */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) helpline = "Press '?' for help on key bindings";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) if (!hists__has(hists, sym) || browser->selection == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) goto skip_annotation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) if (sort__mode == SORT_MODE__BRANCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) if (browser->he_selection)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) bi = browser->he_selection->branch_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) if (bi == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) goto skip_annotation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) nr_options += add_annotate_opt(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) &bi->from.ms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) bi->from.al_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) if (bi->to.ms.sym != bi->from.ms.sym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) nr_options += add_annotate_opt(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) &bi->to.ms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) bi->to.al_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) nr_options += add_annotate_opt(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) browser->selection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) browser->he_selection->ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) skip_annotation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) nr_options += add_thread_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) &options[nr_options], thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) nr_options += add_dso_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) &options[nr_options], map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) nr_options += add_callchain_toggle_opt(browser, &actions[nr_options], &options[nr_options]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) nr_options += add_map_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) browser->selection ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) browser->selection->map : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) nr_options += add_socket_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) socked_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) /* perf script support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) if (!is_report_browser(hbt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) goto skip_scripting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) if (browser->he_selection) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) if (hists__has(hists, thread) && thread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) nr_options += add_script_opt(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) thread, NULL, evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) * Note that browser->selection != NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) * when browser->he_selection is not NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) * so we don't need to check browser->selection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) * before fetching browser->selection->sym like what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) * we do before fetching browser->selection->map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) * See hist_browser__show_entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) if (hists__has(hists, sym) && browser->selection->sym) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) nr_options += add_script_opt(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) NULL, browser->selection->sym,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) nr_options += add_script_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) &options[nr_options], NULL, NULL, evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) nr_options += add_res_sample_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) hist_browser__selected_res_sample(browser),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) evsel, A_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) nr_options += add_res_sample_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) hist_browser__selected_res_sample(browser),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) evsel, A_ASM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) nr_options += add_res_sample_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) &options[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) hist_browser__selected_res_sample(browser),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) evsel, A_SOURCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) nr_options += add_switch_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) &options[nr_options]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) skip_scripting:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) nr_options += add_exit_opt(browser, &actions[nr_options],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) &options[nr_options]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) struct popup_action *act;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) choice = ui__popup_menu(nr_options, options, &key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) if (choice == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) if (choice == nr_options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) goto do_hotkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) act = &actions[choice];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) key = act->fn(browser, act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) } while (key == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) if (key == K_SWITCH_INPUT_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) out_free_stack:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) pstack__delete(browser->pstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) hist_browser__delete(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) free_popup_options(options, MAX_OPTIONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) return key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) struct evsel_menu {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) struct ui_browser b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) struct evsel *selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) struct annotation_options *annotation_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) bool lost_events, lost_events_warned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) float min_pcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) struct perf_env *env;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) static void perf_evsel_menu__write(struct ui_browser *browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) void *entry, int row)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) struct evsel_menu *menu = container_of(browser,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) struct evsel_menu, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) struct evsel *evsel = list_entry(entry, struct evsel, core.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) struct hists *hists = evsel__hists(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) bool current_entry = ui_browser__is_current_entry(browser, row);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) unsigned long nr_events = hists->stats.nr_events[PERF_RECORD_SAMPLE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) const char *ev_name = evsel__name(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) char bf[256], unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) const char *warn = " ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) size_t printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) HE_COLORSET_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) if (evsel__is_group_event(evsel)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) struct evsel *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) ev_name = evsel__group_name(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) for_each_group_member(pos, evsel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) struct hists *pos_hists = evsel__hists(pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) nr_events += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) nr_events = convert_unit(nr_events, &unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) printed = scnprintf(bf, sizeof(bf), "%lu%c%s%s", nr_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) unit, unit == ' ' ? "" : " ", ev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) ui_browser__printf(browser, "%s", bf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) nr_events = hists->stats.nr_events[PERF_RECORD_LOST];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) if (nr_events != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) menu->lost_events = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) if (!current_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) ui_browser__set_color(browser, HE_COLORSET_TOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) nr_events = convert_unit(nr_events, &unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) printed += scnprintf(bf, sizeof(bf), ": %ld%c%schunks LOST!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) nr_events, unit, unit == ' ' ? "" : " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) warn = bf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) ui_browser__write_nstring(browser, warn, browser->width - printed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) if (current_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) menu->selection = evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) static int perf_evsel_menu__run(struct evsel_menu *menu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) int nr_events, const char *help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) struct hist_browser_timer *hbt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) bool warn_lost_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) struct evlist *evlist = menu->b.priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) struct evsel *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) const char *title = "Available samples";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) int delay_secs = hbt ? hbt->refresh : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) int key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) if (ui_browser__show(&menu->b, title,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) "ESC: exit, ENTER|->: Browse histograms") < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) key = ui_browser__run(&menu->b, delay_secs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) case K_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) if (hbt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) hbt->timer(hbt->arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) if (!menu->lost_events_warned &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) menu->lost_events &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) warn_lost_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) ui_browser__warn_lost_events(&menu->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) menu->lost_events_warned = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) case K_RIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) case K_ENTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) if (!menu->selection)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) pos = menu->selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) browse_hists:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) perf_evlist__set_selected(evlist, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) * Give the calling tool a chance to populate the non
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) * default evsel resorted hists tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) if (hbt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) hbt->timer(hbt->arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) key = perf_evsel__hists_browse(pos, nr_events, help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) true, hbt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) menu->min_pcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) menu->env,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) warn_lost_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) menu->annotation_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) ui_browser__show_title(&menu->b, title);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) case K_TAB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) if (pos->core.node.next == &evlist->core.entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) pos = evlist__first(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) pos = evsel__next(pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) goto browse_hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) case K_UNTAB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) if (pos->core.node.prev == &evlist->core.entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) pos = evlist__last(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) pos = evsel__prev(pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) goto browse_hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) case K_SWITCH_INPUT_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) case K_RELOAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) case 'q':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) case CTRL('c'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) case K_ESC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) case K_LEFT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) case K_ESC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) if (!ui_browser__dialog_yesno(&menu->b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) "Do you really want to exit?"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) /* Fall thru */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) case 'q':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) case CTRL('c'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) ui_browser__hide(&menu->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) return key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) static bool filter_group_entries(struct ui_browser *browser __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) void *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) struct evsel *evsel = list_entry(entry, struct evsel, core.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) if (symbol_conf.event_group && !evsel__is_group_leader(evsel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) static int __perf_evlist__tui_browse_hists(struct evlist *evlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) int nr_entries, const char *help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) struct hist_browser_timer *hbt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) float min_pcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) struct perf_env *env,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) bool warn_lost_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) struct annotation_options *annotation_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) struct evsel *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) struct evsel_menu menu = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) .b = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) .entries = &evlist->core.entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) .refresh = ui_browser__list_head_refresh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) .seek = ui_browser__list_head_seek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) .write = perf_evsel_menu__write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) .filter = filter_group_entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) .nr_entries = nr_entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) .priv = evlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) .min_pcnt = min_pcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) .env = env,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) .annotation_opts = annotation_opts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) ui_helpline__push("Press ESC to exit");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) evlist__for_each_entry(evlist, pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) const char *ev_name = evsel__name(pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) size_t line_len = strlen(ev_name) + 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) if (menu.b.width < line_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) menu.b.width = line_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) return perf_evsel_menu__run(&menu, nr_entries, help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) hbt, warn_lost_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) static bool perf_evlist__single_entry(struct evlist *evlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) int nr_entries = evlist->core.nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) if (nr_entries == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) if (nr_entries == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) struct evsel *last = evlist__last(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) if (evsel__is_dummy_event(last))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) int perf_evlist__tui_browse_hists(struct evlist *evlist, const char *help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) struct hist_browser_timer *hbt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) float min_pcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) struct perf_env *env,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) bool warn_lost_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) struct annotation_options *annotation_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) int nr_entries = evlist->core.nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) if (perf_evlist__single_entry(evlist)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) single_entry: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) struct evsel *first = evlist__first(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) return perf_evsel__hists_browse(first, nr_entries, help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) false, hbt, min_pcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) env, warn_lost_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) annotation_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) if (symbol_conf.event_group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) struct evsel *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) nr_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) evlist__for_each_entry(evlist, pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) if (evsel__is_group_leader(pos))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) nr_entries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) if (nr_entries == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) goto single_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) return __perf_evlist__tui_browse_hists(evlist, nr_entries, help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) hbt, min_pcnt, env,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) warn_lost_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) annotation_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) static int block_hists_browser__title(struct hist_browser *browser, char *bf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) struct hists *hists = evsel__hists(browser->block_evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) const char *evname = evsel__name(browser->block_evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) ret = scnprintf(bf, size, "# Samples: %lu", nr_samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) if (evname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) scnprintf(bf + ret, size - ret, " of event '%s'", evname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) float min_percent, struct perf_env *env,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) struct annotation_options *annotation_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) struct hists *hists = &bh->block_hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) struct hist_browser *browser;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) int key = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) struct popup_action action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) static const char help[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) " q Quit \n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) browser = hist_browser__new(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) if (!browser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) browser->block_evsel = evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) browser->title = block_hists_browser__title;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) browser->min_pcnt = min_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) browser->env = env;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) browser->annotation_opts = annotation_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) /* reset abort key so that it can get Ctrl-C as a key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) SLang_reset_tty();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) SLang_init_tty(0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) memset(&action, 0, sizeof(action));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) key = hist_browser__run(browser, "? - help", true, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) case 'q':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) case '?':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) ui_browser__help_window(&browser->b, help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) case 'a':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) case K_ENTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) if (!browser->selection ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) !browser->selection->sym) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) action.ms.map = browser->selection->map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) action.ms.sym = browser->selection->sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) do_annotate(browser, &action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) hist_browser__delete(browser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) }