gsttracer: Add new API to fetch the list of active tracers
authorNirbheek Chauhan <nirbheek@centricular.com>
Tue, 18 Jun 2019 22:52:42 +0000 (04:22 +0530)
committerNirbheek Chauhan <nirbheek@centricular.com>
Tue, 2 Jul 2019 09:43:26 +0000 (15:13 +0530)
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
gst/gsttracerutils.c

index 046ac22..751c1b3 100644 (file)
@@ -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)
index 2522cbf..d3a95b7 100644 (file)
@@ -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;
+}