tracer: use a macros for the enabled check

Avoid a function call and check the variables from the macro.
This commit is contained in:
Stefan Sauer 2013-10-28 21:59:19 +01:00
parent e08fab7d5f
commit 11d6e13d73
4 changed files with 87 additions and 118 deletions

View file

@ -21,7 +21,6 @@
#include "gst_private.h" #include "gst_private.h"
#include "gstenumtypes.h" #include "gstenumtypes.h"
#include "gstquark.h"
#include "gstregistry.h" #include "gstregistry.h"
#include "gsttracer.h" #include "gsttracer.h"
#include "gsttracerfactory.h" #include "gsttracerfactory.h"
@ -124,14 +123,14 @@ gst_tracer_get_property (GObject * object, guint prop_id,
} }
static void static void
gst_tracer_invoke (GstTracer * self, GstTracerHookId id, guint64 ts, gst_tracer_invoke (GstTracer * self, GstTracerHookId hid,
GstStructure * s) GstTracerMessageId mid, va_list var_args)
{ {
GstTracerClass *klass = GST_TRACER_GET_CLASS (self); GstTracerClass *klass = GST_TRACER_GET_CLASS (self);
g_return_if_fail (klass->invoke); g_return_if_fail (klass->invoke);
klass->invoke (self, id, ts, s); klass->invoke (self, hid, mid, var_args);
} }
/* tracing modules */ /* tracing modules */
@ -193,9 +192,9 @@ gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type)
/* tracing helpers */ /* tracing helpers */
static gboolean tracer_enabled = FALSE; gboolean _priv_tracer_enabled = FALSE;
/* TODO(ensonic): use GPtrArray ? */
static GList *tracers[GST_TRACER_HOOK_ID_LAST] = { NULL, }; GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST] = { NULL, };
/* Initialize the debugging system */ /* Initialize the debugging system */
void void
@ -235,7 +234,7 @@ _priv_gst_tracer_init (void)
j = 0; j = 0;
while (mask && (j < GST_TRACER_HOOK_ID_LAST)) { while (mask && (j < GST_TRACER_HOOK_ID_LAST)) {
if (mask & 1) { if (mask & 1) {
tracers[j] = g_list_prepend (tracers[j], _priv_tracers[j] = g_list_prepend (_priv_tracers[j],
gst_object_ref (tracer)); gst_object_ref (tracer));
GST_WARNING_OBJECT (tracer, "added tracer to hook %d", j); GST_WARNING_OBJECT (tracer, "added tracer to hook %d", j);
} }
@ -243,7 +242,7 @@ _priv_gst_tracer_init (void)
j++; j++;
} }
tracer_enabled = TRUE; _priv_tracer_enabled = TRUE;
} else { } else {
GST_WARNING_OBJECT (tracer, GST_WARNING_OBJECT (tracer,
"tracer with zero mask won't have any effect"); "tracer with zero mask won't have any effect");
@ -270,64 +269,26 @@ _priv_gst_tracer_deinit (void)
/* shutdown tracers for final reports */ /* shutdown tracers for final reports */
for (i = 0; i < GST_TRACER_HOOK_ID_LAST; i++) { for (i = 0; i < GST_TRACER_HOOK_ID_LAST; i++) {
for (node = tracers[i]; node; node = g_list_next (node)) { for (node = _priv_tracers[i]; node; node = g_list_next (node)) {
gst_object_unref (node->data); gst_object_unref (node->data);
} }
g_list_free (tracers[i]); g_list_free (_priv_tracers[i]);
tracers[i] = NULL; _priv_tracers[i] = NULL;
} }
_priv_tracer_enabled = FALSE;
} }
gboolean void
gst_tracer_is_enabled (GstTracerHookId id) gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...)
{
return tracer_enabled && (tracers[id] != NULL);
}
static void
dispatch (GstTracerHookId id, guint64 ts, GstStructure * s)
{ {
va_list var_args;
GList *node; GList *node;
for (node = tracers[id]; node; node = g_list_next (node)) {
gst_tracer_invoke (node->data, id, ts, s); for (node = _priv_tracers[hid]; node; node = g_list_next (node)) {
va_start (var_args, mid);
gst_tracer_invoke (node->data, hid, mid, var_args);
va_end (var_args);
} }
} }
/* tracing hooks */
void
gst_tracer_push_pre (guint64 ts, GstPad * pad, GstBuffer * buffer)
{
dispatch (GST_TRACER_HOOK_ID_BUFFERS, ts,
gst_structure_new_id (GST_QUARK (PUSH_BUFFER_PRE),
GST_QUARK (PAD), GST_TYPE_PAD, pad,
GST_QUARK (BUFFER), GST_TYPE_BUFFER, buffer, NULL));
}
void
gst_tracer_push_post (guint64 ts, GstPad * pad, GstFlowReturn res)
{
dispatch (GST_TRACER_HOOK_ID_BUFFERS, ts,
gst_structure_new_id (GST_QUARK (PUSH_BUFFER_POST),
GST_QUARK (PAD), GST_TYPE_PAD, pad,
GST_QUARK (RETURN), G_TYPE_INT, res, NULL));
}
void
gst_tracer_push_list_pre (guint64 ts, GstPad * pad, GstBufferList * list)
{
dispatch (GST_TRACER_HOOK_ID_BUFFERS, ts,
gst_structure_new_id (GST_QUARK (PUSH_BUFFER_LIST_PRE),
GST_QUARK (PAD), GST_TYPE_PAD, pad,
GST_QUARK (LIST), GST_TYPE_BUFFER_LIST, list, NULL));
}
void
gst_tracer_push_list_post (guint64 ts, GstPad * pad, GstFlowReturn res)
{
dispatch (GST_TRACER_HOOK_ID_BUFFERS, ts,
gst_structure_new_id (GST_QUARK (PUSH_BUFFER_LIST_POST),
GST_QUARK (PAD), GST_TYPE_PAD, pad,
GST_QUARK (RETURN), G_TYPE_INT, res, NULL));
}
#endif /* GST_DISABLE_GST_DEBUG */ #endif /* GST_DISABLE_GST_DEBUG */

