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, };
48 /* Initialize the tracing system */
50 _priv_gst_tracer_init (void)
52 const gchar *env = g_getenv ("GST_TRACE");
54 if (env != NULL && *env != '\0') {
55 GstRegistry *registry = gst_registry_get ();
56 GstPluginFeature *feature;
57 GstTracerFactory *factory;
60 gchar **t = g_strsplit_set (env, ";", 0);
64 GST_INFO ("enabling tracers: '%s'", env);
67 // check t[i] for params
68 if ((params = strchr (t[i], '('))) {
69 gchar *end = strchr (¶ms[1], ')');
78 GST_INFO ("checking tracer: '%s'", t[i]);
80 if ((feature = gst_registry_lookup_feature (registry, t[i]))) {
81 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
83 GST_INFO_OBJECT (factory, "creating tracer: type-id=%u",
84 (guint) factory->type);
86 tracer = g_object_new (factory->type, "params", params, NULL);
87 g_object_get (tracer, "mask", &mask, NULL);
90 /* add to lists according to mask */
92 while (mask && (j < GST_TRACER_HOOK_ID_LAST)) {
94 _priv_tracers[j] = g_list_prepend (_priv_tracers[j],
95 gst_object_ref (tracer));
96 GST_WARNING_OBJECT (tracer, "added tracer to hook %d", j);
102 _priv_tracer_enabled = TRUE;
104 GST_WARNING_OBJECT (tracer,
105 "tracer with zero mask won't have any effect");
107 gst_object_unref (tracer);
109 GST_WARNING_OBJECT (feature,
110 "loading plugin containing feature %s failed!", t[i]);
113 GST_WARNING ("no tracer named '%s'", t[i]);
122 _priv_gst_tracer_deinit (void)
127 /* shutdown tracers for final reports */
128 for (i = 0; i < GST_TRACER_HOOK_ID_LAST; i++) {
129 for (node = _priv_tracers[i]; node; node = g_list_next (node)) {
130 gst_object_unref (node->data);
132 g_list_free (_priv_tracers[i]);
133 _priv_tracers[i] = NULL;
135 _priv_tracer_enabled = FALSE;
139 gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...)
144 for (node = _priv_tracers[hid]; node; node = g_list_next (node)) {
145 va_start (var_args, mid);
146 gst_tracer_invoke (node->data, mid, var_args);
151 #endif /* GST_DISABLE_GST_DEBUG */