From 1685f38bb276b0ff28c83a042aaefc2cec21a71d Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 19 Jun 2019 04:22:42 +0530 Subject: [PATCH] gsttracer: Add new API to fetch the list of active tracers This will be useful in the next commit where we add action-signals on the leaks tracer to get information about leaks and to manipulate checkpoints as a replacement for the SIGUSR1 and SIGUSR2 signals for doing the same. --- gst/gsttracer.h | 3 +++ gst/gsttracerutils.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/gst/gsttracer.h b/gst/gsttracer.h index 046ac22..751c1b3 100644 --- a/gst/gsttracer.h +++ b/gst/gsttracer.h @@ -74,6 +74,9 @@ void gst_tracing_register_hook (GstTracer *tracer, const gchar *detail, GST_API gboolean gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type); +GST_API +GList* gst_tracing_get_active_tracers (void); + #endif G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstTracer, gst_object_unref) diff --git a/gst/gsttracerutils.c b/gst/gsttracerutils.c index 2522cbf..d3a95b7 100644 --- a/gst/gsttracerutils.c +++ b/gst/gsttracerutils.c @@ -205,3 +205,41 @@ gst_tracing_register_hook (GstTracer * tracer, const gchar * detail, } #endif /* GST_DISABLE_GST_TRACER_HOOKS */ + +/** + * gst_tracing_get_active_tracers: + * + * Get a list of all active tracer objects owned by the tracing framework for + * the entirety of the run-time of the process or till gst_deinit() is called. + * + * Returns: (transfer full) (element-type Gst.Tracer): A #GList of + * #GstTracer objects + * + * Since: 1.18 + */ +GList * +gst_tracing_get_active_tracers (void) +{ + GList *tracers, *h_list, *h_node, *t_node; + GstTracerHook *hook; + + if (!_priv_tracer_enabled || !_priv_tracers) + return NULL; + + tracers = NULL; + h_list = g_hash_table_get_values (_priv_tracers); + for (h_node = h_list; h_node; h_node = g_list_next (h_node)) { + for (t_node = h_node->data; t_node; t_node = g_list_next (t_node)) { + hook = (GstTracerHook *) t_node->data; + /* Skip duplicate tracers from different hooks. This function is O(n), but + * that should be fine since the number of tracers enabled on a process + * should be small. */ + if (g_list_index (tracers, hook->tracer) >= 0) + continue; + tracers = g_list_prepend (tracers, gst_object_ref (hook->tracer)); + } + } + g_list_free (h_list); + + return tracers; +} -- 2.7.4