From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 02/10] trace-cruncher: APIs for adding start/end fields to synth. event
Date: Mon, 24 Jan 2022 10:56:17 +0200 [thread overview]
Message-ID: <20220124085625.92297-3-y.karadz@gmail.com> (raw)
In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com>
Here we add the following methods to the Python type for synthetic
events:
add_start_fields()
add_end_fields()
The new APIs allows for adding fields from the original 'start' and
'end' events to the new synthetic event.
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
src/ftracepy-utils.c | 64 ++++++++++++++++++++++++++++++++++++++++++++
src/ftracepy-utils.h | 6 +++++
src/ftracepy.c | 10 +++++++
3 files changed, 80 insertions(+)
diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 1fcf2f8..42bd9d0 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -1009,6 +1009,70 @@ PyObject *PyTraceHist_close(PyTraceHist *self, PyObject *args,
Py_RETURN_NONE;
}
+typedef int (*add_field_ptr)(struct tracefs_synth *,
+ const char *,
+ const char *);
+
+PyObject *synth_add_fields(PySynthEvent *self, PyObject *args,
+ PyObject *kwargs,
+ bool to_start)
+{
+ static char *kwlist[] = {"fields", "names", NULL};
+ PyObject *py_fields, *py_names = NULL;
+ PyObject *item_field, *item_name;
+ add_field_ptr add_field_func;
+ const char *field, *name;
+ int ret, n, i;
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kwargs,
+ "O|O",
+ kwlist,
+ &py_fields,
+ &py_names)) {
+ return NULL;
+ }
+
+ add_field_func = to_start ? tracefs_synth_add_start_field:
+ tracefs_synth_add_end_field;
+
+ n = PyList_Size(py_fields);
+ for (i = 0; i < n; ++i) {
+ item_field = PyList_GetItem(py_fields, i);
+ field = PyUnicode_DATA(item_field);
+
+ name = NULL;
+ if (py_names) {
+ item_name = PyList_GetItem(py_names, i);
+ if (item_name && item_name != Py_None)
+ name = PyUnicode_DATA(item_name);
+ }
+
+ ret = add_field_func(self->ptrObj, field, name);
+ if (ret < 0) {
+ TfsError_fmt(NULL,
+ "Failed to add %s field '%s' to synth. event %s",
+ to_start ? "start" : "end", field,
+ tracefs_synth_get_name(self->ptrObj));
+ return NULL;
+ }
+ }
+
+ Py_RETURN_NONE;
+}
+
+PyObject *PySynthEvent_add_start_fields(PySynthEvent *self, PyObject *args,
+ PyObject *kwargs)
+{
+ return synth_add_fields(self, args, kwargs, true);
+}
+
+PyObject *PySynthEvent_add_end_fields(PySynthEvent *self, PyObject *args,
+ PyObject *kwargs)
+{
+ return synth_add_fields(self, args, kwargs, false);
+}
+
PyObject *PyFtrace_dir(PyObject *self)
{
return PyUnicode_FromString(tracefs_tracing_dir());
diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h
index e8db811..3c6c0f3 100644
--- a/src/ftracepy-utils.h
+++ b/src/ftracepy-utils.h
@@ -121,6 +121,12 @@ PyObject *PyTraceHist_read(PyTraceHist *self, PyObject *args,
PyObject *PyTraceHist_close(PyTraceHist *self, PyObject *args,
PyObject *kwargs);
+PyObject *PySynthEvent_add_start_fields(PySynthEvent *self, PyObject *args,
+ PyObject *kwargs);
+
+PyObject *PySynthEvent_add_end_fields(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 f8b8b36..44114f0 100644
--- a/src/ftracepy.c
+++ b/src/ftracepy.c
@@ -222,6 +222,16 @@ C_OBJECT_WRAPPER(tracefs_hist, PyTraceHist,
tracefs_hist_free)
static PyMethodDef PySynthEvent_methods[] = {
+ {"add_start_fields",
+ (PyCFunction) PySynthEvent_add_start_fields,
+ METH_VARARGS | METH_KEYWORDS,
+ "Add fields from the start event to save."
+ },
+ {"add_end_fields",
+ (PyCFunction) PySynthEvent_add_end_fields,
+ METH_VARARGS | METH_KEYWORDS,
+ "Add fields from the end event to save."
+ },
{NULL, NULL, 0, NULL}
};
--
2.32.0
next prev parent reply other threads:[~2022-01-24 8:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 8:56 [PATCH 00/10] trace-cruncher: Synthetic events Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 01/10] trace-cruncher: Define Python type for synthetic events Yordan Karadzhov (VMware)
2022-01-24 8:56 ` Yordan Karadzhov (VMware) [this message]
2022-01-24 8:56 ` [PATCH 03/10] trace-cruncher: APIs for adding arithmetic fields to synth. events Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 04/10] trace-cruncher: APIs for registering/unregistering " Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 05/10] trace-cruncher: APIs for enabling " Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 06/10] trace-cryncher: Add static methods for manipulating filters Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 07/10] trace-cruncher: APIs for filtering synth. events Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 08/10] trace-cruncher: API to show descriptor of the synth. event Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 09/10] trace-cruncher: Add synthetic event example Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 10/10] trace-cruncher: Add synth. events tests Yordan Karadzhov (VMware)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220124085625.92297-3-y.karadz@gmail.com \
--to=y.karadz@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).