2 * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
4 * gsttracerutils.c: tracing subsystem
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 * SECTION:gsttracerutils
24 * @short_description: Tracing subsystem
26 * The tracing subsystem provides hooks in the core library and API for modules
29 * The user can activate tracers by setting the environment variable GST_TRACE
30 * to a ';' separated list of tracers.
33 #define GST_USE_UNSTABLE_API
35 #include "gst_private.h"
36 #include "gsttracer.h"
37 #include "gsttracerfactory.h"
38 #include "gsttracerutils.h"
40 #ifndef GST_DISABLE_GST_DEBUG
44 gboolean _priv_tracer_enabled = FALSE;
45 /* TODO(ensonic): use array of GPtrArray* ? */
46 GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST] = { NULL, };
51 GstTracerHookFunction func;
54 /* Initialize the tracing system */
56 _priv_gst_tracer_init (void)
58 const gchar *env = g_getenv ("GST_TRACE");
60 if (env != NULL && *env != '\0') {
61 GstRegistry *registry = gst_registry_get ();
62 GstPluginFeature *feature;
63 GstTracerFactory *factory;
64 gchar **t = g_strsplit_set (env, ";", 0);
68 GST_INFO ("enabling tracers: '%s'", env);
71 // check t[i] for params
72 if ((params = strchr (t[i], '('))) {
73 gchar *end = strchr (¶ms[1], ')');
82 GST_INFO ("checking tracer: '%s'", t[i]);
84 if ((feature = gst_registry_lookup_feature (registry, t[i]))) {
85 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
87 GST_INFO_OBJECT (factory, "creating tracer: type-id=%u",
88 (guint) factory->type);
90 /* tracers register them self to the hooks */
91 gst_object_unref (g_object_new (factory->type, "params", params,
94 GST_WARNING_OBJECT (feature,
95 "loading plugin containing feature %s failed!", t[i]);
98 GST_WARNING ("no tracer named '%s'", t[i]);
107 _priv_gst_tracer_deinit (void)
113 /* shutdown tracers for final reports */
114 for (i = 0; i < GST_TRACER_HOOK_ID_LAST; i++) {
115 for (node = _priv_tracers[i]; node; node = g_list_next (node)) {
116 hook = (GstTracerHook *) node->data;
117 gst_object_unref (hook->tracer);
118 g_slice_free (GstTracerHook, hook);
120 g_list_free (_priv_tracers[i]);
121 _priv_tracers[i] = NULL;
123 _priv_tracer_enabled = FALSE;
127 gst_tracer_register_hook (GstTracer * tracer, GstTracerHookId id,
128 GstTracerHookFunction func)
130 GstTracerHook *hook = g_slice_new0 (GstTracerHook);
131 hook->tracer = gst_object_ref (tracer);
133 _priv_tracers[id] = g_list_prepend (_priv_tracers[id], hook);
134 GST_DEBUG_OBJECT (tracer, "added tracer to hook %d", id);
135 _priv_tracer_enabled = TRUE;
139 gst_tracer_dispatch (GstTracerHookId id, ...)
145 for (node = _priv_tracers[id]; node; node = g_list_next (node)) {
146 hook = (GstTracerHook *) node->data;
147 va_start (var_args, id);
148 hook->func (hook->tracer, var_args);
153 #endif /* GST_DISABLE_GST_DEBUG */