diff mbox series

[07/10] trace-cruncher: APIs for filtering synth. events

Message ID 20220124085625.92297-8-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series trace-cruncher: Synthetic events | expand

Commit Message

Yordan Karadzhov Jan. 24, 2022, 8:56 a.m. UTC
Here we add the following methods to the Python type for synthetic
events:
set_filter()
get_filter()
clear_filter()

The new APIs allow for easy manipulation of the filters associated
with a given synthetic event.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
 src/ftracepy-utils.h |  9 +++++++
 src/ftracepy.c       | 15 ++++++++++++
 3 files changed, 80 insertions(+)
diff mbox series

Patch

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index af73784..43c0f07 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -2739,6 +2739,62 @@  PyObject *PySynthEvent_is_enabled(PySynthEvent *self, PyObject *args,
 				tracefs_synth_get_name(self->ptrObj));
 }
 
+struct tep_event *synth_get_event(PySynthEvent *event, struct tep_handle **tep_ptr)
+{
+	struct tep_event *tep_evt;
+	struct tep_handle *tep;
+
+	tep = get_tep(NULL, NULL);
+	if (!tep)
+		return NULL;
+
+	tep_evt = tracefs_synth_get_event(tep, event->ptrObj);
+	if (!tep_evt) {
+		TfsError_setstr(NULL, "Failed to get synth. event.");
+		return NULL;
+	}
+
+	if (tep_ptr)
+		*tep_ptr = tep;
+
+	return tep_evt;
+}
+
+PyObject *PySynthEvent_set_filter(PySynthEvent *self, PyObject *args,
+						      PyObject *kwargs)
+{
+	struct tep_handle *tep;
+	struct tep_event *evt;
+
+	evt = synth_get_event(self, &tep);
+	if (!evt)
+		return NULL;
+
+	return set_filter(args, kwargs, tep, evt);
+}
+
+PyObject *PySynthEvent_get_filter(PySynthEvent *self, PyObject *args,
+						      PyObject *kwargs)
+{
+	struct tep_event *evt = synth_get_event(self, NULL);
+
+	if (!evt)
+		return NULL;
+
+	return get_filter(args, kwargs, SYNTH_SYS, evt->name);
+}
+
+PyObject *PySynthEvent_clear_filter(PySynthEvent *self, PyObject *args,
+							PyObject *kwargs)
+{
+	struct tep_event *evt = synth_get_event(self, NULL);
+
+	if (!evt)
+		return NULL;
+
+	return clear_filter(args, kwargs, evt);
+}
+
 PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args,
 						       PyObject *kwargs)
 {
diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h
index daf1a19..f31b330 100644
--- a/src/ftracepy-utils.h
+++ b/src/ftracepy-utils.h
@@ -152,6 +152,15 @@  PyObject *PySynthEvent_disable(PySynthEvent *self, PyObject *args,
 PyObject *PySynthEvent_is_enabled(PySynthEvent *self, PyObject *args,
 						      PyObject *kwargs);
 
+PyObject *PySynthEvent_set_filter(PySynthEvent *self, PyObject *args,
+						      PyObject *kwargs);
+
+PyObject *PySynthEvent_get_filter(PySynthEvent *self, PyObject *args,
+						      PyObject *kwargs);
+
+PyObject *PySynthEvent_clear_filter(PySynthEvent *self, PyObject *args,
+							PyObject *kwargs);
+
 PyObject *PyFtrace_dir(PyObject *self);
 
 PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs);
diff --git a/src/ftracepy.c b/src/ftracepy.c
index 62c6de0..50675c0 100644
--- a/src/ftracepy.c
+++ b/src/ftracepy.c
@@ -277,6 +277,21 @@  static PyMethodDef PySynthEvent_methods[] = {
 	 METH_VARARGS | METH_KEYWORDS,
 	 "Check if synth. event is enabled."
 	},
+	{"set_filter",
+	 (PyCFunction) PySynthEvent_set_filter,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Define a filter for a synthetic event."
+	},
+	{"get_filter",
+	 (PyCFunction) PySynthEvent_get_filter,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Get the filter of a synthetic event."
+	},
+	{"clear_filter",
+	 (PyCFunction) PySynthEvent_clear_filter,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Clear the filter of a synthetic event."
+	},
 	{NULL, NULL, 0, NULL}
 };