tracing: add hooks when objects or miniobjects are created and destroyed
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 9 May 2016 14:31:36 +0000 (16:31 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 2 Jun 2016 22:10:44 +0000 (23:10 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=765052

gst/gstminiobject.c
gst/gstobject.c
gst/gsttracerutils.c
gst/gsttracerutils.h

index 4812f31..c45f082 100644 (file)
@@ -129,6 +129,7 @@ gst_mini_object_init (GstMiniObject * mini_object, guint flags, GType type,
   mini_object->n_qdata = 0;
   mini_object->qdata = NULL;
 
+  GST_TRACER_MINI_OBJECT_CREATED (mini_object);
 #ifndef GST_DISABLE_TRACE
   _gst_alloc_trace_new (_gst_mini_object_trace, mini_object);
 #endif
@@ -460,6 +461,7 @@ gst_mini_object_unref (GstMiniObject * mini_object)
         call_finalize_notify (mini_object);
         g_free (mini_object->qdata);
       }
+      GST_TRACER_MINI_OBJECT_DESTROYED (mini_object);
 #ifndef GST_DISABLE_TRACE
       _gst_alloc_trace_free (_gst_mini_object_trace, mini_object);
 #endif
index 372f3cf..6090f31 100644 (file)
@@ -154,6 +154,14 @@ static GParamSpec *properties[PROP_LAST];
 G_DEFINE_ABSTRACT_TYPE (GstObject, gst_object, G_TYPE_INITIALLY_UNOWNED);
 
 static void
+gst_object_constructed (GObject * object)
+{
+  GST_TRACER_OBJECT_CREATED (GST_OBJECT_CAST (object));
+
+  ((GObjectClass *) gst_object_parent_class)->constructed (object);
+}
+
+static void
 gst_object_class_init (GstObjectClass * klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
@@ -208,6 +216,7 @@ gst_object_class_init (GstObjectClass * klass)
   gobject_class->dispatch_properties_changed
       = GST_DEBUG_FUNCPTR (gst_object_dispatch_properties_changed);
 
+  gobject_class->constructed = gst_object_constructed;
   gobject_class->dispose = gst_object_dispose;
   gobject_class->finalize = gst_object_finalize;
 }
@@ -415,6 +424,7 @@ gst_object_finalize (GObject * object)
   g_free (gstobject->name);
   g_mutex_clear (&gstobject->lock);
 
+  GST_TRACER_OBJECT_DESTROYED (gstobject);
 #ifndef GST_DISABLE_TRACE
   _gst_alloc_trace_free (_gst_object_trace, object);
 #endif
index 3088b06..85689e5 100644 (file)
@@ -55,7 +55,9 @@ static const gchar *_quark_strings[] = {
   "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"
+  "element-change-state-pre", "element-change-state-post",
+  "mini-object-created", "mini-object-destroyed", "object-created",
+  "object-destroyed",
 };
 
 GQuark _priv_gst_tracer_quark_table[GST_TRACER_QUARK_MAX];
index 64cc14c..e61d66d 100644 (file)
@@ -27,6 +27,7 @@
 #include <glib-object.h>
 #include <gst/gstconfig.h>
 #include <gst/gstbin.h>
+#include <gst/gstutils.h>
 
 G_BEGIN_DECLS
 
@@ -70,6 +71,10 @@ typedef enum /*< skip >*/
   GST_TRACER_QUARK_HOOK_PAD_UNLINK_POST,
   GST_TRACER_QUARK_HOOK_ELEMENT_CHANGE_STATE_PRE,
   GST_TRACER_QUARK_HOOK_ELEMENT_CHANGE_STATE_POST,
+  GST_TRACER_QUARK_HOOK_MINI_OBJECT_CREATED,
+  GST_TRACER_QUARK_HOOK_MINI_OBJECT_DESTROYED,
+  GST_TRACER_QUARK_HOOK_OBJECT_CREATED,
+  GST_TRACER_QUARK_HOOK_OBJECT_DESTROYED,
   GST_TRACER_QUARK_MAX
 } GstTracerQuarkId;
 
@@ -555,6 +560,69 @@ typedef void (*GstTracerHookPadUnlinkPost) (GObject *self, GstClockTime ts,
     GstTracerHookPadUnlinkPost, (GST_TRACER_ARGS, srcpad, sinkpad, result)); \
 }G_STMT_END
 
+/**
+ * GstTracerHookMiniObjectCreated:
+ * @self: the tracer instance
+ * @ts: the current timestamp
+ * @object: the mini object being created
+ *
+ * Hook called when a #GstMiniObject is created named "mini-object-created".
+ */
+typedef void (*GstTracerHookMiniObjectCreated) (GObject *self, GstClockTime ts,
+    GstMiniObject *object);
+#define GST_TRACER_MINI_OBJECT_CREATED(object) G_STMT_START{ \
+  GST_TRACER_DISPATCH(GST_TRACER_QUARK(HOOK_MINI_OBJECT_CREATED), \
+    GstTracerHookMiniObjectCreated, (GST_TRACER_ARGS, object)); \
+}G_STMT_END
+
+/**
+ * GstTracerHookMiniObjectDestroyed:
+ * @self: the tracer instance
+ * @ts: the current timestamp
+ * @object: the mini object being destroyed
+ *
+ * Hook called when a #GstMiniObject is being destroyed named
+ * "mini-object-destroyed".
+ */
+typedef void (*GstTracerHookMiniObjectDestroyed) (GObject *self, GstClockTime ts,
+    GstMiniObject *object);
+#define GST_TRACER_MINI_OBJECT_DESTROYED(object) G_STMT_START{ \
+  GST_TRACER_DISPATCH(GST_TRACER_QUARK(HOOK_MINI_OBJECT_DESTROYED), \
+    GstTracerHookMiniObjectDestroyed, (GST_TRACER_ARGS, object)); \
+}G_STMT_END
+
+/**
+ * GstTracerHookObjectCreated:
+ * @self: the tracer instance
+ * @ts: the current timestamp
+ * @object: the object being created
+ *
+ * Hook called when a #GstObject is created named "object-created".
+ */
+typedef void (*GstTracerHookObjectCreated) (GObject *self, GstClockTime ts,
+    GstObject *object);
+#define GST_TRACER_OBJECT_CREATED(object) G_STMT_START{ \
+  GST_TRACER_DISPATCH(GST_TRACER_QUARK(HOOK_OBJECT_CREATED), \
+    GstTracerHookObjectCreated, (GST_TRACER_ARGS, object)); \
+}G_STMT_END
+
+/**
+ * GstTracerHookObjectDestroyed:
+ * @self: the tracer instance
+ * @ts: the current timestamp
+ * @object: the object being destroyed
+ *
+ * Hook called when a #GstObject is being destroyed named
+ * "object-destroyed".
+ */
+typedef void (*GstTracerHookObjectDestroyed) (GObject *self, GstClockTime ts,
+    GstObject *object);
+#define GST_TRACER_OBJECT_DESTROYED(object) G_STMT_START{ \
+  GST_TRACER_DISPATCH(GST_TRACER_QUARK(HOOK_OBJECT_DESTROYED), \
+    GstTracerHookObjectDestroyed, (GST_TRACER_ARGS, object)); \
+}G_STMT_END
+
+
 #else /* !GST_DISABLE_GST_TRACER_HOOKS */
 
 #define GST_TRACER_PAD_PUSH_PRE(pad, buffer)
@@ -584,6 +652,10 @@ typedef void (*GstTracerHookPadUnlinkPost) (GObject *self, GstClockTime ts,
 #define GST_TRACER_PAD_LINK_POST(srcpad, sinkpad, res)
 #define GST_TRACER_PAD_UNLINK_PRE(srcpad, sinkpad)
 #define GST_TRACER_PAD_UNLINK_POST(srcpad, sinkpad, res)
+#define GST_TRACER_MINI_OBJECT_CREATED(object)
+#define GST_TRACER_MINI_OBJECT_DESTROYED(object)
+#define GST_TRACER_OBJECT_CREATED(object)
+#define GST_TRACER_OBJECT_DESTROYED(object)
 
 #endif /* GST_DISABLE_GST_TRACER_HOOKS */