View file

@ -60,6 +60,15 @@ typedef enum
GST_TRACER_HOOK_ID_LAST GST_TRACER_HOOK_ID_LAST
} GstTracerHookId; } GstTracerHookId;
typedef enum
{
GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE = 0,
GST_TRACER_MESSAGE_ID_PAD_PUSH_POST,
GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_PRE,
GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_POST,
GST_TRACER_MESSAGE_ID_LAST
} GstTracerMessageId;
/* tracing plugins */ /* tracing plugins */
typedef struct _GstTracer GstTracer; typedef struct _GstTracer GstTracer;
@ -81,8 +90,8 @@ struct _GstTracer {
gpointer _gst_reserved[GST_PADDING]; gpointer _gst_reserved[GST_PADDING];
}; };
typedef void (*GstTracerInvokeFunction) (GstTracer * self, GstTracerHookId id, typedef void (*GstTracerInvokeFunction) (GstTracer * self, GstTracerHookId hid,
guint64 ts, GstStructure *s); GstTracerMessageId mid, va_list var_args);
struct _GstTracerClass { struct _GstTracerClass {
GstObjectClass parent_class; GstObjectClass parent_class;
@ -102,32 +111,46 @@ void _priv_gst_tracer_init (void);
void _priv_gst_tracer_deinit (void); void _priv_gst_tracer_deinit (void);
gboolean gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type); gboolean gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type);
void gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...);
gboolean gst_tracer_is_enabled (GstTracerHookId id); extern gboolean _priv_tracer_enabled;
extern GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST];
void gst_tracer_push_pre (guint64 ts, GstPad *pad, GstBuffer *buffer); #define GST_TRACER_IS_ENABLED(id) \
void gst_tracer_push_post (guint64 ts, GstPad *pad, GstFlowReturn res); (_priv_tracer_enabled && (_priv_tracers[id] != NULL))
void gst_tracer_push_list_pre (guint64 ts, GstPad * pad, GstBufferList * list);
void gst_tracer_push_list_post (guint64 ts, GstPad * pad, GstFlowReturn res); /* tracing hooks */
#define GST_TRACER_PAD_PUSH_PRE(pad, buffer) G_STMT_START{ \ #define GST_TRACER_PAD_PUSH_PRE(pad, buffer) G_STMT_START{ \
if (gst_tracer_is_enabled (GST_TRACER_HOOK_ID_BUFFERS)) \ if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
gst_tracer_push_pre (gst_util_get_timestamp (), pad, buffer); \ gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE, gst_util_get_timestamp (), \
pad, buffer); \
} \
}G_STMT_END }G_STMT_END
#define GST_TRACER_PAD_PUSH_POST(pad, res) G_STMT_START{ \ #define GST_TRACER_PAD_PUSH_POST(pad, res) G_STMT_START{ \
if (gst_tracer_is_enabled (GST_TRACER_HOOK_ID_BUFFERS)) \ if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
gst_tracer_push_post (gst_util_get_timestamp (), pad, res); \ gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
GST_TRACER_MESSAGE_ID_PAD_PUSH_POST, gst_util_get_timestamp (), \
pad, res); \
} \
}G_STMT_END }G_STMT_END
#define GST_TRACER_PAD_PUSH_LIST_PRE(pad, list) G_STMT_START{ \ #define GST_TRACER_PAD_PUSH_LIST_PRE(pad, list) G_STMT_START{ \
if (gst_tracer_is_enabled (GST_TRACER_HOOK_ID_BUFFERS)) \ if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
gst_tracer_push_list_pre (gst_util_get_timestamp (), pad, list); \ gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_PRE, gst_util_get_timestamp (), \
pad, list); \
} \
}G_STMT_END }G_STMT_END
#define GST_TRACER_PAD_PUSH_LIST_POST(pad, res) G_STMT_START{ \ #define GST_TRACER_PAD_PUSH_LIST_POST(pad, res) G_STMT_START{ \
if (gst_tracer_is_enabled (GST_TRACER_HOOK_ID_BUFFERS)) \ if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
gst_tracer_push_list_post (gst_util_get_timestamp (), pad, res); \ gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_POST, gst_util_get_timestamp (), \
pad, res); \
} \
}G_STMT_END }G_STMT_END
#else /* !GST_DISABLE_GST_DEBUG */ #else /* !GST_DISABLE_GST_DEBUG */

