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 3/4] trace-cruncher: Allow for detachable instances
Date: Mon, 12 Jul 2021 15:32:41 +0300	[thread overview]
Message-ID: <20210712123242.223500-3-y.karadz@gmail.com> (raw)
In-Reply-To: <20210712123242.223500-1-y.karadz@gmail.com>

 If the instance is created with "detached=True", the Python module is
 no longer responsible for destroying it when exiting. It is therefore
 up to the user free it explicitly, or to keep it active.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 8f4b50c..d061817 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -421,6 +421,12 @@ static PyObject *tfs_list2py_list(char **list)
 
 struct instance_wrapper {
 	struct tracefs_instance *ptr;
+	bool detached;
+
+	/*
+	 * This name will be used only for searching. The actual name of
+	 * the instance is owned by the "tracefs_instance" object.
+	 */
 	const char *name;
 };
 
@@ -451,10 +457,12 @@ void instance_wrapper_free(void *ptr)
 
 	iw = ptr;
 	if (iw->ptr) {
-		if (tracefs_instance_destroy(iw->ptr) < 0)
-			fprintf(stderr,
-				"\ntfs_error: Failed to destroy instance '%s'.\n",
-				get_instance_name(iw->ptr));
+		if (!iw->detached) {
+			if (tracefs_instance_destroy(iw->ptr) < 0)
+				fprintf(stderr,
+					"\ntfs_error: Failed to destroy instance '%s'.\n",
+					get_instance_name(iw->ptr));
+		}
 
 		free(iw->ptr);
 	}
@@ -569,14 +577,16 @@ PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args,
 	struct tracefs_instance *instance;
 	const char *name = NO_ARG;
 	int tracing_on = true;
+	int detached = false;
+	static char *kwlist[] = {"name", "tracing_on", "detached", NULL};
 
-	static char *kwlist[] = {"name", "tracing_on", NULL};
 	if (!PyArg_ParseTupleAndKeywords(args,
 					 kwargs,
-					 "|sp",
+					 "|spp",
 					 kwlist,
 					 &name,
-					 &tracing_on)) {
+					 &tracing_on,
+					 &detached)) {
 		return NULL;
 	}
 
@@ -600,6 +610,11 @@ PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args,
 	}
 
 	iw->ptr = instance;
+	if (detached) {
+		printf("detached instance: %s\n", name);
+		iw->detached = detached;
+	}
+
 	iw_ptr = tsearch(iw, &instance_root, instance_compare);
 	if (!iw_ptr || !(*iw_ptr) || !(*iw_ptr)->ptr ||
 	    strcmp(tracefs_instance_get_name((*iw_ptr)->ptr), name) != 0) {
-- 
2.27.0


  parent reply	other threads:[~2021-07-12 12:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-12 12:32 [PATCH 1/4] trace-cruncher: Add set_ftrace_loglevel() Yordan Karadzhov (VMware)
2021-07-12 12:32 ` [PATCH 2/4] trace-cruncher: Add local_tep() to utils Yordan Karadzhov (VMware)
2021-07-12 12:32 ` Yordan Karadzhov (VMware) [this message]
2021-07-22 21:19   ` [PATCH 3/4] trace-cruncher: Allow for detachable instances Steven Rostedt
2021-07-26  9:04     ` Yordan Karadzhov (VMware)
2021-07-26 13:48       ` Steven Rostedt
2021-07-12 12:32 ` [PATCH 4/4] trace-cruncher: Allow for detachable kprobes Yordan Karadzhov (VMware)
2021-07-22 21:24   ` Steven Rostedt
     [not found]     ` <cb908dc6-9ca8-7962-723a-a2388cebaf82@gmail.com>
2021-07-29 10:25       ` Yordan Karadzhov
2021-07-22 21:15 ` [PATCH 1/4] trace-cruncher: Add set_ftrace_loglevel() Steven Rostedt
2021-07-26  9:34   ` 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=20210712123242.223500-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).