tools/perf/util/trace-event-scripting.c

Source file repositories/reference/linux-study-clean/tools/perf/util/trace-event-scripting.c

File Facts

System
Linux kernel
Corpus path
tools/perf/util/trace-event-scripting.c
Extension
.c
Size
10039 bytes
Lines
411
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 script_spec {
	struct list_head	node;
	struct scripting_ops	*ops;
	char			spec[];
};

static LIST_HEAD(script_specs);

static struct script_spec *script_spec__new(const char *spec,
					    struct scripting_ops *ops)
{
	struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1);

	if (s != NULL) {
		strcpy(s->spec, spec);
		s->ops = ops;
	}

	return s;
}

static void script_spec__add(struct script_spec *s)
{
	list_add_tail(&s->node, &script_specs);
}

static struct script_spec *script_spec__find(const char *spec)
{
	struct script_spec *s;

	list_for_each_entry(s, &script_specs, node)
		if (strcasecmp(s->spec, spec) == 0)
			return s;
	return NULL;
}

static int script_spec_register(const char *spec, struct scripting_ops *ops)
{
	struct script_spec *s;

	s = script_spec__find(spec);
	if (s)
		return -1;

	s = script_spec__new(spec, ops);
	if (!s)
		return -1;

	script_spec__add(s);
	return 0;
}

struct scripting_ops *script_spec__lookup(const char *spec)
{
	struct script_spec *s = script_spec__find(spec);

	if (!s)
		return NULL;

	return s->ops;
}

int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec))
{
	struct script_spec *s;
	int ret = 0;

	list_for_each_entry(s, &script_specs, node) {
		ret = cb(s->ops, s->spec);
		if (ret)
			break;
	}
	return ret;
}

void scripting_context__update(struct scripting_context *c,
			       union perf_event *event,
			       struct perf_sample *sample,
			       struct evsel *evsel,
			       struct addr_location *al,
			       struct addr_location *addr_al)
{
#ifdef HAVE_LIBTRACEEVENT
	const struct tep_event *tp_format = evsel__tp_format(evsel);

	c->pevent = tp_format ? tp_format->tep : NULL;
#else
	c->pevent = NULL;
#endif
	c->event_data = sample->raw_data;

Annotation

Implementation Notes