tools/perf/util/tp_pmu.c
Source file repositories/reference/linux-study-clean/tools/perf/util/tp_pmu.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/tp_pmu.c- Extension
.c- Size
- 4853 bytes
- Lines
- 209
- 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
tp_pmu.hpmus.hapi/fs/fs.hapi/fs/tracing_path.hapi/io_dir.hlinux/kernel.herrno.hstring.h
Detected Declarations
struct for_each_event_argsfunction tp_pmu__idfunction tp_pmu__for_each_tp_eventfunction tp_pmu__for_each_tp_sysfunction perf_pmu__is_tracepointfunction for_each_event_cbfunction for_each_event_sys_cbfunction tp_pmu__for_each_eventfunction num_events_cbfunction num_events_sys_cbfunction tp_pmu__num_eventsfunction tp_pmu__have_event
Annotated Snippet
struct for_each_event_args {
void *state;
pmu_event_callback cb;
const struct perf_pmu *pmu;
};
static int for_each_event_cb(void *state, const char *sys_name, const char *evt_name)
{
struct for_each_event_args *args = state;
char name[2 * FILENAME_MAX + 2];
/* 16 possible hex digits and 22 other characters and \0. */
char encoding[16 + 22];
char *format = NULL;
size_t format_size;
struct pmu_event_info info = {
.pmu = args->pmu,
.pmu_name = args->pmu->name,
.event_type_desc = "Tracepoint event",
};
char *tp_dir = get_events_file(sys_name);
char path[PATH_MAX];
int id, err;
if (!tp_dir)
return -1;
scnprintf(path, sizeof(path), "%s/%s/id", tp_dir, evt_name);
err = filename__read_int(path, &id);
if (err == 0) {
snprintf(encoding, sizeof(encoding), "tracepoint/config=0x%x/", id);
info.encoding_desc = encoding;
}
scnprintf(path, sizeof(path), "%s/%s/format", tp_dir, evt_name);
put_events_file(tp_dir);
err = filename__read_str(path, &format, &format_size);
if (err == 0) {
info.long_desc = format;
for (size_t i = 0 ; i < format_size; i++) {
/* Swap tabs to spaces due to some rendering issues. */
if (format[i] == '\t')
format[i] = ' ';
}
}
snprintf(name, sizeof(name), "%s:%s", sys_name, evt_name);
info.name = name;
err = args->cb(args->state, &info);
free(format);
return err;
}
static int for_each_event_sys_cb(void *state, const char *sys_name)
{
return tp_pmu__for_each_tp_event(sys_name, state, for_each_event_cb);
}
int tp_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_callback cb)
{
struct for_each_event_args args = {
.state = state,
.cb = cb,
.pmu = pmu,
};
return tp_pmu__for_each_tp_sys(&args, for_each_event_sys_cb);
}
static int num_events_cb(void *state, const char *sys_name __maybe_unused,
const char *evt_name __maybe_unused)
{
size_t *count = state;
(*count)++;
return 0;
}
static int num_events_sys_cb(void *state, const char *sys_name)
{
return tp_pmu__for_each_tp_event(sys_name, state, num_events_cb);
}
size_t tp_pmu__num_events(struct perf_pmu *pmu __maybe_unused)
{
size_t count = 0;
tp_pmu__for_each_tp_sys(&count, num_events_sys_cb);
return count;
}
bool tp_pmu__have_event(struct perf_pmu *pmu __maybe_unused, const char *name)
Annotation
- Immediate include surface: `tp_pmu.h`, `pmus.h`, `api/fs/fs.h`, `api/fs/tracing_path.h`, `api/io_dir.h`, `linux/kernel.h`, `errno.h`, `string.h`.
- Detected declarations: `struct for_each_event_args`, `function tp_pmu__id`, `function tp_pmu__for_each_tp_event`, `function tp_pmu__for_each_tp_sys`, `function perf_pmu__is_tracepoint`, `function for_each_event_cb`, `function for_each_event_sys_cb`, `function tp_pmu__for_each_event`, `function num_events_cb`, `function num_events_sys_cb`.
- 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.