tools/perf/util/print-events.c
Source file repositories/reference/linux-study-clean/tools/perf/util/print-events.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/print-events.c- Extension
.c- Size
- 8649 bytes
- Lines
- 358
- 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
dirent.herrno.hstdio.hstdlib.hstring.hfcntl.hsys/param.hunistd.hapi/fs/tracing_path.hapi/io.hlinux/stddef.hlinux/perf_event.hlinux/zalloc.hsubcmd/pager.hbuild-id.hdebug.hevsel.hmetricgroup.hparse-events.hpmu.hpmus.hprint-events.hprobe-file.hstring2.hstrlist.htracepoint.hpfm.hthread_map.htool_pmu.hutil.h
Detected Declarations
struct mepfunction print_sdt_eventsfunction list_for_each_entryfunction strlist__for_each_entryfunction is_event_supportedfunction mep_cmpfunction mep_deletefunction metricgroup__add_to_mep_groups_callbackfunction metricgroup__printfunction print_events
Annotated Snippet
struct mep {
/** nd - RB-tree element. */
struct rb_node nd;
/** @metric_group: Owned metric group name, separated others with ';'. */
char *metric_group;
const char *metric_name;
const char *metric_desc;
const char *metric_long_desc;
const char *metric_expr;
const char *metric_threshold;
const char *metric_unit;
const char *pmu_name;
};
static int mep_cmp(struct rb_node *rb_node, const void *entry)
{
struct mep *a = container_of(rb_node, struct mep, nd);
struct mep *b = (struct mep *)entry;
int ret;
ret = strcmp(a->metric_group, b->metric_group);
if (ret)
return ret;
return strcmp(a->metric_name, b->metric_name);
}
static struct rb_node *mep_new(struct rblist *rl __maybe_unused, const void *entry)
{
struct mep *me = malloc(sizeof(struct mep));
if (!me)
return NULL;
memcpy(me, entry, sizeof(struct mep));
return &me->nd;
}
static void mep_delete(struct rblist *rl __maybe_unused,
struct rb_node *nd)
{
struct mep *me = container_of(nd, struct mep, nd);
zfree(&me->metric_group);
free(me);
}
static struct mep *mep_lookup(struct rblist *groups, const char *metric_group,
const char *metric_name)
{
struct rb_node *nd;
struct mep me = {
.metric_group = strdup(metric_group),
.metric_name = metric_name,
};
nd = rblist__find(groups, &me);
if (nd) {
free(me.metric_group);
return container_of(nd, struct mep, nd);
}
rblist__add_node(groups, &me);
nd = rblist__find(groups, &me);
if (nd)
return container_of(nd, struct mep, nd);
return NULL;
}
static int metricgroup__add_to_mep_groups_callback(const struct pmu_metric *pm,
const struct pmu_metrics_table *table __maybe_unused,
void *vdata)
{
struct rblist *groups = vdata;
const char *g;
char *omg, *mg;
mg = strdup(pm->metric_group ?: pm->metric_name);
if (!mg)
return -ENOMEM;
omg = mg;
while ((g = strsep(&mg, ";")) != NULL) {
struct mep *me;
g = skip_spaces(g);
if (strlen(g))
me = mep_lookup(groups, g, pm->metric_name);
else
me = mep_lookup(groups, pm->metric_name, pm->metric_name);
if (me) {
me->metric_desc = pm->desc;
Annotation
- Immediate include surface: `dirent.h`, `errno.h`, `stdio.h`, `stdlib.h`, `string.h`, `fcntl.h`, `sys/param.h`, `unistd.h`.
- Detected declarations: `struct mep`, `function print_sdt_events`, `function list_for_each_entry`, `function strlist__for_each_entry`, `function is_event_supported`, `function mep_cmp`, `function mep_delete`, `function metricgroup__add_to_mep_groups_callback`, `function metricgroup__print`, `function print_events`.
- 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.