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.

Dependency Surface

Detected Declarations

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

Implementation Notes