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

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

File Facts

System
Linux kernel
Corpus path
tools/perf/util/scripting-engines/trace-event-python.c
Extension
.c
Size
59770 bytes
Lines
2210
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

call_object(tables->context_switch_handler, t, "context_switch");

	Py_DECREF(t);

	return 0;
}

static int python_process_call_return(struct call_return *cr, u64 *parent_db_id,
				      void *data)
{
	struct db_export *dbe = data;

	return db_export__call_return(dbe, cr, parent_db_id);
}

static void python_process_general_event(struct perf_sample *sample,
					 struct evsel *evsel,
					 struct addr_location *al,
					 struct addr_location *addr_al)
{
	PyObject *handler, *t, *dict, *callchain;
	static char handler_name[64];
	unsigned n = 0;

	snprintf(handler_name, sizeof(handler_name), "%s", "process_event");

	handler = get_handler(handler_name);
	if (!handler)
		return;

	/*
	 * Use the MAX_FIELDS to make the function expandable, though
	 * currently there is only one item for the tuple.
	 */
	t = PyTuple_New(MAX_FIELDS);
	if (!t)
		Py_FatalError("couldn't create Python tuple");

	/* ip unwinding */
	callchain = python_process_callchain(sample, evsel, al);
	dict = get_perf_sample_dict(sample, evsel, al, addr_al, callchain);

	PyTuple_SetItem(t, n++, dict);
	if (_PyTuple_Resize(&t, n) == -1)
		Py_FatalError("error resizing Python tuple");

	call_object(handler, t, handler_name);

	Py_DECREF(t);
}

static void python_process_event(union perf_event *event,
				 struct perf_sample *sample,
				 struct evsel *evsel,
				 struct addr_location *al,
				 struct addr_location *addr_al)
{
	struct tables *tables = &tables_global;

	scripting_context__update(scripting_context, event, sample, evsel, al, addr_al);

	switch (evsel->core.attr.type) {
	case PERF_TYPE_TRACEPOINT:
		python_process_tracepoint(sample, evsel, al, addr_al);
		break;
	/* Reserve for future process_hw/sw/raw APIs */
	default:
		if (tables->db_export_mode)
			db_export__sample(&tables->dbe, event, sample, evsel, al, addr_al);
		else
			python_process_general_event(sample, evsel, al, addr_al);
	}
}

static void python_process_throttle(union perf_event *event,
				    struct perf_sample *sample,
				    struct machine *machine)
{
	const char *handler_name;
	PyObject *handler, *t;

	if (event->header.type == PERF_RECORD_THROTTLE)
		handler_name = "throttle";
	else
		handler_name = "unthrottle";
	handler = get_handler(handler_name);
	if (!handler)
		return;

	t = tuple_new(6);

Annotation

Implementation Notes