8b7705b5edbe84474bffa8b05509c618f9baf244
[platform/upstream/gstreamer.git] / plugins / tracers / gststats.c
1 /* GStreamer
2  * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
3  *
4  * gststats.c: tracing module that logs events
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 /**
22  * SECTION:gststats
23  * @short_description: log event stats
24  *
25  * A tracing module that builds usage statistic for elements and pads.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #  include "config.h"
30 #endif
31
32 #include "gststats.h"
33
34 #include <stdio.h>
35
36 GST_DEBUG_CATEGORY_STATIC (gst_stats_debug);
37 #define GST_CAT_DEFAULT gst_stats_debug
38
39 static GQuark data_quark;
40 G_LOCK_DEFINE (_elem_stats);
41 G_LOCK_DEFINE (_pad_stats);
42
43 #define _do_init \
44     GST_DEBUG_CATEGORY_INIT (gst_stats_debug, "stats", 0, "stats tracer"); \
45     data_quark = g_quark_from_static_string ("gststats:data");
46 #define gst_stats_tracer_parent_class parent_class
47 G_DEFINE_TYPE_WITH_CODE (GstStatsTracer, gst_stats_tracer, GST_TYPE_TRACER,
48     _do_init);
49
50 static GstTracerRecord *tr_new_element;
51 static GstTracerRecord *tr_new_pad;
52 static GstTracerRecord *tr_buffer;
53 static GstTracerRecord *tr_element_query;
54 static GstTracerRecord *tr_event;
55 static GstTracerRecord *tr_message;
56 static GstTracerRecord *tr_query;
57
58 typedef struct
59 {
60   /* we can't rely on the address to be unique over time */
61   guint index;
62   /* for pre + post */
63   GstClockTime last_ts;
64   /* hierarchy */
65   guint parent_ix;
66 } GstPadStats;
67
68 typedef struct
69 {
70   /* we can't rely on the address to be unique over time */
71   guint index;
72   /* for pre + post */
73   GstClockTime last_ts;
74   /* time spend in this element */
75   GstClockTime treal;
76   /* hierarchy */
77   guint parent_ix;
78 } GstElementStats;
79
80 /* data helper */
81
82 static GstElementStats no_elem_stats = { 0, };
83
84 static GstElementStats *
85 fill_element_stats (GstStatsTracer * self, GstElement * element)
86 {
87   GstElementStats *stats = g_slice_new0 (GstElementStats);
88
89   stats->index = self->num_elements++;
90   stats->parent_ix = G_MAXUINT;
91   return stats;
92 }
93
94 static void
95 log_new_element_stats (GstElementStats * stats, GstElement * element,
96     GstClockTime elapsed)
97 {
98   gst_tracer_record_log (tr_new_element, (guint64) (guintptr) g_thread_self (),
99       elapsed, stats->index, stats->parent_ix, GST_OBJECT_NAME (element),
100       G_OBJECT_TYPE_NAME (element), GST_IS_BIN (element));
101 }
102
103 static void
104 free_element_stats (gpointer data)
105 {
106   g_slice_free (GstElementStats, data);
107 }
108
109 static GstElementStats *
110 create_element_stats (GstStatsTracer * self, GstElement * element)
111 {
112   GstElementStats *stats;
113
114   stats = fill_element_stats (self, element);
115   g_object_set_qdata_full ((GObject *) element, data_quark, stats,
116       free_element_stats);
117
118   return stats;
119 }
120
121 static inline GstElementStats *
122 get_element_stats (GstStatsTracer * self, GstElement * element)
123 {
124   GstElementStats *stats;
125   gboolean is_new = FALSE;
126
127   if (!element) {
128     no_elem_stats.index = G_MAXUINT;
129     return &no_elem_stats;
130   }
131
132   G_LOCK (_elem_stats);
133   if (!(stats = g_object_get_qdata ((GObject *) element, data_quark))) {
134     stats = create_element_stats (self, element);
135     is_new = TRUE;
136   }
137   G_UNLOCK (_elem_stats);
138   if (G_UNLIKELY (stats->parent_ix == G_MAXUINT)) {
139     GstElement *parent = GST_ELEMENT_PARENT (element);
140     if (parent) {
141       GstElementStats *parent_stats = get_element_stats (self, parent);
142       stats->parent_ix = parent_stats->index;
143     }
144   }
145   if (G_UNLIKELY (is_new)) {
146     log_new_element_stats (stats, element, GST_CLOCK_TIME_NONE);
147   }
148   return stats;
149 }
150
151 /*
152  * Get the element/bin owning the pad.
153  *
154  * in: a normal pad
155  * out: the element
156  *
157  * in: a proxy pad
158  * out: the element that contains the peer of the proxy
159  *
160  * in: a ghost pad
161  * out: the bin owning the ghostpad
162  */
163 /* TODO(ensonic): gst_pad_get_parent_element() would not work here, should we
164  * add this as new api, e.g. gst_pad_find_parent_element();
165  */
166 static GstElement *
167 get_real_pad_parent (GstPad * pad)
168 {
169   GstObject *parent;
170
171   if (!pad)
172     return NULL;
173
174   parent = GST_OBJECT_PARENT (pad);
175
176   /* if parent of pad is a ghost-pad, then pad is a proxy_pad */
177   if (parent && GST_IS_GHOST_PAD (parent)) {
178     pad = GST_PAD_CAST (parent);
179     parent = GST_OBJECT_PARENT (pad);
180   }
181   return GST_ELEMENT_CAST (parent);
182 }
183
184 static GstPadStats no_pad_stats = { 0, };
185
186 static GstPadStats *
187 fill_pad_stats (GstStatsTracer * self, GstPad * pad)
188 {
189   GstPadStats *stats = g_slice_new0 (GstPadStats);
190
191   stats->index = self->num_pads++;
192   stats->parent_ix = G_MAXUINT;
193
194   return stats;
195 }
196
197 static void
198 log_new_pad_stats (GstPadStats * stats, GstPad * pad)
199 {
200   gst_tracer_record_log (tr_new_pad, (guint64) (guintptr) g_thread_self (),
201       stats->index, stats->parent_ix, GST_OBJECT_NAME (pad),
202       G_OBJECT_TYPE_NAME (pad), GST_IS_GHOST_PAD (pad),
203       GST_PAD_DIRECTION (pad));
204 }
205
206 static void
207 free_pad_stats (gpointer data)
208 {
209   g_slice_free (GstPadStats, data);
210 }
211
212 static GstPadStats *
213 get_pad_stats (GstStatsTracer * self, GstPad * pad)
214 {
215   GstPadStats *stats;
216   gboolean is_new = FALSE;
217
218   if (!pad) {
219     no_pad_stats.index = G_MAXUINT;
220     return &no_pad_stats;
221   }
222
223   G_LOCK (_pad_stats);
224   if (!(stats = g_object_get_qdata ((GObject *) pad, data_quark))) {
225     stats = fill_pad_stats (self, pad);
226     g_object_set_qdata_full ((GObject *) pad, data_quark, stats,
227         free_pad_stats);
228     is_new = TRUE;
229   }
230   G_UNLOCK (_pad_stats);
231   if (G_UNLIKELY (stats->parent_ix == G_MAXUINT)) {
232     GstElement *elem = get_real_pad_parent (pad);
233     if (elem) {
234       GstElementStats *elem_stats = get_element_stats (self, elem);
235
236       stats->parent_ix = elem_stats->index;
237     }
238   }
239   if (G_UNLIKELY (is_new)) {
240     log_new_pad_stats (stats, pad);
241   }
242   return stats;
243 }
244
245 static void
246 do_buffer_stats (GstStatsTracer * self, GstPad * this_pad,
247     GstPadStats * this_pad_stats, GstPad * that_pad,
248     GstPadStats * that_pad_stats, GstBuffer * buf, GstClockTime elapsed)
249 {
250   GstElement *this_elem = get_real_pad_parent (this_pad);
251   GstElementStats *this_elem_stats = get_element_stats (self, this_elem);
252   GstElement *that_elem = get_real_pad_parent (that_pad);
253   GstElementStats *that_elem_stats = get_element_stats (self, that_elem);
254
255   gst_tracer_record_log (tr_buffer, (guint64) (guintptr) g_thread_self (),
256       elapsed, this_pad_stats->index, this_elem_stats->index,
257       that_pad_stats->index, that_elem_stats->index, gst_buffer_get_size (buf),
258       GST_BUFFER_PTS (buf), GST_BUFFER_DTS (buf), GST_BUFFER_DURATION (buf),
259       GST_BUFFER_FLAGS (buf));
260 }
261
262 static void
263 do_query_stats (GstStatsTracer * self, GstPad * this_pad,
264     GstPadStats * this_pad_stats, GstPad * that_pad,
265     GstPadStats * that_pad_stats, GstQuery * qry, GstClockTime elapsed,
266     gboolean have_res, gboolean res)
267 {
268   GstElement *this_elem = get_real_pad_parent (this_pad);
269   GstElementStats *this_elem_stats = get_element_stats (self, this_elem);
270   GstElement *that_elem = get_real_pad_parent (that_pad);
271   GstElementStats *that_elem_stats = get_element_stats (self, that_elem);
272
273   gst_tracer_record_log (tr_query, (guint64) (guintptr) g_thread_self (),
274       elapsed, this_pad_stats->index, this_elem_stats->index,
275       that_pad_stats->index, that_elem_stats->index, GST_QUERY_TYPE_NAME (qry),
276       gst_query_get_structure (qry), have_res, res);
277 }
278
279 static void
280 do_element_stats (GstStatsTracer * self, GstPad * pad, GstClockTime elapsed1,
281     GstClockTime elapsed2)
282 {
283   GstClockTimeDiff elapsed = GST_CLOCK_DIFF (elapsed1, elapsed2);
284   GstObject *parent = GST_OBJECT_PARENT (pad);
285   GstElement *this =
286       GST_ELEMENT_CAST (GST_IS_PAD (parent) ? GST_OBJECT_PARENT (parent) :
287       parent);
288   GstElementStats *this_stats = get_element_stats (self, this);
289   GstPad *peer_pad = GST_PAD_PEER (pad);
290   GstElementStats *peer_stats;
291
292   if (!peer_pad)
293     return;
294
295   /* walk the ghost pad chain downstream to get the real pad */
296   /* if parent of peer_pad is a ghost-pad, then peer_pad is a proxy_pad */
297   parent = GST_OBJECT_PARENT (peer_pad);
298   if (parent && GST_IS_GHOST_PAD (parent)) {
299     peer_pad = GST_PAD_CAST (parent);
300     /* if this is now the ghost pad, get the peer of this */
301     get_pad_stats (self, peer_pad);
302     if ((parent = GST_OBJECT_PARENT (peer_pad))) {
303       get_element_stats (self, GST_ELEMENT_CAST (parent));
304     }
305     peer_pad = GST_PAD_PEER (GST_GHOST_PAD_CAST (peer_pad));
306     parent = peer_pad ? GST_OBJECT_PARENT (peer_pad) : NULL;
307   }
308   /* walk the ghost pad chain upstream to get the real pad */
309   /* if peer_pad is a ghost-pad, then parent is a bin and it is the parent of
310    * a proxy_pad */
311   while (peer_pad && GST_IS_GHOST_PAD (peer_pad)) {
312     get_pad_stats (self, peer_pad);
313     get_element_stats (self, GST_ELEMENT_CAST (parent));
314     peer_pad = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (peer_pad));
315     parent = peer_pad ? GST_OBJECT_PARENT (peer_pad) : NULL;
316   }
317
318   if (!parent) {
319     printf ("%" GST_TIME_FORMAT
320         " transmission on unparented target pad %s_%s -> %s_%s\n",
321         GST_TIME_ARGS (elapsed), GST_DEBUG_PAD_NAME (pad),
322         GST_DEBUG_PAD_NAME (peer_pad));
323     return;
324   }
325   peer_stats = get_element_stats (self, GST_ELEMENT_CAST (parent));
326
327   /* we'd like to gather time spend in each element, but this does not make too
328    * much sense yet
329    * pure push/pull-based:
330    *   - the time spend in the push/pull_range is accounted for the peer and
331    *     removed from the current element
332    *   - this works for chains
333    *   - drawback is sink elements that block to sync have a high time usage
334    *     - we could rerun the ests with sync=false
335    * both:
336    *   - a.g. demuxers both push and pull. thus we subtract time for the pull
337    *     and the push operations, but never add anything.
338    *   - can we start a counter after push/pull in such elements and add then
339    *     time to the element upon next pad activity?
340    */
341 #if 1
342   /* this does not make sense for demuxers */
343   this_stats->treal -= elapsed;
344   peer_stats->treal += elapsed;
345 #else
346   /* this creates several >100% figures */
347   this_stats->treal += GST_CLOCK_DIFF (this_stats->last_ts, elapsed2) - elapsed;
348   peer_stats->treal += elapsed;
349   this_stats->last_ts = elapsed2;
350   peer_stats->last_ts = elapsed2;
351 #endif
352 }
353
354 /* hooks */
355
356 static void
357 do_push_buffer_pre (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
358     GstBuffer * buffer)
359 {
360   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
361   GstPad *that_pad = GST_PAD_PEER (this_pad);
362   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
363
364   do_buffer_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
365       buffer, ts);
366 }
367
368 static void
369 do_push_buffer_post (GstStatsTracer * self, guint64 ts, GstPad * pad,
370     GstFlowReturn res)
371 {
372   GstPadStats *stats = get_pad_stats (self, pad);
373
374   do_element_stats (self, pad, stats->last_ts, ts);
375 }
376
377 typedef struct
378 {
379   GstStatsTracer *self;
380   GstPad *this_pad;
381   GstPadStats *this_pad_stats;
382   GstPad *that_pad;
383   GstPadStats *that_pad_stats;
384   guint64 ts;
385 } DoPushBufferListArgs;
386
387 static gboolean
388 do_push_buffer_list_item (GstBuffer ** buffer, guint idx, gpointer user_data)
389 {
390   DoPushBufferListArgs *args = (DoPushBufferListArgs *) user_data;
391
392   do_buffer_stats (args->self, args->this_pad, args->this_pad_stats,
393       args->that_pad, args->that_pad_stats, *buffer, args->ts);
394   return TRUE;
395 }
396
397 static void
398 do_push_buffer_list_pre (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
399     GstBufferList * list)
400 {
401   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
402   GstPad *that_pad = GST_PAD_PEER (this_pad);
403   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
404   DoPushBufferListArgs args = { self, this_pad, this_pad_stats, that_pad,
405     that_pad_stats, ts
406   };
407
408   gst_buffer_list_foreach (list, do_push_buffer_list_item, &args);
409 }
410
411 static void
412 do_push_buffer_list_post (GstStatsTracer * self, guint64 ts, GstPad * pad,
413     GstFlowReturn res)
414 {
415   GstPadStats *stats = get_pad_stats (self, pad);
416
417   do_element_stats (self, pad, stats->last_ts, ts);
418 }
419
420 static void
421 do_pull_range_pre (GstStatsTracer * self, guint64 ts, GstPad * pad)
422 {
423   GstPadStats *stats = get_pad_stats (self, pad);
424   stats->last_ts = ts;
425 }
426
427 static void
428 do_pull_range_post (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
429     GstBuffer * buffer)
430 {
431   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
432   guint64 last_ts = this_pad_stats->last_ts;
433   GstPad *that_pad = GST_PAD_PEER (this_pad);
434   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
435
436   if (buffer != NULL) {
437     do_buffer_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
438         buffer, ts);
439   }
440   do_element_stats (self, this_pad, last_ts, ts);
441 }
442
443 static void
444 do_push_event_pre (GstStatsTracer * self, guint64 ts, GstPad * pad,
445     GstEvent * ev)
446 {
447   GstElement *elem = get_real_pad_parent (pad);
448   GstElementStats *elem_stats = get_element_stats (self, elem);
449   GstPadStats *pad_stats = get_pad_stats (self, pad);
450
451   elem_stats->last_ts = ts;
452   gst_tracer_record_log (tr_event, (guint64) (guintptr) g_thread_self (), ts,
453       pad_stats->index, elem_stats->index, GST_EVENT_TYPE_NAME (ev));
454 }
455
456 static void
457 do_post_message_pre (GstStatsTracer * self, guint64 ts, GstElement * elem,
458     GstMessage * msg)
459 {
460   GstElementStats *stats = get_element_stats (self, elem);
461   const GstStructure *msg_s = gst_message_get_structure (msg);
462   GstStructure *s =
463       msg_s ? (GstStructure *) msg_s : gst_structure_new_empty ("dummy");
464
465   stats->last_ts = ts;
466   /* FIXME: work out whether using NULL instead of a dummy struct would work */
467   gst_tracer_record_log (tr_message, (guint64) (guintptr) g_thread_self (), ts,
468       stats->index, GST_MESSAGE_TYPE_NAME (msg), s);
469   if (s != msg_s)
470     gst_structure_free (s);
471 }
472
473 static void
474 do_element_new (GstStatsTracer * self, guint64 ts, GstElement * elem)
475 {
476   GstElementStats *stats;
477
478   stats = create_element_stats (self, elem);
479   log_new_element_stats (stats, elem, ts);
480 }
481
482 static void
483 do_element_query_pre (GstStatsTracer * self, guint64 ts, GstElement * elem,
484     GstQuery * qry)
485 {
486   GstElementStats *stats = get_element_stats (self, elem);
487
488   stats->last_ts = ts;
489   gst_tracer_record_log (tr_element_query,
490       (guint64) (guintptr) g_thread_self (), ts, stats->index,
491       GST_QUERY_TYPE_NAME (qry));
492 }
493
494 static void
495 do_query_pre (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
496     GstQuery * qry)
497 {
498   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
499   GstPad *that_pad = GST_PAD_PEER (this_pad);
500   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
501
502   do_query_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
503       qry, ts, FALSE, FALSE);
504 }
505
506 static void
507 do_query_post (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
508     GstQuery * qry, gboolean res)
509 {
510   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
511   GstPad *that_pad = GST_PAD_PEER (this_pad);
512   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
513
514   do_query_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
515       qry, ts, TRUE, res);
516 }
517
518 /* tracer class */
519
520 static void
521 gst_stats_tracer_class_init (GstStatsTracerClass * klass)
522 {
523   /* announce trace formats */
524   /* *INDENT-OFF* */
525   tr_buffer = gst_tracer_record_new ("buffer.class",
526       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
527           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
528           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
529           NULL),
530       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
531           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
532           "description", G_TYPE_STRING, "event ts",
533           NULL),
534       "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
535           "type", G_TYPE_GTYPE, G_TYPE_UINT,
536           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
537           NULL),
538       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
539           "type", G_TYPE_GTYPE, G_TYPE_UINT,
540           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
541           NULL),
542       "peer-pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
543           "type", G_TYPE_GTYPE, G_TYPE_UINT,
544           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
545           NULL),
546       "peer-element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
547           "type", G_TYPE_GTYPE, G_TYPE_UINT,
548           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
549           NULL),
550       "buffer-size", GST_TYPE_STRUCTURE, gst_structure_new ("value",
551           "type", G_TYPE_GTYPE, G_TYPE_UINT,
552           "description", G_TYPE_STRING, "size of buffer in bytes",
553           "min", G_TYPE_UINT, 0,
554           "max", G_TYPE_UINT, G_MAXUINT,
555           NULL),
556       "buffer-pts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
557           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
558           "description", G_TYPE_STRING, "presentation timestamp of the buffer in ns",
559           "min", G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
560           "max", G_TYPE_UINT64, G_MAXUINT64,
561           NULL),
562       "buffer-dts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
563           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
564           "description", G_TYPE_STRING, "decoding timestamp of the buffer in ns",
565           "min", G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
566           "max", G_TYPE_UINT64, G_MAXUINT64,
567           NULL),
568       "buffer-duration", GST_TYPE_STRUCTURE, gst_structure_new ("value",
569           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
570           "description", G_TYPE_STRING, "duration of the buffer in ns",
571           "min", G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
572           "max", G_TYPE_UINT64, G_MAXUINT64,
573           NULL),
574       "buffer-flags", GST_TYPE_STRUCTURE, gst_structure_new ("value",
575           "type", G_TYPE_GTYPE, GST_TYPE_BUFFER_FLAGS,
576           "description", G_TYPE_STRING, "flags of the buffer",
577           NULL),
578       NULL);
579   tr_event = gst_tracer_record_new ("event.class",
580       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
581           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
582           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
583           NULL),
584       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
585           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
586           "description", G_TYPE_STRING, "event ts",
587           NULL),
588       "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
589           "type", G_TYPE_GTYPE, G_TYPE_UINT,
590           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
591           NULL),
592       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
593           "type", G_TYPE_GTYPE, G_TYPE_UINT,
594           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
595           NULL),
596       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
597           "type", G_TYPE_GTYPE, G_TYPE_STRING,
598           "description", G_TYPE_STRING, "name of the event",
599           NULL),
600       NULL);
601   tr_message = gst_tracer_record_new ("message.class",
602       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
603           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
604           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
605           NULL),
606       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
607           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
608           "description", G_TYPE_STRING, "event ts",
609           NULL),
610       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
611           "type", G_TYPE_GTYPE, G_TYPE_UINT,
612           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
613           NULL),
614       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
615           "type", G_TYPE_GTYPE, G_TYPE_STRING,
616           "description", G_TYPE_STRING, "name of the message",
617           NULL),
618       "structure", GST_TYPE_STRUCTURE, gst_structure_new ("structure",
619           "type", G_TYPE_GTYPE, GST_TYPE_STRUCTURE,
620           "description", G_TYPE_STRING, "message structure",
621           NULL),
622       NULL);
623   tr_element_query = gst_tracer_record_new ("element-query.class",
624       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
625           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
626           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
627           NULL),
628       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
629           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
630           "description", G_TYPE_STRING, "event ts",
631           NULL),
632       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
633           "type", G_TYPE_GTYPE, G_TYPE_UINT,
634           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
635           NULL),
636       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
637           "type", G_TYPE_GTYPE, G_TYPE_STRING,
638           "description", G_TYPE_STRING, "name of the query",
639           NULL),
640       NULL);
641   tr_query = gst_tracer_record_new ("query.class",
642       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
643           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
644           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
645           NULL),
646       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
647           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
648           "description", G_TYPE_STRING, "event ts",
649           NULL),
650       "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
651           "type", G_TYPE_GTYPE, G_TYPE_UINT,
652           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
653           NULL),
654       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
655           "type", G_TYPE_GTYPE, G_TYPE_UINT,
656           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
657           NULL),
658       "peer-pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
659           "type", G_TYPE_GTYPE, G_TYPE_UINT,
660           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
661           NULL),
662       "peer-element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
663           "type", G_TYPE_GTYPE, G_TYPE_UINT,
664           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
665           NULL),
666       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
667           "type", G_TYPE_GTYPE, G_TYPE_STRING,
668           "description", G_TYPE_STRING, "name of the query",
669           NULL),
670       "structure", GST_TYPE_STRUCTURE, gst_structure_new ("value",
671           "type", G_TYPE_GTYPE, GST_TYPE_STRUCTURE,
672           "description", G_TYPE_STRING, "query structure",
673           NULL),
674       "res", GST_TYPE_STRUCTURE, gst_structure_new ("value",
675           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
676           "description", G_TYPE_STRING, "query result",
677           "flags", GST_TYPE_TRACER_VALUE_FLAGS, GST_TRACER_VALUE_FLAGS_OPTIONAL,
678           NULL),
679       NULL);
680   tr_new_element = gst_tracer_record_new ("new-element.class",
681       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
682           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
683           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
684           NULL),
685       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
686           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
687           "description", G_TYPE_STRING, "event ts",
688           NULL),
689       "ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
690           "type", G_TYPE_GTYPE, G_TYPE_UINT,
691           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
692           NULL),
693       "parent-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
694           "type", G_TYPE_GTYPE, G_TYPE_UINT,
695           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
696           NULL),
697       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
698           "type", G_TYPE_GTYPE, G_TYPE_STRING,
699           "description", G_TYPE_STRING, "name of the element",
700           NULL),
701       "type", GST_TYPE_STRUCTURE, gst_structure_new ("value",
702           "type", G_TYPE_GTYPE, G_TYPE_STRING,
703           "description", G_TYPE_STRING, "type name of the element",
704           NULL),
705       "is-bin", GST_TYPE_STRUCTURE, gst_structure_new ("value",
706           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
707           "description", G_TYPE_STRING, "is element a bin",
708           NULL),
709       NULL);
710   tr_new_pad = gst_tracer_record_new ("new-pad.class",
711       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
712           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
713           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
714           NULL),
715       "ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
716           "type", G_TYPE_GTYPE, G_TYPE_UINT,
717           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
718           NULL),
719       "parent-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
720           "type", G_TYPE_GTYPE, G_TYPE_UINT,
721           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
722           NULL),
723       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
724           "type", G_TYPE_GTYPE, G_TYPE_STRING,
725           "description", G_TYPE_STRING, "name of the pad",
726           NULL),
727       "type", GST_TYPE_STRUCTURE, gst_structure_new ("value",
728           "type", G_TYPE_GTYPE, G_TYPE_STRING,
729           "description", G_TYPE_STRING, "type name of the pad",
730           NULL),
731       "is-ghostpad", GST_TYPE_STRUCTURE, gst_structure_new ("value",
732           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
733           "description", G_TYPE_STRING, "is pad a ghostpad",
734           NULL),
735       "pad-direction", GST_TYPE_STRUCTURE, gst_structure_new ("value",
736           "type", G_TYPE_GTYPE, GST_TYPE_PAD_DIRECTION,
737           "description", G_TYPE_STRING, "ipad direction",
738           NULL),
739       NULL);
740   /* *INDENT-ON* */
741 }
742
743 static void
744 gst_stats_tracer_init (GstStatsTracer * self)
745 {
746   GstTracer *tracer = GST_TRACER (self);
747
748   gst_tracing_register_hook (tracer, "pad-push-pre",
749       G_CALLBACK (do_push_buffer_pre));
750   gst_tracing_register_hook (tracer, "pad-push-post",
751       G_CALLBACK (do_push_buffer_post));
752   gst_tracing_register_hook (tracer, "pad-push-list-pre",
753       G_CALLBACK (do_push_buffer_list_pre));
754   gst_tracing_register_hook (tracer, "pad-push-list-post",
755       G_CALLBACK (do_push_buffer_list_post));
756   gst_tracing_register_hook (tracer, "pad-pull-range-pre",
757       G_CALLBACK (do_pull_range_pre));
758   gst_tracing_register_hook (tracer, "pad-pull-range-post",
759       G_CALLBACK (do_pull_range_post));
760   gst_tracing_register_hook (tracer, "pad-push-event-pre",
761       G_CALLBACK (do_push_event_pre));
762   gst_tracing_register_hook (tracer, "element-new",
763       G_CALLBACK (do_element_new));
764   gst_tracing_register_hook (tracer, "element-post-message-pre",
765       G_CALLBACK (do_post_message_pre));
766   gst_tracing_register_hook (tracer, "element-query-pre",
767       G_CALLBACK (do_element_query_pre));
768   gst_tracing_register_hook (tracer, "pad-query-pre",
769       G_CALLBACK (do_query_pre));
770   gst_tracing_register_hook (tracer, "pad-query-post",
771       G_CALLBACK (do_query_post));
772 }