View file

@ -35,7 +35,7 @@ G_DEFINE_TYPE_WITH_CODE (GstLogTracer, gst_log_tracer, GST_TYPE_TRACER,
_do_init); _do_init);
static void gst_log_tracer_invoke (GstTracer * self, GstTracerHookId id, static void gst_log_tracer_invoke (GstTracer * self, GstTracerHookId id,
guint64 ts, GstStructure * s); GstTracerMessageId mid, va_list var_args);
static void static void
gst_log_tracer_class_init (GstLogTracerClass * klass) gst_log_tracer_class_init (GstLogTracerClass * klass)
@ -52,17 +52,16 @@ gst_log_tracer_init (GstLogTracer * self)
} }
static void static void
gst_log_tracer_invoke (GstTracer * self, GstTracerHookId id, guint64 ts, gst_log_tracer_invoke (GstTracer * self, GstTracerHookId hid,
GstStructure * s) GstTracerMessageId mid, va_list var_args)
{ {
gchar *str = gst_structure_to_string (s); guint64 ts = va_arg (var_args, guint64);
/* TODO(ensonic): log to different categories depending on 'id' /* TODO(ensonic): log to different categories depending on 'hid'/'mid'
* GST_TRACER_HOOK_ID_BUFFERS -> GST_CAT_BUFFER * GST_TRACER_HOOK_ID_BUFFERS -> GST_CAT_BUFFER
* GST_TRACER_HOOK_ID_EVENTS -> GST_CAT_EVENT * GST_TRACER_HOOK_ID_EVENTS -> GST_CAT_EVENT
* GST_TRACER_HOOK_ID_MESSAGES -> GST_CAT_MESSAGE * GST_TRACER_HOOK_ID_MESSAGES -> GST_CAT_MESSAGE
* GST_TRACER_HOOK_ID_QUERIES -> ? * GST_TRACER_HOOK_ID_QUERIES -> ?
* GST_TRACER_HOOK_ID_TOPLOGY -> ? * GST_TRACER_HOOK_ID_TOPLOGY -> ?
*/ */
GST_TRACE ("%s", str); GST_TRACE ("[%d,%d] %" GST_TIME_FORMAT, hid, mid, GST_TIME_ARGS (ts));
g_free (str);
} }

View file

