linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 01/10] trace-cruncher: Define Python type for synthetic events
Date: Mon, 24 Jan 2022 10:56:16 +0200	[thread overview]
Message-ID: <20220124085625.92297-2-y.karadz@gmail.com> (raw)
In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com>

Addind new Python type and constructor for it:
synth()

The new type 'PySynthEvent will be used to implement APIs for working
with synthetic events.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c | 58 ++++++++++++++++++++++++++++++++++++++++++++
 src/ftracepy-utils.h |  5 ++++
 src/ftracepy.c       | 17 +++++++++++++
 3 files changed, 80 insertions(+)

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index cecb180..1fcf2f8 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -2426,6 +2426,64 @@ PyObject *PyFtrace_hist(PyObject *self, PyObject *args,
 	return NULL;
 }
 
+PyObject *PyFtrace_synth(PyObject *self, PyObject *args,
+					 PyObject *kwargs)
+{
+	const char *name, *start_match, *end_match, *match_name=NULL;
+	const char *start_sys, *start_evt, *end_sys, *end_evt;
+	static char *kwlist[] = {"name",
+				 "start_sys",
+				 "start_evt",
+				 "end_sys",
+				 "end_evt",
+				 "start_match",
+				 "end_match",
+				 "match_name",
+				 NULL};
+	static struct tracefs_synth *synth;
+	struct tep_handle *tep;
+	PyObject *py_synth;
+
+	if (!PyArg_ParseTupleAndKeywords(args,
+					 kwargs,
+					 "sssssss|s",
+					 kwlist,
+					 &name,
+					 &start_sys,
+					 &start_evt,
+					 &end_sys,
+					 &end_evt,
+					 &start_match,
+					 &end_match,
+					 &match_name)) {
+		return NULL;
+	}
+
+	tep = get_tep(NULL, NULL);
+	if (!tep)
+		return NULL;
+
+	synth = tracefs_synth_alloc(tep, name,
+				    start_sys, start_evt,
+				    end_sys, end_evt,
+				    start_match, end_match,
+				    match_name);
+	tep_free(tep);
+	if (!synth) {
+		MEM_ERROR;
+		return NULL;
+	}
+
+	py_synth = PySynthEvent_New(synth);
+	/*
+	 * Here we only allocated and initializes a synthetic event object.
+	 * However, no synthetic event is added to the system yet. Hence,
+	 * there is no need to 'destroy' this event at exit.
+	 */
+	set_destroy_flag(py_synth, false);
+	return py_synth;
+}
+
 PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args,
 						       PyObject *kwargs)
 {
diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h
index fc5016c..e8db811 100644
--- a/src/ftracepy-utils.h
+++ b/src/ftracepy-utils.h
@@ -30,6 +30,8 @@ C_OBJECT_WRAPPER_DECLARE(tracefs_dynevent, PyDynevent);
 
 C_OBJECT_WRAPPER_DECLARE(tracefs_hist, PyTraceHist)
 
+C_OBJECT_WRAPPER_DECLARE(tracefs_synth, PySynthEvent)
+
 PyObject *PyTepRecord_time(PyTepRecord* self);
 
 PyObject *PyTepRecord_cpu(PyTepRecord* self);
@@ -210,6 +212,9 @@ PyObject *PyFtrace_register_kretprobe(PyObject *self, PyObject *args,
 PyObject *PyFtrace_hist(PyObject *self, PyObject *args,
 					PyObject *kwargs);
 
+PyObject *PyFtrace_synth(PyObject *self, PyObject *args,
+					 PyObject *kwargs);
+
 PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args,
 						       PyObject *kwargs);
 
diff --git a/src/ftracepy.c b/src/ftracepy.c
index f59bd4c..f8b8b36 100644
--- a/src/ftracepy.c
+++ b/src/ftracepy.c
@@ -221,6 +221,14 @@ C_OBJECT_WRAPPER(tracefs_hist, PyTraceHist,
 		 NO_DESTROY,
 		 tracefs_hist_free)
 
+static PyMethodDef PySynthEvent_methods[] = {
+	{NULL, NULL, 0, NULL}
+};
+
+C_OBJECT_WRAPPER(tracefs_synth, PySynthEvent,
+		 tracefs_synth_destroy,
+		 tracefs_synth_free)
+
 static PyMethodDef ftracepy_methods[] = {
 	{"dir",
 	 (PyCFunction) PyFtrace_dir,
@@ -382,6 +390,11 @@ static PyMethodDef ftracepy_methods[] = {
 	 METH_VARARGS | METH_KEYWORDS,
 	 "Define a histogram."
 	},
+	{"synth",
+	 (PyCFunction) PyFtrace_synth,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Define a synthetic event."
+	},
 	{"set_ftrace_loglevel",
 	 (PyCFunction) PyFtrace_set_ftrace_loglevel,
 	 METH_VARARGS | METH_KEYWORDS,
@@ -453,6 +466,9 @@ PyMODINIT_FUNC PyInit_ftracepy(void)
 	if (!PyTraceHistTypeInit())
 		return NULL;
 
+	if (!PySynthEventTypeInit())
+		return NULL;
+
 	TFS_ERROR = PyErr_NewException("tracecruncher.ftracepy.tfs_error",
 				       NULL, NULL);
 
@@ -470,6 +486,7 @@ PyMODINIT_FUNC PyInit_ftracepy(void)
 	PyModule_AddObject(module, "tracefs_instance", (PyObject *) &PyTfsInstanceType);
 	PyModule_AddObject(module, "tracefs_dynevent", (PyObject *) &PyDyneventType);
 	PyModule_AddObject(module, "tracefs_hist", (PyObject *) &PyTraceHistType);
+	PyModule_AddObject(module, "tracefs_synth", (PyObject *) &PySynthEventType);
 
 	PyModule_AddObject(module, "tfs_error", TFS_ERROR);
 	PyModule_AddObject(module, "tep_error", TEP_ERROR);
-- 
2.32.0


  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 ` Yordan Karadzhov (VMware) [this message]
2022-01-24  8:56 ` [PATCH 02/10] trace-cruncher: APIs for adding start/end fields to synth. event Yordan Karadzhov (VMware)
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-2-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).