tools/perf/builtin-annotate.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-annotate.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-annotate.c- Extension
.c- Size
- 25521 bytes
- Lines
- 952
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
builtin.hperf.hutil/color.hlinux/list.hutil/cache.hlinux/rbtree.hutil/symbol.hutil/debug.hutil/evlist.hutil/evsel.hutil/annotate.hutil/annotate-data.hutil/event.hsubcmd/parse-options.hutil/parse-events.hutil/sort.hutil/hist.hutil/dso.hutil/machine.hutil/map.hutil/session.hutil/tool.hutil/data.harch/common.hutil/block-range.hutil/map_symbol.hutil/branch.hutil/util.hui/progress.hdlfcn.herrno.hlinux/bitmap.h
Detected Declarations
struct perf_annotatefunction process_basic_blockfunction process_branch_stackfunction hist_iter__branch_callbackfunction process_branch_callbackfunction has_annotationfunction evsel__add_samplefunction process_sample_eventfunction hist_entry__stdio_annotatefunction print_annotate_data_statfunction print_annotate_item_statfunction list_for_each_entry_safefunction list_for_each_entryfunction hists__find_annotationsfunction __cmd_annotatefunction parse_percent_limitfunction parse_data_typefunction cmd_annotate
Annotated Snippet
struct perf_annotate {
struct perf_tool tool;
struct perf_session *session;
#ifdef HAVE_SLANG_SUPPORT
bool use_tui;
#endif
bool use_stdio, use_stdio2;
#ifdef HAVE_GTK2_SUPPORT
bool use_gtk;
#endif
bool skip_missing;
bool has_br_stack;
bool group_set;
bool data_type;
bool type_stat;
bool insn_stat;
float min_percent;
const char *sym_hist_filter;
const char *cpu_list;
const char *target_data_type;
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
};
/*
* Given one basic block:
*
* from to branch_i
* * ----> *
* |
* | block
* v
* * ----> *
* from to branch_i+1
*
* where the horizontal are the branches and the vertical is the executed
* block of instructions.
*
* We count, for each 'instruction', the number of blocks that covered it as
* well as count the ratio each branch is taken.
*
* We can do this without knowing the actual instruction stream by keeping
* track of the address ranges. We break down ranges such that there is no
* overlap and iterate from the start until the end.
*
* @acme: once we parse the objdump output _before_ processing the samples,
* we can easily fold the branch.cycles IPC bits in.
*/
static void process_basic_block(struct addr_map_symbol *start,
struct addr_map_symbol *end,
struct branch_flags *flags)
{
struct symbol *sym = start->ms.sym;
struct annotation *notes = sym ? symbol__annotation(sym) : NULL;
struct block_range_iter iter;
struct block_range *entry;
struct annotated_branch *branch;
/*
* Sanity; NULL isn't executable and the CPU cannot execute backwards
*/
if (!start->addr || start->addr > end->addr)
return;
iter = block_range__create(start->addr, end->addr);
if (!block_range_iter__valid(&iter))
return;
branch = annotation__get_branch(notes);
/*
* First block in range is a branch target.
*/
entry = block_range_iter(&iter);
assert(entry->is_target);
entry->entry++;
do {
entry = block_range_iter(&iter);
entry->coverage++;
entry->sym = sym;
if (branch)
branch->max_coverage = max(branch->max_coverage, entry->coverage);
} while (block_range_iter__next(&iter));
/*
* Last block in rage is a branch.
*/
Annotation
- Immediate include surface: `builtin.h`, `perf.h`, `util/color.h`, `linux/list.h`, `util/cache.h`, `linux/rbtree.h`, `util/symbol.h`, `util/debug.h`.
- Detected declarations: `struct perf_annotate`, `function process_basic_block`, `function process_branch_stack`, `function hist_iter__branch_callback`, `function process_branch_callback`, `function has_annotation`, `function evsel__add_sample`, `function process_sample_event`, `function hist_entry__stdio_annotate`, `function print_annotate_data_stat`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.