tracer: add pad query hooks
authorThiago Santos <thiagoss@osg.samsung.com>
Fri, 13 Mar 2015 13:10:42 +0000 (13:10 +0000)
committerStefan Sauer <ensonic@users.sf.net>
Mon, 5 Oct 2015 18:59:39 +0000 (20:59 +0200)
gst/gstpad.c
gst/gsttracerutils.c
gst/gsttracerutils.h
plugins/tracers/gststats.c

index 0a56c6b..3b0300c 100644 (file)
@@ -3812,6 +3812,7 @@ gst_pad_query (GstPad * pad, GstQuery * query)
 
   GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
       GST_QUERY_TYPE_NAME (query));
+  GST_TRACER_PAD_QUERY_PRE (pad, query);
 
   serialized = GST_QUERY_IS_SERIALIZED (query);
   if (G_UNLIKELY (serialized))
@@ -3834,6 +3835,7 @@ gst_pad_query (GstPad * pad, GstQuery * query)
 
   GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
       GST_QUERY_TYPE_NAME (query), res);
+  GST_TRACER_PAD_QUERY_POST (pad, res, query);
 
   if (res != TRUE)
     goto query_failed;
index 376ad82..ed27ba8 100644 (file)
@@ -46,7 +46,8 @@
 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",
-  "pad-push-event-post", "element-post-message-pre",
+  "pad-push-event-post", "pad-query-pre", "pad-query-post",
+  "element-post-message-pre",
   "element-post-message-post", "element-query-pre", "element-query-post"
 };
 
index dedba2a..3d78fc8 100644 (file)
@@ -55,6 +55,8 @@ typedef enum _GstTracerQuarkId
   GST_TRACER_QUARK_HOOK_PAD_PULL_RANGE_POST,
   GST_TRACER_QUARK_HOOK_PAD_PUSH_EVENT_PRE ,
   GST_TRACER_QUARK_HOOK_PAD_PUSH_EVENT_POST,
+  GST_TRACER_QUARK_HOOK_PAD_QUERY_PRE ,
+  GST_TRACER_QUARK_HOOK_PAD_QUERY_POST,
   GST_TRACER_QUARK_HOOK_ELEMENT_POST_MESSAGE_PRE,
   GST_TRACER_QUARK_HOOK_ELEMENT_POST_MESSAGE_POST,
   GST_TRACER_QUARK_HOOK_ELEMENT_QUERY_PRE,
@@ -159,6 +161,20 @@ typedef void (*GstTracerHookPadPushEventPost) (GObject *, GstClockTime,
     GstTracerHookPadPushEventPost, (GST_TRACER_ARGS, pad, res)); \
 }G_STMT_END
 
+typedef void (*GstTracerHookPadQueryPre) (GObject *, GstClockTime, GstPad *,
+    GstQuery *);
+#define GST_TRACER_PAD_QUERY_PRE(pad, query) G_STMT_START{ \
+  GST_TRACER_DISPATCH(GST_TRACER_QUARK(HOOK_PAD_QUERY_PRE), \
+    GstTracerHookPadQueryPre, (GST_TRACER_ARGS, pad, query)); \
+}G_STMT_END
+
+typedef void (*GstTracerHookPadQueryPost) (GObject *, GstClockTime,
+    GstPad *, gboolean, GstQuery *);
+#define GST_TRACER_PAD_QUERY_POST(pad, res, query) G_STMT_START{ \
+  GST_TRACER_DISPATCH(GST_TRACER_QUARK(HOOK_PAD_QUERY_POST), \
+    GstTracerHookPadQueryPost, (GST_TRACER_ARGS, pad, res, query)); \
+}G_STMT_END
+
 typedef void (*GstTracerHookElementPostMessagePre) (GObject *, GstClockTime,
     GstElement *, GstMessage *);
 #define GST_TRACER_ELEMENT_POST_MESSAGE_PRE(element, message) G_STMT_START{ \
