tools/perf/util/evlist.c

Source file repositories/reference/linux-study-clean/tools/perf/util/evlist.c

File Facts

System
Linux kernel
Corpus path
tools/perf/util/evlist.c
Extension
.c
Size
62928 bytes
Lines
2696
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

struct event_enable_time {
	int	start;
	int	end;
};

static int parse_event_enable_time(const char *str, struct event_enable_time *range, bool first)
{
	const char *fmt = first ? "%u - %u %n" : " , %u - %u %n";
	int ret, start, end, n;

	ret = sscanf(str, fmt, &start, &end, &n);
	if (ret != 2 || end <= start)
		return -EINVAL;
	if (range) {
		range->start = start;
		range->end = end;
	}
	return n;
}

static ssize_t parse_event_enable_times(const char *str, struct event_enable_time *range)
{
	int incr = !!range;
	bool first = true;
	ssize_t ret, cnt;

	for (cnt = 0; *str; cnt++) {
		ret = parse_event_enable_time(str, range, first);
		if (ret < 0)
			return ret;
		/* Check no overlap */
		if (!first && range && range->start <= range[-1].end)
			return -EINVAL;
		str += ret;
		range += incr;
		first = false;
	}
	return cnt;
}

/**
 * struct event_enable_timer - control structure for perf record -D/--delay.
 * @evlist: event list
 * @times: time ranges that events are enabled (N.B. this is also accessed as an
 *         array of int)
 * @times_cnt: number of time ranges
 * @timerfd: timer file descriptor
 * @pollfd_pos: position in @evlist array of file descriptors to poll (fdarray)
 * @times_step: current position in (int *)@times)[],
 *              refer event_enable_timer__process()
 *
 * Note, this structure is only used when there are time ranges, not when there
 * is only an initial delay.
 */
struct event_enable_timer {
	struct evlist *evlist;
	struct event_enable_time *times;
	size_t	times_cnt;
	int	timerfd;
	int	pollfd_pos;
	size_t	times_step;
};

static int str_to_delay(const char *str)
{
	char *endptr;
	long d;

	d = strtol(str, &endptr, 10);
	if (*endptr || d > INT_MAX || d < -1)
		return 0;
	return d;
}

int evlist__parse_event_enable_time(struct evlist *evlist, struct record_opts *opts,
				    const char *str, int unset)
{
	enum fdarray_flags flags = fdarray_flag__nonfilterable | fdarray_flag__non_perf_event;
	struct event_enable_timer *eet;
	ssize_t times_cnt;
	ssize_t ret;
	int err;

	if (unset)
		return 0;

	opts->target.initial_delay = str_to_delay(str);
	if (opts->target.initial_delay)
		return 0;

Annotation

Implementation Notes