tools/perf/builtin-top.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-top.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-top.c- Extension
.c- Size
- 51809 bytes
- Lines
- 1907
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
builtin.hperf.hutil/annotate.hutil/bpf-event.hutil/cgroup.hutil/config.hutil/color.hutil/dso.hutil/evlist.hutil/evsel.hutil/evsel_config.hutil/event.hutil/machine.hutil/map.hutil/mmap.hutil/session.hutil/thread.hutil/stat.hutil/symbol.hutil/synthetic-events.hutil/top.hutil/util.hlinux/rbtree.hsubcmd/parse-options.hutil/parse-events.hutil/callchain.hutil/cpumap.hutil/sort.hutil/string2.hutil/term.hutil/intlist.hutil/parse-branch-options.h
Detected Declarations
function perf_top__update_print_entriesfunction winch_sigfunction perf_top__resizefunction perf_top__parse_sourcefunction __zero_source_countersfunction ui__warn_map_erangefunction perf_top__record_precise_ipfunction perf_top__show_detailsfunction perf_top__resort_histsfunction evlist__for_each_entryfunction evlist__for_each_entryfunction perf_top__print_sym_tablefunction prompt_integerfunction prompt_percentfunction perf_top__prompt_symbolfunction perf_top__print_mapped_keysfunction perf_top__key_mappedfunction perf_top__handle_keypressfunction perf_top__sort_new_samplesfunction stop_topfunction display_sigfunction display_setup_sigfunction hist_iter__top_callbackfunction perf_event__process_samplefunction perf_top__process_lostfunction perf_top__process_lost_samplesfunction perf_top__mmap_read_idxfunction perf_top__mmap_readfunction perf_top__overwrite_checkfunction evlist__for_each_entryfunction list_for_each_entryfunction perf_top_overwrite_fallbackfunction perf_top__start_countersfunction evlist__for_each_entryfunction callchain_param__setup_sample_typefunction should_dropfunction deliver_eventfunction init_process_threadfunction exit_process_threadfunction __cmd_topfunction parse_callchain_optfunction callchain_optfunction perf_top_configfunction parse_percent_limitfunction cmd_top
Annotated Snippet
else if (err == -ENOMEM) {
pr_err("Not enough memory for annotating '%s' symbol!\n",
sym->name);
sleep(1);
}
mutex_lock(&he->hists->lock);
}
}
static void perf_top__show_details(struct perf_top *top)
{
struct hist_entry *he = top->sym_filter_entry;
struct evsel *evsel;
struct annotation *notes;
struct symbol *symbol;
int more;
if (!he)
return;
evsel = hists_to_evsel(he->hists);
symbol = he->ms.sym;
notes = symbol__annotation(symbol);
annotation__lock(notes);
symbol__calc_percent(symbol, evsel);
if (notes->src == NULL)
goto out_unlock;
printf("Showing %s for %s\n", evsel__name(top->sym_evsel), symbol->name);
printf(" Events Pcnt (>=%d%%)\n", annotate_opts.min_pcnt);
more = hist_entry__annotate_printf(he, top->sym_evsel);
if (top->evlist->enabled) {
if (top->zero)
symbol__annotate_zero_histogram(symbol, top->sym_evsel);
else
symbol__annotate_decay_histogram(symbol, top->sym_evsel);
}
if (more != 0)
printf("%d lines not displayed, maybe increase display entries [e]\n", more);
out_unlock:
annotation__unlock(notes);
}
static void perf_top__resort_hists(struct perf_top *t)
{
struct evlist *evlist = t->evlist;
struct evsel *pos;
evlist__for_each_entry(evlist, pos) {
struct hists *hists = evsel__hists(pos);
/*
* unlink existing entries so that they can be linked
* in a correct order in hists__match() below.
*/
hists__unlink(hists);
if (evlist->enabled) {
if (t->zero) {
hists__delete_entries(hists);
} else {
hists__decay_entries(hists, t->hide_user_symbols,
t->hide_kernel_symbols);
}
}
hists__collapse_resort(hists, NULL);
/* Non-group events are considered as leader */
if (symbol_conf.event_group && !evsel__is_group_leader(pos)) {
struct hists *leader_hists = evsel__hists(evsel__leader(pos));
hists__match(leader_hists, hists);
hists__link(leader_hists, hists);
}
}
evlist__for_each_entry(evlist, pos) {
evsel__output_resort(pos, NULL);
}
}
static void perf_top__print_sym_table(struct perf_top *top)
Annotation
- Immediate include surface: `builtin.h`, `perf.h`, `util/annotate.h`, `util/bpf-event.h`, `util/cgroup.h`, `util/config.h`, `util/color.h`, `util/dso.h`.
- Detected declarations: `function perf_top__update_print_entries`, `function winch_sig`, `function perf_top__resize`, `function perf_top__parse_source`, `function __zero_source_counters`, `function ui__warn_map_erange`, `function perf_top__record_precise_ip`, `function perf_top__show_details`, `function perf_top__resort_hists`, `function evlist__for_each_entry`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.