@@ -197,6 +213,8 @@ typedef void (*GstTracerHookElementQueryPost) (GObject *, GstClockTime,
 #define GST_TRACER_PAD_PULL_RANGE_POST(pad, buffer, res)
 #define GST_TRACER_PAD_PUSH_EVENT_PRE(pad, event)
 #define GST_TRACER_PAD_PUSH_EVENT_POST(pad, res)
+#define GST_TRACER_PAD_QUERY_PRE(pad, event)
+#define GST_TRACER_PAD_QUERY_POST(pad, res)
 #define GST_TRACER_ELEMENT_POST_MESSAGE_PRE(element, message)
 #define GST_TRACER_ELEMENT_POST_MESSAGE_POST(element, res)
 #define GST_TRACER_ELEMENT_QUERY_PRE(element, query)
index 87659eb..27db1fd 100644 (file)
@@ -259,6 +259,32 @@ do_buffer_stats (GstStatsTracer * self, GstPad * this_pad,
 }
 
 static void
+do_query_stats (GstStatsTracer * self, GstPad * this_pad,
+    GstPadStats * this_pad_stats, GstPad * that_pad,
+    GstPadStats * that_pad_stats, GstQuery * qry, GstClockTime elapsed,
+    gboolean res, gboolean pre)
+{
+  GstElement *this_elem = get_real_pad_parent (this_pad);
+  GstElementStats *this_elem_stats = get_element_stats (self, this_elem);
+  GstElement *that_elem = get_real_pad_parent (that_pad);
+  GstElementStats *that_elem_stats = get_element_stats (self, that_elem);
+  GstStructure *s;
+
+  s = gst_structure_new ("query",
+      "ts", G_TYPE_UINT64, elapsed,
+      "pad-ix", G_TYPE_UINT, this_pad_stats->index,
+      "elem-ix", G_TYPE_UINT, this_elem_stats->index,
+      "peer-pad-ix", G_TYPE_UINT, that_pad_stats->index,
+      "peer-elem-ix", G_TYPE_UINT, that_elem_stats->index,
+      "name", G_TYPE_STRING, GST_QUERY_TYPE_NAME (qry),
+      "structure", GST_TYPE_STRUCTURE, gst_query_get_structure (qry), NULL);
+  if (!pre) {
+    gst_structure_set (s, "res", G_TYPE_BOOLEAN, res, NULL);
+  }
+  gst_tracer_log_trace (s);
+}
+
+static void
 do_element_stats (GstStatsTracer * self, GstPad * pad, GstClockTime elapsed1,
     GstClockTime elapsed2)
 {
@@ -450,18 +476,42 @@ do_post_message_pre (GstStatsTracer * self, guint64 ts, GstElement * elem,
 }
 
 static void
-do_query_pre (GstStatsTracer * self, guint64 ts, GstElement * elem,
+do_element_query_pre (GstStatsTracer * self, guint64 ts, GstElement * elem,
     GstQuery * qry)
 {
   GstElementStats *stats = get_element_stats (self, elem);
 
   stats->last_ts = ts;
-  gst_tracer_log_trace (gst_structure_new ("query",
+  gst_tracer_log_trace (gst_structure_new ("element-query",
           "ts", G_TYPE_UINT64, ts,
           "elem-ix", G_TYPE_UINT, stats->index,
           "name", G_TYPE_STRING, GST_QUERY_TYPE_NAME (qry), NULL));
 }
 
+static void
+do_query_pre (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
+    GstQuery * qry)
+{
+  GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
+  GstPad *that_pad = GST_PAD_PEER (this_pad);
+  GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
+
+  do_query_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
+      qry, ts, FALSE, TRUE);
+}
+
+static void
+do_query_post (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
+    gboolean res, GstQuery * qry)
+{
+  GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
+  GstPad *that_pad = GST_PAD_PEER (this_pad);
+  GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
+
+  do_query_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
+      qry, ts, res, FALSE);
+}
+
 /* tracer class */
 
 static void
@@ -528,15 +578,40 @@ gst_stats_tracer_class_init (GstStatsTracerClass * klass)
           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */ 
           NULL),
       NULL));
+  gst_tracer_log_trace (gst_structure_new ("elementquery.class",
+      "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
+          "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
+          NULL),
+      "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
+          "type", G_TYPE_GTYPE, G_TYPE_STRING,
+          "description", G_TYPE_STRING, "name of the query",
+          "flags", G_TYPE_STRING, "",  /* TODO: use gflags */ 
+          NULL),
+      NULL));
   gst_tracer_log_trace (gst_structure_new ("query.class",
+      "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
+          "related-to", G_TYPE_STRING, "pad",  /* TODO: use genum */
+          NULL),
       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
           NULL),
+      "peer-pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
+          "related-to", G_TYPE_STRING, "pad",  /* TODO: use genum */
+          NULL),
+      "peer-element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
+          "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
+          NULL),
       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
           "type", G_TYPE_GTYPE, G_TYPE_STRING,
           "description", G_TYPE_STRING, "name of the query",
           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */ 
           NULL),
+      "structure", GST_TYPE_STRUCTURE, gst_structure_new ("value",
+          "type", G_TYPE_GTYPE, GST_TYPE_STRUCTURE,
+          "description", G_TYPE_STRING, "query structure",
+          "flags", G_TYPE_STRING, "",  /* TODO: use gflags */ 
+          NULL),
+      /* TODO(ensonic): "buffer-flags" */
       NULL));
   /* *INDENT-ON* */
 }
@@ -563,5 +638,9 @@ gst_stats_tracer_init (GstStatsTracer * self)
   gst_tracing_register_hook (tracer, "element-post-message-pre",
       G_CALLBACK (do_post_message_pre));
   gst_tracing_register_hook (tracer, "element-query-pre",
+      G_CALLBACK (do_element_query_pre));
+  gst_tracing_register_hook (tracer, "pad-query-pre",
       G_CALLBACK (do_query_pre));
+  gst_tracing_register_hook (tracer, "pad-query-post",
+      G_CALLBACK (do_query_post));
 }