tools/lib/perf/tests/test-evsel.c
Source file repositories/reference/linux-study-clean/tools/lib/perf/tests/test-evsel.c
File Facts
- System
- Linux kernel
- Corpus path
tools/lib/perf/tests/test-evsel.c- Extension
.c- Size
- 9495 bytes
- Lines
- 368
- 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
stdarg.hstdio.hstring.hlinux/perf_event.hlinux/kernel.hperf/cpumap.hperf/threadmap.hperf/evsel.hinternal/evsel.hinternal/tests.htests.h
Detected Declarations
function libperf_printfunction test_stat_cpufunction test_stat_threadfunction test_stat_thread_enablefunction test_stat_user_readfunction test_stat_read_format_singlefunction test_stat_read_format_groupfunction test_stat_read_formatfunction test_evsel
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <linux/perf_event.h>
#include <linux/kernel.h>
#include <perf/cpumap.h>
#include <perf/threadmap.h>
#include <perf/evsel.h>
#include <internal/evsel.h>
#include <internal/tests.h>
#include "tests.h"
static int libperf_print(enum libperf_print_level level,
const char *fmt, va_list ap)
{
return vfprintf(stderr, fmt, ap);
}
static int test_stat_cpu(void)
{
struct perf_cpu_map *cpus;
struct perf_evsel *evsel;
struct perf_event_attr attr = {
.type = PERF_TYPE_SOFTWARE,
.config = PERF_COUNT_SW_CPU_CLOCK,
};
int err, idx;
cpus = perf_cpu_map__new_online_cpus();
__T("failed to create cpus", cpus);
evsel = perf_evsel__new(&attr);
__T("failed to create evsel", evsel);
err = perf_evsel__open(evsel, cpus, NULL);
__T("failed to open evsel", err == 0);
for (idx = 0; idx < perf_cpu_map__nr(cpus); idx++) {
struct perf_counts_values counts = { .val = 0 };
perf_evsel__read(evsel, idx, 0, &counts);
__T("failed to read value for evsel", counts.val != 0);
}
perf_evsel__close(evsel);
perf_evsel__delete(evsel);
perf_cpu_map__put(cpus);
return 0;
}
static int test_stat_thread(void)
{
struct perf_counts_values counts = { .val = 0 };
struct perf_thread_map *threads;
struct perf_evsel *evsel;
struct perf_event_attr attr = {
.type = PERF_TYPE_SOFTWARE,
.config = PERF_COUNT_SW_TASK_CLOCK,
};
int err;
threads = perf_thread_map__new_dummy();
__T("failed to create threads", threads);
perf_thread_map__set_pid(threads, 0, 0);
evsel = perf_evsel__new(&attr);
__T("failed to create evsel", evsel);
err = perf_evsel__open(evsel, NULL, threads);
__T("failed to open evsel", err == 0);
perf_evsel__read(evsel, 0, 0, &counts);
__T("failed to read value for evsel", counts.val != 0);
perf_evsel__close(evsel);
perf_evsel__delete(evsel);
perf_thread_map__put(threads);
return 0;
}
static int test_stat_thread_enable(void)
{
struct perf_counts_values counts = { .val = 0 };
struct perf_thread_map *threads;
struct perf_evsel *evsel;
struct perf_event_attr attr = {
Annotation
- Immediate include surface: `stdarg.h`, `stdio.h`, `string.h`, `linux/perf_event.h`, `linux/kernel.h`, `perf/cpumap.h`, `perf/threadmap.h`, `perf/evsel.h`.
- Detected declarations: `function libperf_print`, `function test_stat_cpu`, `function test_stat_thread`, `function test_stat_thread_enable`, `function test_stat_user_read`, `function test_stat_read_format_single`, `function test_stat_read_format_group`, `function test_stat_read_format`, `function test_evsel`.
- 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.