mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 18:05:37 +00:00
tracer: use a macros for the enabled check
Avoid a function call and check the variables from the macro.
This commit is contained in:
parent
e08fab7d5f
commit
11d6e13d73
4 changed files with 87 additions and 118 deletions
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "gst_private.h"
|
||||
#include "gstenumtypes.h"
|
||||
#include "gstquark.h"
|
||||
#include "gstregistry.h"
|
||||
#include "gsttracer.h"
|
||||
#include "gsttracerfactory.h"
|
||||
|
@ -124,14 +123,14 @@ gst_tracer_get_property (GObject * object, guint prop_id,
|
|||
}
|
||||
|
||||
static void
|
||||
gst_tracer_invoke (GstTracer * self, GstTracerHookId id, guint64 ts,
|
||||
GstStructure * s)
|
||||
gst_tracer_invoke (GstTracer * self, GstTracerHookId hid,
|
||||
GstTracerMessageId mid, va_list var_args)
|
||||
{
|
||||
GstTracerClass *klass = GST_TRACER_GET_CLASS (self);
|
||||
|
||||
g_return_if_fail (klass->invoke);
|
||||
|
||||
klass->invoke (self, id, ts, s);
|
||||
klass->invoke (self, hid, mid, var_args);
|
||||
}
|
||||
|
||||
/* tracing modules */
|
||||
|
@ -193,9 +192,9 @@ gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type)
|
|||
|
||||
/* tracing helpers */
|
||||
|
||||
static gboolean tracer_enabled = FALSE;
|
||||
|
||||
static GList *tracers[GST_TRACER_HOOK_ID_LAST] = { NULL, };
|
||||
gboolean _priv_tracer_enabled = FALSE;
|
||||
/* TODO(ensonic): use GPtrArray ? */
|
||||
GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST] = { NULL, };
|
||||
|
||||
/* Initialize the debugging system */
|
||||
void
|
||||
|
@ -235,7 +234,7 @@ _priv_gst_tracer_init (void)
|
|||
j = 0;
|
||||
while (mask && (j < GST_TRACER_HOOK_ID_LAST)) {
|
||||
if (mask & 1) {
|
||||
tracers[j] = g_list_prepend (tracers[j],
|
||||
_priv_tracers[j] = g_list_prepend (_priv_tracers[j],
|
||||
gst_object_ref (tracer));
|
||||
GST_WARNING_OBJECT (tracer, "added tracer to hook %d", j);
|
||||
}
|
||||
|
@ -243,7 +242,7 @@ _priv_gst_tracer_init (void)
|
|||
j++;
|
||||
}
|
||||
|
||||
tracer_enabled = TRUE;
|
||||
_priv_tracer_enabled = TRUE;
|
||||
} else {
|
||||
GST_WARNING_OBJECT (tracer,
|
||||
"tracer with zero mask won't have any effect");
|
||||
|
@ -270,64 +269,26 @@ _priv_gst_tracer_deinit (void)
|
|||
|
||||
/* shutdown tracers for final reports */
|
||||
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);
|
||||
}
|
||||
g_list_free (tracers[i]);
|
||||
tracers[i] = NULL;
|
||||
g_list_free (_priv_tracers[i]);
|
||||
_priv_tracers[i] = NULL;
|
||||
}
|
||||
_priv_tracer_enabled = FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_tracer_is_enabled (GstTracerHookId id)
|
||||
{
|
||||
return tracer_enabled && (tracers[id] != NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
dispatch (GstTracerHookId id, guint64 ts, GstStructure * s)
|
||||
void
|
||||
gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...)
|
||||
{
|
||||
va_list var_args;
|
||||
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 */
|
||||
|
|
|
@ -60,6 +60,15 @@ typedef enum
|
|||
GST_TRACER_HOOK_ID_LAST
|
||||
} 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 */
|
||||
|
||||
typedef struct _GstTracer GstTracer;
|
||||
|
@ -81,8 +90,8 @@ struct _GstTracer {
|
|||
gpointer _gst_reserved[GST_PADDING];
|
||||
};
|
||||
|
||||
typedef void (*GstTracerInvokeFunction) (GstTracer * self, GstTracerHookId id,
|
||||
guint64 ts, GstStructure *s);
|
||||
typedef void (*GstTracerInvokeFunction) (GstTracer * self, GstTracerHookId hid,
|
||||
GstTracerMessageId mid, va_list var_args);
|
||||
|
||||
struct _GstTracerClass {
|
||||
GstObjectClass parent_class;
|
||||
|
@ -102,32 +111,46 @@ void _priv_gst_tracer_init (void);
|
|||
void _priv_gst_tracer_deinit (void);
|
||||
|
||||
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);
|
||||
void gst_tracer_push_post (guint64 ts, GstPad *pad, GstFlowReturn res);
|
||||
void gst_tracer_push_list_pre (guint64 ts, GstPad * pad, GstBufferList * list);
|
||||
void gst_tracer_push_list_post (guint64 ts, GstPad * pad, GstFlowReturn res);
|
||||
#define GST_TRACER_IS_ENABLED(id) \
|
||||
(_priv_tracer_enabled && (_priv_tracers[id] != NULL))
|
||||
|
||||
/* tracing hooks */
|
||||
|
||||
#define GST_TRACER_PAD_PUSH_PRE(pad, buffer) G_STMT_START{ \
|
||||
if (gst_tracer_is_enabled (GST_TRACER_HOOK_ID_BUFFERS)) \
|
||||
gst_tracer_push_pre (gst_util_get_timestamp (), pad, buffer); \
|
||||
if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
|
||||
gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
|
||||
GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE, gst_util_get_timestamp (), \
|
||||
pad, buffer); \
|
||||
} \
|
||||
}G_STMT_END
|
||||
|
||||
#define GST_TRACER_PAD_PUSH_POST(pad, res) G_STMT_START{ \
|
||||
if (gst_tracer_is_enabled (GST_TRACER_HOOK_ID_BUFFERS)) \
|
||||
gst_tracer_push_post (gst_util_get_timestamp (), pad, res); \
|
||||
if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
|
||||
gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
|
||||
GST_TRACER_MESSAGE_ID_PAD_PUSH_POST, gst_util_get_timestamp (), \
|
||||
pad, res); \
|
||||
} \
|
||||
}G_STMT_END
|
||||
|
||||
#define GST_TRACER_PAD_PUSH_LIST_PRE(pad, list) G_STMT_START{ \
|
||||
if (gst_tracer_is_enabled (GST_TRACER_HOOK_ID_BUFFERS)) \
|
||||
gst_tracer_push_list_pre (gst_util_get_timestamp (), pad, list); \
|
||||
if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
|
||||
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
|
||||
|
||||
#define GST_TRACER_PAD_PUSH_LIST_POST(pad, res) G_STMT_START{ \
|
||||
if (gst_tracer_is_enabled (GST_TRACER_HOOK_ID_BUFFERS)) \
|
||||
gst_tracer_push_list_post (gst_util_get_timestamp (), pad, res); \
|
||||
if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
|
||||
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
|
||||
|
||||
#else /* !GST_DISABLE_GST_DEBUG */
|
||||
|
|
|
@ -35,7 +35,7 @@ G_DEFINE_TYPE_WITH_CODE (GstLogTracer, gst_log_tracer, GST_TYPE_TRACER,
|
|||
_do_init);
|
||||
|
||||
static void gst_log_tracer_invoke (GstTracer * self, GstTracerHookId id,
|
||||
guint64 ts, GstStructure * s);
|
||||
GstTracerMessageId mid, va_list var_args);
|
||||
|
||||
static void
|
||||
gst_log_tracer_class_init (GstLogTracerClass * klass)
|
||||
|
@ -52,17 +52,16 @@ gst_log_tracer_init (GstLogTracer * self)
|
|||
}
|
||||
|
||||
static void
|
||||
gst_log_tracer_invoke (GstTracer * self, GstTracerHookId id, guint64 ts,
|
||||
GstStructure * s)
|
||||
gst_log_tracer_invoke (GstTracer * self, GstTracerHookId hid,
|
||||
GstTracerMessageId mid, va_list var_args)
|
||||
{
|
||||
gchar *str = gst_structure_to_string (s);
|
||||
/* TODO(ensonic): log to different categories depending on 'id'
|
||||
guint64 ts = va_arg (var_args, guint64);
|
||||
/* TODO(ensonic): log to different categories depending on 'hid'/'mid'
|
||||
* GST_TRACER_HOOK_ID_BUFFERS -> GST_CAT_BUFFER
|
||||
* GST_TRACER_HOOK_ID_EVENTS -> GST_CAT_EVENT
|
||||
* GST_TRACER_HOOK_ID_MESSAGES -> GST_CAT_MESSAGE
|
||||
* GST_TRACER_HOOK_ID_QUERIES -> ?
|
||||
* GST_TRACER_HOOK_ID_TOPLOGY -> ?
|
||||
*/
|
||||
GST_TRACE ("%s", str);
|
||||
g_free (str);
|
||||
GST_TRACE ("[%d,%d] %" GST_TIME_FORMAT, hid, mid, GST_TIME_ARGS (ts));
|
||||
}
|
||||
|
|
|
@ -30,26 +30,12 @@
|
|||
GST_DEBUG_CATEGORY_STATIC (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 funcs[N_FUNCS];
|
||||
G_LOCK_DEFINE (_stats);
|
||||
|
||||
#define _do_init \
|
||||
GST_DEBUG_CATEGORY_INIT (gst_stats_debug, "stats", 0, "stats tracer"); \
|
||||
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");
|
||||
data_quark = g_quark_from_static_string ("gststats:data");
|
||||
#define gst_stats_tracer_parent_class parent_class
|
||||
G_DEFINE_TYPE_WITH_CODE (GstStatsTracer, gst_stats_tracer, GST_TYPE_TRACER,
|
||||
_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_invoke (GstTracer * obj, GstTracerHookId id,
|
||||
guint64 ts, GstStructure * s);
|
||||
GstTracerMessageId mid, va_list var_args);
|
||||
|
||||
static void
|
||||
gst_stats_tracer_class_init (GstStatsTracerClass * klass)
|
||||
|
@ -477,43 +463,43 @@ gst_stats_tracer_init (GstStatsTracer * self)
|
|||
}
|
||||
|
||||
static void
|
||||
do_push_buffer_pre (GstStatsTracer * self, guint64 ts, GstStructure * s)
|
||||
do_push_buffer_pre (GstStatsTracer * self, va_list var_args)
|
||||
{
|
||||
GstPad *pad;
|
||||
GstBuffer *buffer;
|
||||
GstPadStats *stats;
|
||||
|
||||
gst_structure_get (s,
|
||||
"pad", GST_TYPE_PAD, &pad, "buffer", GST_TYPE_BUFFER, &buffer, NULL);
|
||||
stats = get_pad_stats (self, pad);
|
||||
guint64 ts = va_arg (var_args, guint64);
|
||||
GstPad *pad = va_arg (var_args, GstPad *);
|
||||
GstBuffer *buffer = va_arg (var_args, GstBuffer *);
|
||||
GstPadStats *stats = get_pad_stats (self, pad);
|
||||
|
||||
do_pad_stats (self, pad, stats, buffer, ts);
|
||||
do_transmission_stats (self, pad, buffer, ts);
|
||||
}
|
||||
|
||||
static void
|
||||
do_push_buffer_post (GstStatsTracer * self, guint64 ts, GstStructure * s)
|
||||
do_push_buffer_post (GstStatsTracer * self, va_list var_args)
|
||||
{
|
||||
GstPad *pad;
|
||||
GstPadStats *stats;
|
||||
|
||||
gst_structure_get (s, "pad", GST_TYPE_PAD, &pad, NULL);
|
||||
stats = get_pad_stats (self, pad);
|
||||
guint64 ts = va_arg (var_args, guint64);
|
||||
GstPad *pad = va_arg (var_args, GstPad *);
|
||||
GstPadStats *stats = get_pad_stats (self, pad);
|
||||
|
||||
do_element_stats (self, pad, stats->last_ts, ts);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_stats_tracer_invoke (GstTracer * obj, GstTracerHookId id, guint64 ts,
|
||||
GstStructure * s)
|
||||
gst_stats_tracer_invoke (GstTracer * obj, GstTracerHookId hid,
|
||||
GstTracerMessageId mid, va_list var_args)
|
||||
{
|
||||
GstStatsTracer *self = GST_STATS_TRACER_CAST (obj);
|
||||
GQuark func = gst_structure_get_name_id (s);
|
||||
|
||||
if (func == funcs[PUSH_BUFFER_PRE])
|
||||
do_push_buffer_pre (self, ts, s);
|
||||
else if (func == funcs[PUSH_BUFFER_POST])
|
||||
do_push_buffer_post (self, ts, s);
|
||||
switch (mid) {
|
||||
case GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE:
|
||||
do_push_buffer_pre (self, var_args);
|
||||
break;
|
||||
case GST_TRACER_MESSAGE_ID_PAD_PUSH_POST:
|
||||
do_push_buffer_post (self, var_args);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue