tools/perf/tests/event-times.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/event-times.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/event-times.c- Extension
.c- Size
- 5509 bytes
- Lines
- 243
- 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
linux/compiler.hlinux/string.herrno.hinttypes.hstring.hsys/wait.hperf/cpumap.htests.hevlist.hevsel.hdebug.hparse-events.hthread_map.htarget.h
Detected Declarations
function attach__enable_on_execfunction detach__enable_on_execfunction attach__current_disabledfunction attach__current_enabledfunction detach__disablefunction attach__cpu_disabledfunction attach__cpu_enabledfunction test_timesfunction ways
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <linux/compiler.h>
#include <linux/string.h>
#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include <sys/wait.h>
#include <perf/cpumap.h>
#include "tests.h"
#include "evlist.h"
#include "evsel.h"
#include "debug.h"
#include "parse-events.h"
#include "thread_map.h"
#include "target.h"
static int attach__enable_on_exec(struct evlist *evlist)
{
struct evsel *evsel = evlist__last(evlist);
struct target target = {};
const char *argv[] = { "true", NULL, };
char sbuf[STRERR_BUFSIZE];
int err;
pr_debug("attaching to spawned child, enable on exec\n");
err = evlist__create_maps(evlist, &target);
if (err < 0) {
pr_debug("Not enough memory to create thread/cpu maps\n");
return err;
}
err = evlist__prepare_workload(evlist, &target, argv, false, NULL);
if (err < 0) {
pr_debug("Couldn't run the workload!\n");
return err;
}
evsel->core.attr.enable_on_exec = 1;
err = evlist__open(evlist);
if (err < 0) {
pr_debug("perf_evlist__open: %s\n",
str_error_r(errno, sbuf, sizeof(sbuf)));
return err;
}
return evlist__start_workload(evlist) == 1 ? TEST_OK : TEST_FAIL;
}
static int detach__enable_on_exec(struct evlist *evlist)
{
waitpid(evlist->workload.pid, NULL, 0);
return 0;
}
static int attach__current_disabled(struct evlist *evlist)
{
struct evsel *evsel = evlist__last(evlist);
struct perf_thread_map *threads;
int err;
pr_debug("attaching to current thread as disabled\n");
threads = thread_map__new_by_tid(getpid());
if (threads == NULL) {
pr_debug("thread_map__new\n");
return -1;
}
evsel->core.attr.disabled = 1;
err = evsel__open_per_thread(evsel, threads);
if (err) {
pr_debug("Failed to open event cpu-clock:u\n");
return err;
}
perf_thread_map__put(threads);
return evsel__enable(evsel) == 0 ? TEST_OK : TEST_FAIL;
}
static int attach__current_enabled(struct evlist *evlist)
{
struct evsel *evsel = evlist__last(evlist);
struct perf_thread_map *threads;
int err;
pr_debug("attaching to current thread as enabled\n");
Annotation
- Immediate include surface: `linux/compiler.h`, `linux/string.h`, `errno.h`, `inttypes.h`, `string.h`, `sys/wait.h`, `perf/cpumap.h`, `tests.h`.
- Detected declarations: `function attach__enable_on_exec`, `function detach__enable_on_exec`, `function attach__current_disabled`, `function attach__current_enabled`, `function detach__disable`, `function attach__cpu_disabled`, `function attach__cpu_enabled`, `function test_times`, `function ways`.
- 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.