From 59d239749d555868d551b1a476127c02bd242f91 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Tue, 9 Feb 2021 09:42:24 +0000 Subject: [PATCH 01/14] Stop requiring the FreeBSD source code for FreeBSD13+ Since https://github.com/freebsd/freebsd-src/commit/1f6612b444e3fc54697a4ef3167efdddff6944ea the dtrace.h header is installed to /usr/include so we no longer need to have the full source code installed just to find the headers that we need to build the cython extension. --- setup.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 0978356..2b817d1 100644 --- a/setup.py +++ b/setup.py @@ -17,18 +17,20 @@ from Cython.Build import build_ext, cythonize extra_args = {} if platform.system().lower().startswith("freebsd"): - # On FreeBSD the dtrace headers are not installed by default. - src_dir = os.getenv("FREEBSD_SRC_DIR", "/usr/src") - if not os.path.exists(os.path.join(src_dir, "sys/cddl")): - raise ImportError("Cannot find FreeBSD DTrace headers") - extra_args["include_dirs"] = [ - os.path.join(src_dir, - "sys/cddl/compat/opensolaris"), - os.path.join(src_dir, - "sys/cddl/contrib/opensolaris/uts/common"), - os.path.join(src_dir, - "cddl/contrib/opensolaris/lib/libdtrace/common"), - ] + # On older FreeBSD versions the dtrace headers are not + # installed by default, so we need to find the full sources. + if not os.path.exists("/usr/include/dtrace.h"): + src_dir = os.getenv("FREEBSD_SRC_DIR", "/usr/src") + if not os.path.exists(os.path.join(src_dir, "sys/cddl")): + raise ImportError("Cannot find FreeBSD DTrace headers") + extra_args["include_dirs"] = [ + os.path.join(src_dir, + "sys/cddl/compat/opensolaris"), + os.path.join(src_dir, + "sys/cddl/contrib/opensolaris/uts/common"), + os.path.join(src_dir, + "cddl/contrib/opensolaris/lib/libdtrace/common"), + ] if os.getenv("ENABLE_ASAN", None) is not None: extra_args["extra_compile_args"] = ["-fsanitize=address"] extra_args["extra_link_args"] = ["-fsanitize=address"] From 54036c0f5162ba67d60077d29f2b602d1be1c4a0 Mon Sep 17 00:00:00 2001 From: Thijs Metsch Date: Sat, 20 Feb 2021 16:55:24 +0100 Subject: [PATCH 02/14] new release 0.0.12 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2b817d1..08fae54 100644 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ setup(name='python-dtrace', - version='0.0.11', + version='0.0.12', description='DTrace consumer for Python based on libdtrace. Use Python' ' as DTrace Consumer and Provider! See the homepage for' ' more information.', From 41096b129d04ded2e29053d017173abfb2201b18 Mon Sep 17 00:00:00 2001 From: Thijs Metsch Date: Sun, 21 Feb 2021 12:32:54 +0100 Subject: [PATCH 03/14] let's properly name the var decl. --- dtrace_cython/dtrace_h.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dtrace_cython/dtrace_h.pxd b/dtrace_cython/dtrace_h.pxd index df4c6a2..cad75e1 100644 --- a/dtrace_cython/dtrace_h.pxd +++ b/dtrace_cython/dtrace_h.pxd @@ -103,7 +103,7 @@ cdef extern from "dtrace.h": ctypedef struct dtrace_syminfo_t: const char * dts_object const char * dts_name - long bla + long dts_id # from dtrace.h ctypedef int dtrace_handle_buffered_f(const dtrace_bufdata_t * buf_data, void * arg) From fed64428b6cfb987e74935699b2b5b60f414a9ee Mon Sep 17 00:00:00 2001 From: tmetsch Date: Sun, 21 Feb 2021 12:34:15 +0100 Subject: [PATCH 04/14] let's use the proper names :-) --- dtrace_cython/dtrace_h.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dtrace_cython/dtrace_h.pxd b/dtrace_cython/dtrace_h.pxd index df4c6a2..cad75e1 100644 --- a/dtrace_cython/dtrace_h.pxd +++ b/dtrace_cython/dtrace_h.pxd @@ -103,7 +103,7 @@ cdef extern from "dtrace.h": ctypedef struct dtrace_syminfo_t: const char * dts_object const char * dts_name - long bla + long dts_id # from dtrace.h ctypedef int dtrace_handle_buffered_f(const dtrace_bufdata_t * buf_data, void * arg) From 3608b6e08a4ea85ee240fc3414b9453c58699558 Mon Sep 17 00:00:00 2001 From: tmetsch Date: Wed, 24 Feb 2021 10:08:39 +0100 Subject: [PATCH 05/14] github will stop redirecting sometime soon. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 08fae54..5cfdb70 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ ' more information.', license='MIT', keywords='DTrace', - url='http://tmetsch.github.com/python-dtrace/', + url='http://tmetsch.github.io/python-dtrace/', packages=['dtrace_ctypes'], cmdclass=BUILD_EXTENSION, ext_modules=EXT_MODULES, From f06de369e1c679abb34f68265f27573556ca531a Mon Sep 17 00:00:00 2001 From: tmetsch Date: Sun, 28 Feb 2021 18:25:47 +0100 Subject: [PATCH 06/14] Update consumer.pyx switch to 64 bit uint. --- dtrace_cython/consumer.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dtrace_cython/consumer.pyx b/dtrace_cython/consumer.pyx index fe10476..a11ab7e 100644 --- a/dtrace_cython/consumer.pyx +++ b/dtrace_cython/consumer.pyx @@ -90,7 +90,7 @@ cdef int walk(const dtrace_aggdata_t * data, void * arg) with gil: address = data.dtada_data + rec.dtrd_offset # TODO: need to extend this. - if rec.dtrd_size == sizeof(uint32_t): + if rec.dtrd_size == sizeof(uint64_t): keys.append((address)[0]) if rec.dtrd_size == 20 * sizeof(uint64_t): # case stack() has been used --> need to lookup symbols. From 2e2222888ca94bd5e6fb9809bea96d1ccfbf8e22 Mon Sep 17 00:00:00 2001 From: tmetsch Date: Sun, 28 Feb 2021 18:26:57 +0100 Subject: [PATCH 07/14] Update consumer.pyx --- dtrace_cython/consumer.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dtrace_cython/consumer.pyx b/dtrace_cython/consumer.pyx index a11ab7e..9751b20 100644 --- a/dtrace_cython/consumer.pyx +++ b/dtrace_cython/consumer.pyx @@ -91,7 +91,7 @@ cdef int walk(const dtrace_aggdata_t * data, void * arg) with gil: # TODO: need to extend this. if rec.dtrd_size == sizeof(uint64_t): - keys.append((address)[0]) + keys.append((address)[0]) if rec.dtrd_size == 20 * sizeof(uint64_t): # case stack() has been used --> need to lookup symbols. for j in range(rec.dtrd_arg): From 93afc72a47054f442ea9c5dcc2f507b1076fcd77 Mon Sep 17 00:00:00 2001 From: Thijs Metsch Date: Sun, 28 Feb 2021 19:28:38 +0100 Subject: [PATCH 08/14] handling 32 and 64 bit ints. --- dtrace_cython/consumer.pyx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dtrace_cython/consumer.pyx b/dtrace_cython/consumer.pyx index 9751b20..8eb9658 100644 --- a/dtrace_cython/consumer.pyx +++ b/dtrace_cython/consumer.pyx @@ -90,9 +90,11 @@ cdef int walk(const dtrace_aggdata_t * data, void * arg) with gil: address = data.dtada_data + rec.dtrd_offset # TODO: need to extend this. - if rec.dtrd_size == sizeof(uint64_t): - keys.append((address)[0]) - if rec.dtrd_size == 20 * sizeof(uint64_t): + if rec.dtrd_size == sizeof(uint32_t): + keys.append((address)[0]) + elif rec.dtrd_size == sizeof(uint64_t): + keys.append(( address)[0]) + elif rec.dtrd_size == 20 * sizeof(uint64_t): # case stack() has been used --> need to lookup symbols. for j in range(rec.dtrd_arg): pc = dereference(address) From a2c394a84ae812d5c06c07d72ab950d115a78e34 Mon Sep 17 00:00:00 2001 From: Thijs Metsch Date: Sat, 6 Mar 2021 18:12:09 +0100 Subject: [PATCH 09/14] release fixing #25 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5cfdb70..d9d2159 100644 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ setup(name='python-dtrace', - version='0.0.12', + version='0.0.13', description='DTrace consumer for Python based on libdtrace. Use Python' ' as DTrace Consumer and Provider! See the homepage for' ' more information.', From 0a889ceed8cbcc96df35d11760f62f9fb644752a Mon Sep 17 00:00:00 2001 From: Konrad Witaszczyk Date: Wed, 9 Feb 2022 13:13:58 +0000 Subject: [PATCH 10/14] Correctly free DTrace resources. Cython's cdef attributes are not regular class attributes as in Python. hasattr(object, name) always returns False for a cdef attribute corresponding to name. Instead, we should simply check a pointer's value. I couldn't confirm it in any documentation but, based on examples I found and my experiments, it seems that a cdef pointer is always initially set to NULL, at least when declared as a class attribute. --- dtrace_cython/consumer.pyx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dtrace_cython/consumer.pyx b/dtrace_cython/consumer.pyx index 8eb9658..c5a6e42 100644 --- a/dtrace_cython/consumer.pyx +++ b/dtrace_cython/consumer.pyx @@ -312,7 +312,7 @@ cdef class DTraceConsumer: self.walk_func = noop_walk if walk_func is None else walk_func cdef int err - if not hasattr(self, 'handle'): + if self.handle == NULL: # ensure we only grab 1 - cython might call init twice, of more. self.handle = dtrace_open(3, 0, &err) if self.handle == NULL: @@ -331,8 +331,9 @@ cdef class DTraceConsumer: """ Release DTrace handle. """ - if hasattr(self, 'handle') and self.handle != NULL: + if self.handle != NULL: dtrace_close(self.handle) + self.handle = NULL cpdef compile(self, str script): """ @@ -437,7 +438,7 @@ cdef class DTraceContinuousConsumer: self.script = script.encode("utf-8") cdef int err - if not hasattr(self, 'handle'): + if self.handle == NULL: # ensure we only grab 1 - cython might call init twice, of more. self.handle = dtrace_open(3, 0, &err) if self.handle == NULL: @@ -456,9 +457,10 @@ cdef class DTraceContinuousConsumer: """ Release DTrace handle. """ - if hasattr(self, 'handle') and self.handle != NULL: + if self.handle != NULL: dtrace_stop(self.handle) dtrace_close(self.handle) + self.handle = NULL cpdef go(self): """ From 56101d6d07d736c7041b0838bb138c3bfed25a81 Mon Sep 17 00:00:00 2001 From: tmetsch Date: Tue, 15 Feb 2022 14:41:33 +0100 Subject: [PATCH 11/14] Update setup.py new version prep. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d9d2159..d066c6f 100644 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ setup(name='python-dtrace', - version='0.0.13', + version='0.0.14', description='DTrace consumer for Python based on libdtrace. Use Python' ' as DTrace Consumer and Provider! See the homepage for' ' more information.', From 8707df56d5d0bd434562b4e0e39404ada64bde80 Mon Sep 17 00:00:00 2001 From: tmetsch Date: Tue, 15 Feb 2022 14:44:50 +0100 Subject: [PATCH 12/14] Update ACKNOWLEDGEMENTS new version prep. --- ACKNOWLEDGEMENTS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ACKNOWLEDGEMENTS b/ACKNOWLEDGEMENTS index fca1df1..86f4514 100644 --- a/ACKNOWLEDGEMENTS +++ b/ACKNOWLEDGEMENTS @@ -10,3 +10,6 @@ of the DTrace handles. Thanks to Alexander Richardson (https://github.com/arichardson) for doing a huge refactoring and looking into properly supporting python3. + +Thanks to Konrad Witaszczyk (https://github.com/kwitaszczyk) for looking into +properly freeing up DTrace resources. From d938182122aa84a80ef1e9525f64fe4fc5a063e9 Mon Sep 17 00:00:00 2001 From: tmetsch Date: Wed, 4 May 2022 18:45:52 +0200 Subject: [PATCH 13/14] Potential fix for issue #28. --- dtrace_cython/consumer.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dtrace_cython/consumer.pyx b/dtrace_cython/consumer.pyx index c5a6e42..0401000 100644 --- a/dtrace_cython/consumer.pyx +++ b/dtrace_cython/consumer.pyx @@ -307,7 +307,7 @@ cdef class DTraceConsumer: """ self.chew_func = noop_chew if chew_func is None else chew_func self.chewrec_func = noop_chewrec if chewrec_func is None \ - else simple_chewrec + else chewrec_func self.out_func = noop_out if out_func is None else out_func self.walk_func = noop_walk if walk_func is None else walk_func @@ -432,7 +432,7 @@ cdef class DTraceContinuousConsumer: """ self.chew_func = noop_chew if chew_func is None else chew_func self.chewrec_func = noop_chewrec if chewrec_func is None \ - else simple_chewrec + else chewrec_func self.out_func = noop_out if out_func is None else out_func self.walk_func = noop_walk if walk_func is None else walk_func self.script = script.encode("utf-8") From 1cc6897eded5af05ec210d5fd08489d0ab5b9a26 Mon Sep 17 00:00:00 2001 From: Thijs Metsch Date: Fri, 13 May 2022 21:26:10 +0200 Subject: [PATCH 14/14] new bugfix release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d066c6f..6f573ea 100644 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ setup(name='python-dtrace', - version='0.0.14', + version='0.0.15', description='DTrace consumer for Python based on libdtrace. Use Python' ' as DTrace Consumer and Provider! See the homepage for' ' more information.',