@ -30,26 +30,12 @@
GST_DEBUG_CATEGORY_STATIC (gst_stats_debug); GST_DEBUG_CATEGORY_STATIC (gst_stats_debug);
#define GST_CAT_DEFAULT gst_stats_debug #define GST_CAT_DEFAULT gst_stats_debug
/* TODO(ensonic): the quark table from gst/gstquark.{c,h} is not exported
* - we need a tracer specific quark table
* - or we add a GQuark gst_quark_get (GstQuarkId id); there for external use
*/
enum _FuncEnum
{
PUSH_BUFFER_PRE,
PUSH_BUFFER_POST,
N_FUNCS
};
static GQuark data_quark; static GQuark data_quark;
static GQuark funcs[N_FUNCS];
G_LOCK_DEFINE (_stats); G_LOCK_DEFINE (_stats);
#define _do_init \ #define _do_init \
GST_DEBUG_CATEGORY_INIT (gst_stats_debug, "stats", 0, "stats tracer"); \ GST_DEBUG_CATEGORY_INIT (gst_stats_debug, "stats", 0, "stats tracer"); \
data_quark = g_quark_from_static_string ("gststats:data"); \ data_quark = g_quark_from_static_string ("gststats:data");
funcs[PUSH_BUFFER_PRE] = g_quark_from_static_string ("push_buffer::pre"); \
funcs[PUSH_BUFFER_POST] = g_quark_from_static_string ("push_buffer::post");
#define gst_stats_tracer_parent_class parent_class #define gst_stats_tracer_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstStatsTracer, gst_stats_tracer, GST_TYPE_TRACER, G_DEFINE_TYPE_WITH_CODE (GstStatsTracer, gst_stats_tracer, GST_TYPE_TRACER,
_do_init); _do_init);
@ -453,7 +439,7 @@ do_element_stats (GstStatsTracer * self, GstPad * pad, GstClockTime elapsed1,
static void gst_stats_tracer_finalize (GObject * obj); static void gst_stats_tracer_finalize (GObject * obj);
static void gst_stats_tracer_invoke (GstTracer * obj, GstTracerHookId id, static void gst_stats_tracer_invoke (GstTracer * obj, GstTracerHookId id,
guint64 ts, GstStructure * s); GstTracerMessageId mid, va_list var_args);
static void static void
gst_stats_tracer_class_init (GstStatsTracerClass * klass) gst_stats_tracer_class_init (GstStatsTracerClass * klass)
@ -477,43 +463,43 @@ gst_stats_tracer_init (GstStatsTracer * self)
} }
static void static void
do_push_buffer_pre (GstStatsTracer * self, guint64 ts, GstStructure * s) do_push_buffer_pre (GstStatsTracer * self, va_list var_args)
{ {
GstPad *pad; guint64 ts = va_arg (var_args, guint64);
GstBuffer *buffer; GstPad *pad = va_arg (var_args, GstPad *);
GstPadStats *stats; GstBuffer *buffer = va_arg (var_args, GstBuffer *);
GstPadStats *stats = get_pad_stats (self, pad);
gst_structure_get (s,
"pad", GST_TYPE_PAD, &pad, "buffer", GST_TYPE_BUFFER, &buffer, NULL);
stats = get_pad_stats (self, pad);
do_pad_stats (self, pad, stats, buffer, ts); do_pad_stats (self, pad, stats, buffer, ts);
do_transmission_stats (self, pad, buffer, ts); do_transmission_stats (self, pad, buffer, ts);
} }
static void static void
do_push_buffer_post (GstStatsTracer * self, guint64 ts, GstStructure * s) do_push_buffer_post (GstStatsTracer * self, va_list var_args)
{ {
GstPad *pad; guint64 ts = va_arg (var_args, guint64);
GstPadStats *stats; GstPad *pad = va_arg (var_args, GstPad *);
GstPadStats *stats = get_pad_stats (self, pad);
gst_structure_get (s, "pad", GST_TYPE_PAD, &pad, NULL);
stats = get_pad_stats (self, pad);
do_element_stats (self, pad, stats->last_ts, ts); do_element_stats (self, pad, stats->last_ts, ts);
} }
static void static void
gst_stats_tracer_invoke (GstTracer * obj, GstTracerHookId id, guint64 ts, gst_stats_tracer_invoke (GstTracer * obj, GstTracerHookId hid,
GstStructure * s) GstTracerMessageId mid, va_list var_args)
{ {
GstStatsTracer *self = GST_STATS_TRACER_CAST (obj); GstStatsTracer *self = GST_STATS_TRACER_CAST (obj);
GQuark func = gst_structure_get_name_id (s);
if (func == funcs[PUSH_BUFFER_PRE]) switch (mid) {
do_push_buffer_pre (self, ts, s); case GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE:
else if (func == funcs[PUSH_BUFFER_POST]) do_push_buffer_pre (self, var_args);
do_push_buffer_post (self, ts, s); break;
case GST_TRACER_MESSAGE_ID_PAD_PUSH_POST:
do_push_buffer_post (self, var_args);
break;
default:
break;
}
} }
static void static void