tools/perf/util/synthetic-events.c
Source file repositories/reference/linux-study-clean/tools/perf/util/synthetic-events.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/synthetic-events.c- Extension
.c- Size
- 67949 bytes
- Lines
- 2733
- 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
util/cgroup.hutil/data.hutil/debug.hutil/dso.hutil/event.hutil/evlist.hutil/machine.hutil/map.hutil/map_symbol.hutil/branch.hutil/memswap.hutil/namespaces.hutil/session.hutil/stat.hutil/symbol.hutil/synthetic-events.hutil/target.hutil/time-utils.hlinux/bitops.hlinux/kernel.hlinux/string.hlinux/zalloc.hlinux/perf_event.hasm/bug.hperf/evsel.hperf/cpumap.hinternal/lib.hinternal/threadmap.hperf/threadmap.hsymbol/kallsyms.hdirent.herrno.h
Detected Declarations
struct perf_event__synthesize_modules_maps_cb_argsstruct synthesize_threads_argstruct synthesize_cpu_map_datafunction perf_tool__process_synth_eventfunction perf_event__get_comm_idsfunction perf_event__prepare_commfunction perf_event__synthesize_commfunction perf_event__get_ns_link_infofunction perf_event__synthesize_namespacesfunction perf_event__synthesize_forkfunction read_proc_maps_linefunction perf_record_mmap2__read_build_idfunction perf_event__synthesize_mmap_eventsfunction perf_event__synthesize_cgroupfunction perf_event__walk_cgroup_treefunction perf_event__synthesize_cgroupsfunction perf_event__synthesize_cgroupsfunction perf_event__synthesize_modules_maps_cbfunction perf_event__synthesize_modulesfunction filter_taskfunction __event__synthesize_threadfunction perf_event__synthesize_thread_mapfunction __perf_event__synthesize_threadsfunction perf_event__synthesize_threadsfunction perf_event__synthesize_extra_kmapsfunction __perf_event__synthesize_kernel_mmapfunction perf_event__synthesize_kernel_mmapfunction perf_event__synthesize_thread_map2function synthesize_cpusfunction synthesize_maskfunction perf_cpu_map__for_each_cpufunction synthesize_range_cpusfunction cpu_map_data__synthesizefunction perf_event__synthesize_cpu_mapfunction perf_event__synthesize_stat_configfunction perf_event__synthesize_statfunction perf_event__synthesize_stat_roundfunction perf_event__sample_event_sizefunction perf_synthesize_sample_weightfunction sample_read_group__for_eachfunction perf_event__synthesize_samplefunction perf_event__synthesize_id_samplefunction __perf_event__synthesize_id_indexfunction perf_event__synthesize_id_indexfunction __machine__synthesize_threadsfunction machine__synthesize_threadsfunction perf_event__synthesize_event_update_unitfunction perf_event__synthesize_event_update_scale
Annotated Snippet
struct perf_event__synthesize_modules_maps_cb_args {
const struct perf_tool *tool;
perf_event__handler_t process;
struct machine *machine;
union perf_event *event;
};
static int perf_event__synthesize_modules_maps_cb(struct map *map, void *data)
{
struct perf_event__synthesize_modules_maps_cb_args *args = data;
union perf_event *event = args->event;
struct dso *dso;
size_t size;
if (!__map__is_kmodule(map))
return 0;
dso = map__dso(map);
if (!symbol_conf.no_buildid_mmap2) {
size = PERF_ALIGN(dso__long_name_len(dso) + 1, sizeof(u64));
event->mmap2.header.type = PERF_RECORD_MMAP2;
event->mmap2.header.size = (sizeof(event->mmap2) -
(sizeof(event->mmap2.filename) - size));
memset(event->mmap2.filename + size, 0, args->machine->id_hdr_size);
event->mmap2.header.size += args->machine->id_hdr_size;
event->mmap2.start = map__start(map);
event->mmap2.len = map__size(map);
event->mmap2.pid = args->machine->pid;
memcpy(event->mmap2.filename, dso__long_name(dso), dso__long_name_len(dso) + 1);
/* Clear stale build ID from previous module iteration */
event->mmap2.header.misc &= ~PERF_RECORD_MISC_MMAP_BUILD_ID;
memset(event->mmap2.build_id, 0, sizeof(event->mmap2.build_id));
event->mmap2.build_id_size = 0;
perf_record_mmap2__read_build_id(&event->mmap2, args->machine, false);
} else {
size = PERF_ALIGN(dso__long_name_len(dso) + 1, sizeof(u64));
event->mmap.header.type = PERF_RECORD_MMAP;
event->mmap.header.size = (sizeof(event->mmap) -
(sizeof(event->mmap.filename) - size));
memset(event->mmap.filename + size, 0, args->machine->id_hdr_size);
event->mmap.header.size += args->machine->id_hdr_size;
event->mmap.start = map__start(map);
event->mmap.len = map__size(map);
event->mmap.pid = args->machine->pid;
memcpy(event->mmap.filename, dso__long_name(dso), dso__long_name_len(dso) + 1);
}
if (perf_tool__process_synth_event(args->tool, event, args->machine, args->process) != 0)
return -1;
return 0;
}
int perf_event__synthesize_modules(const struct perf_tool *tool, perf_event__handler_t process,
struct machine *machine)
{
int rc;
struct maps *maps = machine__kernel_maps(machine);
struct perf_event__synthesize_modules_maps_cb_args args = {
.tool = tool,
.process = process,
.machine = machine,
};
size_t size = symbol_conf.no_buildid_mmap2
? sizeof(args.event->mmap)
: sizeof(args.event->mmap2);
args.event = zalloc(size + machine->id_hdr_size);
if (args.event == NULL) {
pr_debug("Not enough memory synthesizing mmap event "
"for kernel modules\n");
return -1;
}
/*
* kernel uses 0 for user space maps, see kernel/perf_event.c
* __perf_event_mmap
*/
if (machine__is_host(machine))
args.event->header.misc = PERF_RECORD_MISC_KERNEL;
else
args.event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
rc = maps__for_each_map(maps, perf_event__synthesize_modules_maps_cb, &args);
free(args.event);
Annotation
- Immediate include surface: `util/cgroup.h`, `util/data.h`, `util/debug.h`, `util/dso.h`, `util/event.h`, `util/evlist.h`, `util/machine.h`, `util/map.h`.
- Detected declarations: `struct perf_event__synthesize_modules_maps_cb_args`, `struct synthesize_threads_arg`, `struct synthesize_cpu_map_data`, `function perf_tool__process_synth_event`, `function perf_event__get_comm_ids`, `function perf_event__prepare_comm`, `function perf_event__synthesize_comm`, `function perf_event__get_ns_link_info`, `function perf_event__synthesize_namespaces`, `function perf_event__synthesize_fork`.
- 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.