2014-07-18 05:49:38 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
|
|
|
|
*
|
|
|
|
* gsttracerutils.c: tracing subsystem
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gsttracerutils
|
|
|
|
* @short_description: Tracing subsystem
|
|
|
|
*
|
|
|
|
* The tracing subsystem provides hooks in the core library and API for modules
|
|
|
|
* to attach to them.
|
|
|
|
*
|
|
|
|
* The user can activate tracers by setting the environment variable GST_TRACE
|
|
|
|
* to a ';' separated list of tracers.
|
2016-01-22 10:25:30 +00:00
|
|
|
*
|
|
|
|
* Note that instanciating tracers at runtime is possible but is not thread safe
|
|
|
|
* and needs to be done before any pipeline state is set to PAUSED.
|
2014-07-18 05:49:38 +00:00
|
|
|
*/
|
|
|
|
|
2016-01-16 14:51:37 +00:00
|
|
|
#define GST_USE_UNSTABLE_API
|
|
|
|
|
2014-07-18 05:49:38 +00:00
|
|
|
#include "gst_private.h"
|
|
|
|
#include "gsttracer.h"
|
|
|
|
#include "gsttracerfactory.h"
|
|
|
|
#include "gsttracerutils.h"
|
|
|
|
|
2016-01-07 16:46:21 +00:00
|
|
|
#ifndef GST_DISABLE_GST_TRACER_HOOKS
|
2014-07-18 05:49:38 +00:00
|
|
|
|
2014-09-15 20:27:11 +00:00
|
|
|
/* tracer quarks */
|
|
|
|
|
|
|
|
/* These strings must match order and number declared in the GstTracerQuarkId
|
|
|
|
* enum in gsttracerutils.h! */
|
|
|
|
static const gchar *_quark_strings[] = {
|
|
|
|
"pad-push-pre", "pad-push-post", "pad-push-list-pre", "pad-push-list-post",
|
|
|
|
"pad-pull-range-pre", "pad-pull-range-post", "pad-push-event-pre",
|
2015-03-13 13:10:42 +00:00
|
|
|
"pad-push-event-post", "pad-query-pre", "pad-query-post",
|
|
|
|
"element-post-message-pre",
|
tracer: add missing hooks
Add following hooks: element-new, element-add-pad, element-remove-pad,
bin-add-pre, bin-add-post, bin-remove-pre, bin-remove-post, pad-link-pre,
pad-link-post, pad-unlink-pre, pad-unlink-post.
https://bugzilla.gnome.org/show_bug.cgi?id=733187
2015-06-03 23:50:34 +00:00
|
|
|
"element-post-message-post", "element-query-pre", "element-query-post",
|
2015-10-29 11:40:32 +00:00
|
|
|
"element-new", "element-add-pad", "element-remove-pad",
|
|
|
|
"bin-add-pre", "bin-add-post", "bin-remove-pre", "bin-remove-post",
|
|
|
|
"pad-link-pre", "pad-link-post", "pad-unlink-pre", "pad-unlink-post",
|
|
|
|
"element-change-state-pre", "element-change-state-post"
|
2014-09-15 20:27:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GQuark _priv_gst_tracer_quark_table[GST_TRACER_QUARK_MAX];
|
|
|
|
|
2014-07-18 05:49:38 +00:00
|
|
|
/* tracing helpers */
|
|
|
|
|
|
|
|
gboolean _priv_tracer_enabled = FALSE;
|
2014-09-15 20:27:11 +00:00
|
|
|
GHashTable *_priv_tracers = NULL;
|
2014-07-18 05:49:38 +00:00
|
|
|
|
|
|
|
/* Initialize the tracing system */
|
|
|
|
void
|
2014-09-22 07:55:56 +00:00
|
|
|
_priv_gst_tracing_init (void)
|
2014-07-18 05:49:38 +00:00
|
|
|
{
|
2016-01-22 10:25:30 +00:00
|
|
|
gint i = 0;
|
2016-01-22 12:50:08 +00:00
|
|
|
const gchar *env = g_getenv ("GST_TRACERS");
|
2014-07-18 05:49:38 +00:00
|
|
|
|
2016-01-22 10:25:30 +00:00
|
|
|
/* We initialize the tracer sub system even if the end
|
|
|
|
* user did not activate it through the env variable
|
|
|
|
* so that external tools can use it anyway */
|
|
|
|
GST_DEBUG ("Initializing GstTracer");
|
|
|
|
_priv_tracers = g_hash_table_new (NULL, NULL);
|
|
|
|
|
|
|
|
if (G_N_ELEMENTS (_quark_strings) != GST_TRACER_QUARK_MAX)
|
|
|
|
g_warning ("the quark table is not consistent! %d != %d",
|
|
|
|
(gint) G_N_ELEMENTS (_quark_strings), GST_TRACER_QUARK_MAX);
|
|
|
|
|
|
|
|
for (i = 0; i < GST_TRACER_QUARK_MAX; i++) {
|
|
|
|
_priv_gst_tracer_quark_table[i] =
|
|
|
|
g_quark_from_static_string (_quark_strings[i]);
|
|
|
|
}
|
|
|
|
|
2014-07-18 05:49:38 +00:00
|
|
|
if (env != NULL && *env != '\0') {
|
|
|
|
GstRegistry *registry = gst_registry_get ();
|
|
|
|
GstPluginFeature *feature;
|
|
|
|
GstTracerFactory *factory;
|
|
|
|
gchar **t = g_strsplit_set (env, ";", 0);
|
|
|
|
gchar *params;
|
|
|
|
|
|
|
|
GST_INFO ("enabling tracers: '%s'", env);
|
2014-09-15 20:27:11 +00:00
|
|
|
i = 0;
|
2014-07-18 05:49:38 +00:00
|
|
|
while (t[i]) {
|
|
|
|
// check t[i] for params
|
|
|
|
if ((params = strchr (t[i], '('))) {
|
|
|
|
gchar *end = strchr (¶ms[1], ')');
|
|
|
|
*params = '\0';
|
|
|
|
params++;
|
|
|
|
if (end)
|
|
|
|
*end = '\0';
|
|
|
|
} else {
|
|
|
|
params = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_INFO ("checking tracer: '%s'", t[i]);
|
|
|
|
|
|
|
|
if ((feature = gst_registry_lookup_feature (registry, t[i]))) {
|
|
|
|
factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
|
|
|
|
if (factory) {
|
|
|
|
GST_INFO_OBJECT (factory, "creating tracer: type-id=%u",
|
|
|
|
(guint) factory->type);
|
|
|
|
|
2014-09-15 11:15:17 +00:00
|
|
|
/* tracers register them self to the hooks */
|
|
|
|
gst_object_unref (g_object_new (factory->type, "params", params,
|
|
|
|
NULL));
|
2014-07-18 05:49:38 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (feature,
|
|
|
|
"loading plugin containing feature %s failed!", t[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("no tracer named '%s'", t[i]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
g_strfreev (t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-22 07:55:56 +00:00
|
|
|
_priv_gst_tracing_deinit (void)
|
2014-07-18 05:49:38 +00:00
|
|
|
{
|
2014-09-15 20:27:11 +00:00
|
|
|
GList *h_list, *h_node, *t_node;
|
2014-09-15 11:15:17 +00:00
|
|
|
GstTracerHook *hook;
|
2014-07-18 05:49:38 +00:00
|
|
|
|
2014-09-15 20:27:11 +00:00
|
|
|
_priv_tracer_enabled = FALSE;
|
|
|
|
if (!_priv_tracers)
|
|
|
|
return;
|
|
|
|
|
2014-07-18 05:49:38 +00:00
|
|
|
/* shutdown tracers for final reports */
|
2014-09-15 20:27:11 +00:00
|
|
|
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;
|
2014-09-15 11:15:17 +00:00
|
|
|
gst_object_unref (hook->tracer);
|
|
|
|
g_slice_free (GstTracerHook, hook);
|
2014-07-18 05:49:38 +00:00
|
|
|
}
|
2014-09-15 20:27:11 +00:00
|
|
|
g_list_free (h_node->data);
|
2014-07-18 05:49:38 +00:00
|
|
|
}
|
2014-09-15 20:27:11 +00:00
|
|
|
g_list_free (h_list);
|
|
|
|
g_hash_table_destroy (_priv_tracers);
|
|
|
|
_priv_tracers = NULL;
|
2014-07-18 05:49:38 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 19:41:26 +00:00
|
|
|
static void
|
2014-09-22 07:55:56 +00:00
|
|
|
gst_tracing_register_hook_id (GstTracer * tracer, GQuark detail, GCallback func)
|
2014-09-15 11:15:17 +00:00
|
|
|
{
|
2014-09-15 20:27:11 +00:00
|
|
|
gpointer key = GINT_TO_POINTER (detail);
|
|
|
|
GList *list = g_hash_table_lookup (_priv_tracers, key);
|
2014-09-15 11:15:17 +00:00
|
|
|
GstTracerHook *hook = g_slice_new0 (GstTracerHook);
|
|
|
|
hook->tracer = gst_object_ref (tracer);
|
|
|
|
hook->func = func;
|
2014-09-15 20:27:11 +00:00
|
|
|
|
|
|
|
list = g_list_prepend (list, hook);
|
|
|
|
g_hash_table_replace (_priv_tracers, key, list);
|
|
|
|
GST_DEBUG ("registering tracer for '%s', list.len=%d",
|
|
|
|
(detail ? g_quark_to_string (detail) : "*"), g_list_length (list));
|
2014-09-15 11:15:17 +00:00
|
|
|
_priv_tracer_enabled = TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-22 07:55:56 +00:00
|
|
|
/**
|
|
|
|
* gst_tracing_register_hook:
|
|
|
|
* @tracer: the tracer
|
|
|
|
* @detail: the detailed hook
|
|
|
|
* @func: (scope async): the callback
|
|
|
|
*
|
|
|
|
* Register @func to be called when the trace hook @detail is getting invoked.
|
2016-01-06 19:41:26 +00:00
|
|
|
* Use %NULL for @detail to register to all hooks.
|
2014-09-22 07:55:56 +00:00
|
|
|
*/
|
2014-09-15 11:15:17 +00:00
|
|
|
void
|
2014-09-22 07:55:56 +00:00
|
|
|
gst_tracing_register_hook (GstTracer * tracer, const gchar * detail,
|
2014-09-18 06:26:19 +00:00
|
|
|
GCallback func)
|
2014-09-15 20:27:11 +00:00
|
|
|
{
|
2014-09-22 07:55:56 +00:00
|
|
|
gst_tracing_register_hook_id (tracer, g_quark_try_string (detail), func);
|
2014-09-15 20:27:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 21:43:58 +00:00
|
|
|
#endif /* GST_DISABLE_GST_TRACER_HOOKS */
|