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 2/2] trace-cruncher: Add attach()
Date: Thu, 9 Sep 2021 18:59:41 +0300 [thread overview]
Message-ID: <20210909155941.271165-2-y.karadz@gmail.com> (raw)
In-Reply-To: <20210909155941.271165-1-y.karadz@gmail.com>
Here we add mechanisms that will make possible to reattach object to
the ftracepy module. This means that the object will be properly
destroyed when the module exits.
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
src/ftracepy-utils.c | 18 ++++++++++++++----
src/ftracepy-utils.h | 2 ++
src/ftracepy.c | 5 +++++
.../tests/1_unit/test_01_ftracepy_unit.py | 13 +++++++++++++
4 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index bf811ae..d4fa59e 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -507,24 +507,34 @@ static void set_destroy_flag(PyObject *py_obj, bool val)
obj_head->destroy = val;
}
-PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs)
+static PyObject *set_destroy(PyObject *args, PyObject *kwargs, bool destroy)
{
static char *kwlist[] = {"object", NULL};
- PyObject *py_obj = NULL;
+ PyObject *py_obj;
if (!PyArg_ParseTupleAndKeywords(args,
kwargs,
"O",
kwlist,
&py_obj)) {
- return false;
+ return NULL;
}
- set_destroy_flag(py_obj, false);
+ set_destroy_flag(py_obj, destroy);
Py_RETURN_NONE;
}
+PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ return set_destroy(args, kwargs, false);
+}
+
+PyObject *PyFtrace_attach(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ return set_destroy(args, kwargs, true);
+}
+
static char aname_pool[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h
index c1eec21..be1b37c 100644
--- a/src/ftracepy-utils.h
+++ b/src/ftracepy-utils.h
@@ -83,6 +83,8 @@ PyObject *PyFtrace_dir(PyObject *self);
PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs);
+PyObject *PyFtrace_attach(PyObject *self, PyObject *args, PyObject *kwargs);
+
PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args,
PyObject *kwargs);
diff --git a/src/ftracepy.c b/src/ftracepy.c
index e48adb6..763a7d2 100644
--- a/src/ftracepy.c
+++ b/src/ftracepy.c
@@ -150,6 +150,11 @@ static PyMethodDef ftracepy_methods[] = {
METH_VARARGS | METH_KEYWORDS,
"Detach object from the \'ftracepy\' module."
},
+ {"attach",
+ (PyCFunction) PyFtrace_attach,
+ METH_VARARGS | METH_KEYWORDS,
+ "Attach object to the \'ftracepy\' module."
+ },
{"create_instance",
(PyCFunction) PyFtrace_create_instance,
METH_VARARGS | METH_KEYWORDS,
diff --git a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py
index a7010e2..d3e3960 100644
--- a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py
+++ b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py
@@ -48,6 +48,19 @@ class InstanceTestCase(unittest.TestCase):
inst_2 = ft.find_instance(another_instance_name)
self.assertTrue(err in str(context.exception))
+ def test_1_detach(self):
+ inst = ft.create_instance(instance_name)
+ ft.detach(inst)
+
+ def test_2_attach(self):
+ inst = ft.find_instance(instance_name)
+ ft.attach(inst)
+
+ def test_3_attach(self):
+ tracefs_dir = ft.dir();
+ instance_dir = tracefs_dir + '/instances/' + instance_name
+ self.assertFalse(os.path.isdir(instance_dir))
+
class PyTepTestCase(unittest.TestCase):
def test_init_local(self):
--
2.30.2
prev parent reply other threads:[~2021-09-09 15:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-09 15:59 [PATCH 1/2] trace-cruncher: Add find_instance() Yordan Karadzhov (VMware)
2021-09-09 15:59 ` Yordan Karadzhov (VMware) [this message]
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=20210909155941.271165-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).