[PATCH 03/10] trace-cruncher: APIs for adding arithmetic fields to synth. events

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here we add the following methods to the Python type for synthetic
events:
add_delta_start(),
add_delta_end(),
add_delta_T(),
add_sum()

The new APIs allows for adding to the new synthetic event, fields that
are calculated from the fields of the original 'start' and 'end' events
by using simple addition or subtraction.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx>
---
 src/ftracepy-utils.c | 81 ++++++++++++++++++++++++++++++++++++++++++++
 src/ftracepy-utils.h | 12 +++++++
 src/ftracepy.c       | 20 +++++++++++
 3 files changed, 113 insertions(+)

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 42bd9d0..9245b07 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -1073,6 +1073,87 @@ PyObject *PySynthEvent_add_end_fields(PySynthEvent *self, PyObject *args,
 	return synth_add_fields(self, args, kwargs, false);
 }
 
+static inline void add_synth_field_err(const char *field, const char *event)
+{
+	TfsError_fmt(NULL, "Failed to add field '%s' to synth. event %s",
+		     field, event);
+}
+
+static inline PyObject *
+add_synth_field(PySynthEvent *self, PyObject *args, PyObject *kwargs,
+		enum tracefs_synth_calc calc)
+{
+	static char *kwlist[] = {"name", "start_field", "end_field", NULL};
+	const char *start_field, *end_field, *name;
+	int ret;
+
+	if (!PyArg_ParseTupleAndKeywords(args,
+					 kwargs,
+					 "sss",
+					 kwlist,
+					 &name,
+					 &start_field,
+					 &end_field)) {
+		return NULL;
+	}
+
+	ret = tracefs_synth_add_compare_field(self->ptrObj,
+					      start_field, end_field, calc,
+					      name);
+	if (ret < 0) {
+		add_synth_field_err(name, tracefs_synth_get_name(self->ptrObj));
+		return NULL;
+	}
+
+	Py_RETURN_NONE;
+}
+
+PyObject *PySynthEvent_add_delta_start(PySynthEvent *self, PyObject *args,
+							   PyObject *kwargs)
+{
+	return add_synth_field(self, args, kwargs, TRACEFS_SYNTH_DELTA_START);
+}
+
+PyObject *PySynthEvent_add_delta_end(PySynthEvent *self, PyObject *args,
+							 PyObject *kwargs)
+{
+	return add_synth_field(self, args, kwargs, TRACEFS_SYNTH_DELTA_END);
+}
+
+PyObject *PySynthEvent_add_sum(PySynthEvent *self, PyObject *args,
+						   PyObject *kwargs)
+{
+	return add_synth_field(self, args, kwargs, TRACEFS_SYNTH_ADD);
+}
+
+PyObject *PySynthEvent_add_delta_T(PySynthEvent *self, PyObject *args,
+						       PyObject *kwargs)
+{
+	static char *kwlist[] = {"name", "hd", NULL};
+	const char *name = "delta_T";
+	const char* time_rez;
+	int ret, hd = 0;
+
+	if (!PyArg_ParseTupleAndKeywords(args,
+					 kwargs,
+					 "|sp",
+					 kwlist,
+					 &name,
+					 &hd)) {
+		return NULL;
+	}
+
+	time_rez = hd ? TRACEFS_TIMESTAMP : TRACEFS_TIMESTAMP_USECS;
+	ret = tracefs_synth_add_compare_field(self->ptrObj, time_rez, time_rez,
+					      TRACEFS_SYNTH_DELTA_END, name);
+	if (ret < 0) {
+		add_synth_field_err(name, tracefs_synth_get_name(self->ptrObj));
+		return NULL;
+	}
+
+	Py_RETURN_NONE;
+}
+
 PyObject *PyFtrace_dir(PyObject *self)
 {
 	return PyUnicode_FromString(tracefs_tracing_dir());
diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h
index 3c6c0f3..7b798fc 100644
--- a/src/ftracepy-utils.h
+++ b/src/ftracepy-utils.h
@@ -127,6 +127,18 @@ PyObject *PySynthEvent_add_start_fields(PySynthEvent *self, PyObject *args,
 PyObject *PySynthEvent_add_end_fields(PySynthEvent *self, PyObject *args,
 							  PyObject *kwargs);
 
+PyObject *PySynthEvent_add_delta_start(PySynthEvent *self, PyObject *args,
+							   PyObject *kwargs);
+
+PyObject *PySynthEvent_add_delta_end(PySynthEvent *self, PyObject *args,
+							 PyObject *kwargs);
+
+PyObject *PySynthEvent_add_delta_T(PySynthEvent *self, PyObject *args,
+						       PyObject *kwargs);
+
+PyObject *PySynthEvent_add_sum(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 44114f0..066fc65 100644
--- a/src/ftracepy.c
+++ b/src/ftracepy.c
@@ -232,6 +232,26 @@ static PyMethodDef PySynthEvent_methods[] = {
 	 METH_VARARGS | METH_KEYWORDS,
 	 "Add fields from the end event to save."
 	},
+	{"add_delta_start",
+	 (PyCFunction) PySynthEvent_add_delta_start,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Add 'start - end' field."
+	},
+	{"add_delta_end",
+	 (PyCFunction) PySynthEvent_add_delta_end,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Add 'end - start' field."
+	},
+	{"add_delta_T",
+	 (PyCFunction) PySynthEvent_add_delta_T,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Add time-difference field."
+	},
+	{"add_sum",
+	 (PyCFunction) PySynthEvent_add_delta_T,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Add 'start + end' field."
+	},
 	{NULL, NULL, 0, NULL}
 };
 
-- 
2.32.0




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux