tools/perf/tests/perf-record.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/perf-record.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/perf-record.c- Extension
.c- Size
- 9593 bytes
- Lines
- 376
- 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.hlinux/string.hsched.hperf/mmap.hevent.hevlist.hevsel.hdebug.hrecord.htests.hutil/mmap.hutil/sample.hutil/cpumap.h
Detected Declarations
function sched__get_first_possible_cpufunction test__PERF_RECORD
Annotated Snippet
if (errno == EINVAL && nrcpus < (cpu__max_cpu().cpu << 8)) {
nrcpus = nrcpus << 2;
goto realloc;
}
perror("sched_getaffinity");
return -1;
}
for (i = 0; i < nrcpus; i++) {
if (CPU_ISSET_S(i, size, maskp)) {
if (cpu == -1)
cpu = i;
else
CPU_CLR_S(i, size, maskp);
}
}
return cpu;
}
static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{
struct record_opts opts = {
.target = {
.uses_mmap = true,
},
.no_buffering = true,
.mmap_pages = 256,
};
int nrcpus = cpu__max_cpu().cpu;
cpu_set_t *cpu_mask;
size_t cpu_mask_size;
struct evlist *evlist = evlist__new_dummy();
struct evsel *evsel;
struct perf_sample sample;
const char *cmd = "sleep";
const char *argv[] = { cmd, "1", NULL, };
char *bname, *mmap_filename;
u64 prev_time = 0;
bool found_cmd_mmap = false,
found_coreutils_mmap = false,
found_libc_mmap = false,
found_vdso_mmap = false,
found_ld_mmap = false;
int err = -1, errs = 0, i, wakeups = 0;
u32 cpu;
int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, };
char sbuf[STRERR_BUFSIZE];
cpu_mask = CPU_ALLOC(nrcpus);
if (!cpu_mask) {
pr_debug("failed to create cpumask\n");
goto out;
}
cpu_mask_size = CPU_ALLOC_SIZE(nrcpus);
CPU_ZERO_S(cpu_mask_size, cpu_mask);
perf_sample__init(&sample, /*all=*/false);
if (evlist == NULL) { /* Fallback for kernels lacking PERF_COUNT_SW_DUMMY */
struct target target = {};
evlist = evlist__new_default(&target, /*sample_callchains=*/false);
}
if (evlist == NULL) {
pr_debug("Not enough memory to create evlist\n");
CPU_FREE(cpu_mask);
goto out;
}
/*
* Create maps of threads and cpus to monitor. In this case
* we start with all threads and cpus (-1, -1) but then in
* evlist__prepare_workload we'll fill in the only thread
* we're monitoring, the one forked there.
*/
err = evlist__create_maps(evlist, &opts.target);
if (err < 0) {
pr_debug("Not enough memory to create thread/cpu maps\n");
goto out_delete_evlist;
}
/*
* Prepare the workload in argv[] to run, it'll fork it, and then wait
* for evlist__start_workload() to exec it. This is done this way
* so that we have time to open the evlist (calling sys_perf_event_open
* on all the fds) and then mmap them.
*/
err = evlist__prepare_workload(evlist, &opts.target, argv, false, NULL);
Annotation
- Immediate include surface: `errno.h`, `inttypes.h`, `linux/string.h`, `sched.h`, `perf/mmap.h`, `event.h`, `evlist.h`, `evsel.h`.
- Detected declarations: `function sched__get_first_possible_cpu`, `function test__PERF_RECORD`.
- 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.