tools/perf/util/annotate.c
Source file repositories/reference/linux-study-clean/tools/perf/util/annotate.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/annotate.c- Extension
.c- Size
- 79904 bytes
- Lines
- 3206
- 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
errno.hinttypes.hstdlib.hutil.hui/ui.hsort.hbuild-id.hcolor.hconfig.hdisasm.hdso.henv.hmap.hmaps.hsymbol.hsrcline.hunits.hdebug.hdebuginfo.hannotate.hannotate-data.hevsel.hevlist.hbpf-event.hbpf-utils.hblock-range.hstring2.hdwarf-regs.hutil/event.hutil/sharded_mutex.harch/common.hnamespaces.h
Detected Declarations
struct type_hash_entrystruct basic_block_datastruct basic_block_linkfunction sym_hist_hashfunction sym_hist_equalfunction annotated_source__deletefunction annotated_source__alloc_histogramsfunction symbol__annotate_zero_histogramsfunction __symbol__account_cyclesfunction __symbol__inc_addr_samplesfunction symbol__inc_addr_samplesfunction symbol__account_br_cntrfunction symbol__account_cyclesfunction addr_map_symbol__account_cyclesfunction list_for_each_entryfunction annotation__count_insnfunction list_for_each_entry_fromfunction annotated_branch__deletefunction annotation__count_and_fillfunction list_for_each_entry_fromfunction annotation__compute_ipcfunction addr_map_symbol__inc_samplesfunction hist_entry__inc_addr_samplesfunction annotation__exitfunction annotation__init_sharded_mutexfunction annotation__hashfunction annotation__trylockfunction annotation_line__addfunction annotation_line__nextfunction annotate__branch_printffunction disasm_line__printfunction needs_type_infofunction annotation_line__printfunction list_for_each_entry_fromfunction calc_percentfunction annotation__calc_percentfunction list_for_each_entryfunction for_each_group_evselfunction symbol__calc_percentfunction thread__get_archfunction symbol__annotatefunction for_each_group_evselfunction insert_source_linefunction cmp_source_linefunction __resort_source_linefunction resort_source_linefunction print_summaryfunction symbol__annotate_hits
Annotated Snippet
struct type_hash_entry {
struct annotated_data_type *type;
int offset;
};
static int disasm_line__snprint_type_info(struct disasm_line *dl,
char *buf, int len,
struct annotation_print_data *apd)
{
struct annotated_data_type *data_type = NULL;
struct type_hash_entry *entry = NULL;
char member[256];
int offset = 0;
int printed;
scnprintf(buf, len, " ");
if (!annotate_opts.code_with_type || apd->dbg == NULL)
return 1;
if (apd->type_hash) {
hashmap__find(apd->type_hash, dl->al.offset, &entry);
if (entry != NULL) {
data_type = entry->type;
offset = entry->offset;
}
}
if (data_type == NULL)
data_type = __hist_entry__get_data_type(apd->he, apd->arch, apd->dbg, dl, &offset);
if (apd->type_hash && entry == NULL) {
entry = malloc(sizeof(*entry));
if (entry != NULL) {
entry->type = data_type;
entry->offset = offset;
hashmap__add(apd->type_hash, dl->al.offset, entry);
}
}
if (!needs_type_info(data_type))
return 1;
printed = scnprintf(buf, len, "\t\t# data-type: %s", data_type->self.type_name);
if (data_type != &stackop_type && data_type != &canary_type && len > printed)
printed += scnprintf(buf + printed, len - printed, " +%#x", offset);
if (annotated_data_type__get_member_name(data_type, member, sizeof(member), offset) &&
len > printed) {
printed += scnprintf(buf + printed, len - printed, " (%s)", member);
}
return printed;
}
void annotation_line__write(struct annotation_line *al, struct annotation *notes,
const struct annotation_write_ops *wops,
struct annotation_print_data *apd)
{
bool current_entry = wops->current_entry;
bool change_color = wops->change_color;
double percent_max = annotation_line__max_percent(al, annotate_opts.percent_type);
int width = wops->width;
int pcnt_width = annotation__pcnt_width(notes);
int cycles_width = annotation__cycles_width(notes);
bool show_title = false;
char bf[256];
int printed;
void *obj = wops->obj;
int (*obj__set_color)(void *obj, int color) = wops->set_color;
void (*obj__set_percent_color)(void *obj, double percent, bool current) = wops->set_percent_color;
int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current) = wops->set_jumps_percent_color;
void (*obj__printf)(void *obj, const char *fmt, ...) = wops->printf;
void (*obj__write_graph)(void *obj, int graph) = wops->write_graph;
if (wops->first_line && (al->offset == -1 || percent_max == 0.0)) {
if (notes->branch && al->cycles) {
if (al->cycles->ipc == 0.0 && al->cycles->avg == 0)
show_title = true;
} else
show_title = true;
}
if (al->offset != -1 && percent_max != 0.0) {
int i;
for (i = 0; i < al->data_nr; i++) {
double percent;
percent = annotation_data__percent(&al->data[i],
Annotation
- Immediate include surface: `errno.h`, `inttypes.h`, `stdlib.h`, `util.h`, `ui/ui.h`, `sort.h`, `build-id.h`, `color.h`.
- Detected declarations: `struct type_hash_entry`, `struct basic_block_data`, `struct basic_block_link`, `function sym_hist_hash`, `function sym_hist_equal`, `function annotated_source__delete`, `function annotated_source__alloc_histograms`, `function symbol__annotate_zero_histograms`, `function __symbol__account_cycles`, `function __symbol__inc_addr_samples`.
- 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.