tools/perf/bench/evlist-open-close.c
Source file repositories/reference/linux-study-clean/tools/perf/bench/evlist-open-close.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/bench/evlist-open-close.c- Extension
.c- Size
- 6967 bytes
- Lines
- 277
- 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.hstdio.hstdlib.hlimits.hbench.h../util/debug.h../util/stat.h../util/evlist.h../util/evsel.h../util/strbuf.h../util/record.h../util/parse-events.hinternal/threadmap.hinternal/cpumap.hlinux/perf_event.hlinux/kernel.hlinux/time64.hlinux/string.hsubcmd/parse-options.h
Detected Declarations
function timeval2usecfunction evlist__count_evsel_fdsfunction bench__do_evlist_open_closefunction bench_evlist_open_close__runfunction bench_evlist_open_close
Annotated Snippet
if (uid == UINT_MAX) {
pr_err("Invalid User: %s", uid_str);
ret = -EINVAL;
goto out_delete_evlist;
}
ret = parse_uid_filter(evlist, uid);
if (ret)
goto out_delete_evlist;
}
ret = evlist__create_maps(evlist, &opts.target);
if (ret < 0) {
pr_err("Not enough memory to create thread/cpu maps\n");
goto out_delete_evlist;
}
evlist__config(evlist, &opts, NULL);
return evlist;
out_delete_evlist:
evlist__delete(evlist);
return NULL;
}
static int bench__do_evlist_open_close(struct evlist *evlist)
{
char sbuf[STRERR_BUFSIZE];
int err = evlist__open(evlist);
if (err < 0) {
pr_err("evlist__open: %s\n", str_error_r(errno, sbuf, sizeof(sbuf)));
return err;
}
err = evlist__mmap(evlist, opts.mmap_pages);
if (err < 0) {
pr_err("evlist__mmap: %s\n", str_error_r(errno, sbuf, sizeof(sbuf)));
return err;
}
evlist__enable(evlist);
evlist__disable(evlist);
evlist__munmap(evlist);
evlist__close(evlist);
return 0;
}
static int bench_evlist_open_close__run(char *evstr, const char *uid_str)
{
// used to print statistics only
struct evlist *evlist = bench__create_evlist(evstr, uid_str);
double time_average, time_stddev;
struct timeval start, end, diff;
struct stats time_stats;
u64 runtime_us;
int i, err;
if (!evlist)
return -ENOMEM;
init_stats(&time_stats);
printf(" Number of cpus:\t%d\n", perf_cpu_map__nr(evlist->core.user_requested_cpus));
printf(" Number of threads:\t%d\n", evlist->core.threads->nr);
printf(" Number of events:\t%d (%d fds)\n",
evlist->core.nr_entries, evlist__count_evsel_fds(evlist));
printf(" Number of iterations:\t%d\n", iterations);
evlist__delete(evlist);
for (i = 0; i < iterations; i++) {
pr_debug("Started iteration %d\n", i);
evlist = bench__create_evlist(evstr, uid_str);
if (!evlist)
return -ENOMEM;
gettimeofday(&start, NULL);
err = bench__do_evlist_open_close(evlist);
if (err) {
evlist__delete(evlist);
return err;
}
gettimeofday(&end, NULL);
timersub(&end, &start, &diff);
runtime_us = timeval2usec(&diff);
update_stats(&time_stats, runtime_us);
evlist__delete(evlist);
Annotation
- Immediate include surface: `errno.h`, `inttypes.h`, `stdio.h`, `stdlib.h`, `limits.h`, `bench.h`, `../util/debug.h`, `../util/stat.h`.
- Detected declarations: `function timeval2usec`, `function evlist__count_evsel_fds`, `function bench__do_evlist_open_close`, `function bench_evlist_open_close__run`, `function bench_evlist_open_close`.
- 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.