Add tracepoint_disable_destructors()
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 10 Mar 2016 14:32:59 +0000 (09:32 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 15 Mar 2016 18:59:47 +0000 (14:59 -0400)
Calling this function from an instrumented program allows disabling
tracepoint destructors. This allows threads to continue calling
tracepoint code even after the tracepoint destructors have run. This is
needed for applications that exit without joining all their threads.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: Jeffrey Chen <cpthk@live.com>
include/lttng/tracepoint.h

index 16348b86106c98e15abe58cf62b8fc11cdc43a4c..ed20594497ab65bab366b594bb965e740d3e9b29 100644 (file)
@@ -227,6 +227,21 @@ struct lttng_ust_tracepoint_dlopen {
 
 extern struct lttng_ust_tracepoint_dlopen tracepoint_dlopen;
 
+/* Disable tracepoint destructors. */
+int __tracepoints__disable_destructors __attribute__((weak));
+
+/*
+ * Programs that have threads that survive after they exit, and
+ * therefore call library destructors, should disable the tracepoint
+ * destructors by calling tracepoint_disable_destructors(). This will
+ * leak the tracepoint instrumentation library shared object, leaving
+ * its teardown to the operating system process teardown.
+ */
+static inline void tracepoint_disable_destructors(void)
+{
+       __tracepoints__disable_destructors = 1;
+}
+
 #if defined(TRACEPOINT_DEFINE) || defined(TRACEPOINT_CREATE_PROBES)
 
 /*
@@ -301,7 +316,9 @@ __tracepoints__destroy(void)
 
        if (--__tracepoint_registered)
                return;
-       if (tracepoint_dlopen.liblttngust_handle && !__tracepoint_ptrs_registered) {
+       if (!__tracepoints__disable_destructors
+                       && tracepoint_dlopen.liblttngust_handle
+                       && !__tracepoint_ptrs_registered) {
                ret = dlclose(tracepoint_dlopen.liblttngust_handle);
                if (ret) {
                        fprintf(stderr, "Error (%d) in dlclose\n", ret);
@@ -406,7 +423,9 @@ __tracepoints__ptrs_destroy(void)
                return;
        if (tracepoint_dlopen.tracepoint_unregister_lib)
                tracepoint_dlopen.tracepoint_unregister_lib(__start___tracepoints_ptrs);
-       if (tracepoint_dlopen.liblttngust_handle && !__tracepoint_registered) {
+       if (!__tracepoints__disable_destructors
+                       && tracepoint_dlopen.liblttngust_handle
+                       && !__tracepoint_ptrs_registered) {
                ret = dlclose(tracepoint_dlopen.liblttngust_handle);
                if (ret) {
                        fprintf(stderr, "Error (%d) in dlclose\n", ret);
This page took 0.026414 seconds and 4 git commands to generate.