tools/lib/perf/tests/test-evlist.c
Source file repositories/reference/linux-study-clean/tools/lib/perf/tests/test-evlist.c
File Facts
- System
- Linux kernel
- Corpus path
tools/lib/perf/tests/test-evlist.c- Extension
.c- Size
- 13817 bytes
- Lines
- 590
- 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
inttypes.hsched.hstdio.hstdarg.hunistd.hstdlib.hlinux/perf_event.hlinux/limits.hsys/types.hsys/wait.hsys/prctl.hperf/cpumap.hperf/threadmap.hperf/evlist.hperf/evsel.hperf/mmap.hperf/event.hinternal/tests.hapi/fs/fs.htests.hinternal/evsel.h
Detected Declarations
function libperf_printfunction test_stat_cpufunction perf_evlist__for_each_evselfunction test_stat_threadfunction perf_evlist__for_each_evselfunction test_stat_thread_enablefunction perf_evlist__for_each_evselfunction perf_evlist__for_each_evselfunction test_mmap_threadfunction perf_evlist__for_each_mmapfunction test_mmap_cpusfunction perf_cpu_map__for_each_cpufunction perf_evlist__for_each_mmapfunction display_errorfunction test_stat_multiplexingfunction test_evlist
Annotated Snippet
while ((event = perf_mmap__read_event(map)) != NULL) {
count++;
perf_mmap__consume(map);
}
perf_mmap__read_done(map);
}
/* calls perf_evlist__munmap/perf_evlist__close */
perf_evlist__delete(evlist);
perf_thread_map__put(threads);
perf_cpu_map__put(cpus);
/*
* The generated prctl calls should match the
* number of events in the buffer.
*/
__T("failed count", count == 100);
return 0;
}
static int test_mmap_cpus(void)
{
struct perf_evlist *evlist;
struct perf_evsel *evsel;
struct perf_mmap *map;
struct perf_cpu_map *cpus;
struct perf_event_attr attr = {
.type = PERF_TYPE_TRACEPOINT,
.sample_period = 1,
.wakeup_watermark = 1,
.disabled = 1,
};
cpu_set_t saved_mask;
char path[PATH_MAX];
int id, err, tmp;
struct perf_cpu cpu;
union perf_event *event;
int count = 0;
snprintf(path, PATH_MAX, "%s/kernel/debug/tracing/events/syscalls/sys_enter_prctl/id",
sysfs__mountpoint());
if (filename__read_int(path, &id)) {
fprintf(stderr, "error: failed to get tracepoint id: %s\n", path);
return -1;
}
attr.config = id;
cpus = perf_cpu_map__new_online_cpus();
__T("failed to create cpus", cpus);
evlist = perf_evlist__new();
__T("failed to create evlist", evlist);
evsel = perf_evsel__new(&attr);
__T("failed to create evsel1", evsel);
__T("failed to set leader", evsel->leader == evsel);
perf_evlist__add(evlist, evsel);
perf_evlist__set_maps(evlist, cpus, NULL);
err = perf_evlist__open(evlist);
__T("failed to open evlist", err == 0);
err = perf_evlist__mmap(evlist, 4);
__T("failed to mmap evlist", err == 0);
perf_evlist__enable(evlist);
err = sched_getaffinity(0, sizeof(saved_mask), &saved_mask);
__T("sched_getaffinity failed", err == 0);
perf_cpu_map__for_each_cpu(cpu, tmp, cpus) {
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(cpu.cpu, &mask);
err = sched_setaffinity(0, sizeof(mask), &mask);
__T("sched_setaffinity failed", err == 0);
prctl(0, 0, 0, 0, 0);
}
err = sched_setaffinity(0, sizeof(saved_mask), &saved_mask);
Annotation
- Immediate include surface: `inttypes.h`, `sched.h`, `stdio.h`, `stdarg.h`, `unistd.h`, `stdlib.h`, `linux/perf_event.h`, `linux/limits.h`.
- Detected declarations: `function libperf_print`, `function test_stat_cpu`, `function perf_evlist__for_each_evsel`, `function test_stat_thread`, `function perf_evlist__for_each_evsel`, `function test_stat_thread_enable`, `function perf_evlist__for_each_evsel`, `function perf_evlist__for_each_evsel`, `function test_mmap_thread`, `function perf_evlist__for_each_mmap`.
- 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.