tools/perf/ui/hist.c
Source file repositories/reference/linux-study-clean/tools/perf/ui/hist.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/ui/hist.c- Extension
.c- Size
- 32335 bytes
- Lines
- 1274
- 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
errno.hinttypes.hmath.hstdlib.hstring.hlinux/compiler.h../util/callchain.h../util/debug.h../util/hist.h../util/sort.h../util/evsel.h../util/evlist.h../util/mem-events.h../util/string2.h../util/thread.h../util/util.h
Detected Declarations
struct hpp_fmt_valuefunction __hpp__fmt_printfunction __hpp__fmtfunction list_for_each_entryfunction hpp__fmtfunction hpp__fmt_accfunction hpp__fmt_mem_statfunction field_cmpfunction hist_entry__new_pairfunction list_for_each_entryfunction list_for_each_entryfunction __hpp__group_sort_idxfunction __hpp__sortfunction __hpp__sort_accfunction hpp__mem_stat_typefunction hpp__sort_mem_statfunction hpp__width_fnfunction for_each_group_evselfunction hpp__header_fnfunction hpp__header_mem_stat_fnfunction hpp_color_scnprintffunction hpp_entry_scnprintffunction hpp__nop_cmpfunction perf_hpp__is_mem_stat_entryfunction perf_hpp__is_hpp_entryfunction hpp__equalfunction hpp__equal_mem_statfunction fmt_freefunction fmt_equalfunction perf_hpp__initfunction setup_overheadfunction perf_hpp_list__column_registerfunction perf_hpp_list__register_sort_fieldfunction perf_hpp_list__prepend_sort_fieldfunction perf_hpp__column_unregisterfunction perf_hpp__cancel_cumulatefunction perf_hpp_list__for_each_format_safefunction evlist__for_each_entryfunction list_for_each_entryfunction perf_hpp__cancel_latencyfunction perf_hpp_list__for_each_format_safefunction evlist__for_each_entryfunction list_for_each_entryfunction perf_hpp__setup_output_fieldfunction perf_hpp_list__for_each_formatfunction perf_hpp__append_sort_keysfunction perf_hpp_list__for_each_sort_listfunction perf_hpp__reset_output_field
Annotated Snippet
struct hpp_fmt_value {
struct hists *hists;
u64 val;
int samples;
};
static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
hpp_field_fn get_field, const char *fmt, int len,
hpp_snprint_fn print_fn, enum perf_hpp_fmt_type fmtype)
{
int ret = 0;
struct hists *hists = he->hists;
struct evsel *evsel = hists_to_evsel(hists);
struct evsel *pos;
char *buf = hpp->buf;
size_t size = hpp->size;
int i = 0, nr_members = 1;
struct hpp_fmt_value *values;
if (evsel__is_group_event(evsel))
nr_members = evsel->core.nr_members;
values = calloc(nr_members, sizeof(*values));
if (values == NULL)
return 0;
values[0].hists = evsel__hists(evsel);
values[0].val = get_field(he);
values[0].samples = he->stat.nr_events;
if (evsel__is_group_event(evsel)) {
struct hist_entry *pair;
for_each_group_member(pos, evsel)
values[++i].hists = evsel__hists(pos);
list_for_each_entry(pair, &he->pairs.head, pairs.node) {
for (i = 0; i < nr_members; i++) {
if (values[i].hists != pair->hists)
continue;
values[i].val = get_field(pair);
values[i].samples = pair->stat.nr_events;
break;
}
}
}
for (i = 0; i < nr_members; i++) {
if (symbol_conf.skip_empty &&
values[i].hists->stats.nr_samples == 0)
continue;
ret += __hpp__fmt_print(hpp, values[i].hists, values[i].val,
values[i].samples, fmt, len,
print_fn, fmtype);
}
free(values);
/*
* Restore original buf and size as it's where caller expects
* the result will be saved.
*/
hpp->buf = buf;
hpp->size = size;
return ret;
}
int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
struct hist_entry *he, hpp_field_fn get_field,
const char *fmtstr, hpp_snprint_fn print_fn,
enum perf_hpp_fmt_type fmtype)
{
int len = max(fmt->user_len ?: fmt->len, (int)strlen(fmt->name));
if (symbol_conf.field_sep) {
return __hpp__fmt(hpp, he, get_field, fmtstr, 1,
print_fn, fmtype);
}
if (fmtype == PERF_HPP_FMT_TYPE__PERCENT || fmtype == PERF_HPP_FMT_TYPE__LATENCY)
len -= 2; /* 2 for a space and a % sign */
else
len -= 1;
return __hpp__fmt(hpp, he, get_field, fmtstr, len, print_fn, fmtype);
}
Annotation
- Immediate include surface: `errno.h`, `inttypes.h`, `math.h`, `stdlib.h`, `string.h`, `linux/compiler.h`, `../util/callchain.h`, `../util/debug.h`.
- Detected declarations: `struct hpp_fmt_value`, `function __hpp__fmt_print`, `function __hpp__fmt`, `function list_for_each_entry`, `function hpp__fmt`, `function hpp__fmt_acc`, `function hpp__fmt_mem_stat`, `function field_cmp`, `function hist_entry__new_pair`, `function list_for_each_entry`.
- 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.