tracer: add a GstTracerValueFlags and replace strings
[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) 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_element, (guint64) 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) g_thread_self (), elapsed,
256       this_pad_stats->index, this_elem_stats->index, that_pad_stats->index,
257       that_elem_stats->index, gst_buffer_get_size (buf), GST_BUFFER_PTS (buf),
258       GST_BUFFER_DTS (buf), GST_BUFFER_DURATION (buf), GST_BUFFER_FLAGS (buf));
259 }
260
261 static void
262 do_query_stats (GstStatsTracer * self, GstPad * this_pad,
263     GstPadStats * this_pad_stats, GstPad * that_pad,
264     GstPadStats * that_pad_stats, GstQuery * qry, GstClockTime elapsed,
265     gboolean have_res, gboolean res)
266 {
267   GstElement *this_elem = get_real_pad_parent (this_pad);
268   GstElementStats *this_elem_stats = get_element_stats (self, this_elem);
269   GstElement *that_elem = get_real_pad_parent (that_pad);
270   GstElementStats *that_elem_stats = get_element_stats (self, that_elem);
271
272   gst_tracer_record_log (tr_query, (guint64) g_thread_self (), elapsed,
273       this_pad_stats->index, this_elem_stats->index, that_pad_stats->index,
274       that_elem_stats->index, GST_QUERY_TYPE_NAME (qry),
275       gst_query_get_structure (qry), have_res, res);
276 }
277
278 static void
279 do_element_stats (GstStatsTracer * self, GstPad * pad, GstClockTime elapsed1,
280     GstClockTime elapsed2)
281 {
282   GstClockTimeDiff elapsed = GST_CLOCK_DIFF (elapsed1, elapsed2);
283   GstObject *parent = GST_OBJECT_PARENT (pad);
284   GstElement *this =
285       GST_ELEMENT_CAST (GST_IS_PAD (parent) ? GST_OBJECT_PARENT (parent) :
286       parent);
287   GstElementStats *this_stats = get_element_stats (self, this);
288   GstPad *peer_pad = GST_PAD_PEER (pad);
289   GstElementStats *peer_stats;
290
291   if (!peer_pad)
292     return;
293
294   /* walk the ghost pad chain downstream to get the real pad */
295   /* if parent of peer_pad is a ghost-pad, then peer_pad is a proxy_pad */
296   parent = GST_OBJECT_PARENT (peer_pad);
297   if (parent && GST_IS_GHOST_PAD (parent)) {
298     peer_pad = GST_PAD_CAST (parent);
299     /* if this is now the ghost pad, get the peer of this */
300     get_pad_stats (self, peer_pad);
301     if ((parent = GST_OBJECT_PARENT (peer_pad))) {
302       get_element_stats (self, GST_ELEMENT_CAST (parent));
303     }
304     peer_pad = GST_PAD_PEER (GST_GHOST_PAD_CAST (peer_pad));
305     parent = peer_pad ? GST_OBJECT_PARENT (peer_pad) : NULL;
306   }
307   /* walk the ghost pad chain upstream to get the real pad */
308   /* if peer_pad is a ghost-pad, then parent is a bin and it is the parent of
309    * a proxy_pad */
310   while (peer_pad && GST_IS_GHOST_PAD (peer_pad)) {
311     get_pad_stats (self, peer_pad);
312     get_element_stats (self, GST_ELEMENT_CAST (parent));
313     peer_pad = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (peer_pad));
314     parent = peer_pad ? GST_OBJECT_PARENT (peer_pad) : NULL;
315   }
316
317   if (!parent) {
318     printf ("%" GST_TIME_FORMAT
319         " transmission on unparented target pad %s_%s -> %s_%s\n",
320         GST_TIME_ARGS (elapsed), GST_DEBUG_PAD_NAME (pad),
321         GST_DEBUG_PAD_NAME (peer_pad));
322     return;
323   }
324   peer_stats = get_element_stats (self, GST_ELEMENT_CAST (parent));
325
326   /* we'd like to gather time spend in each element, but this does not make too
327    * much sense yet
328    * pure push/pull-based:
329    *   - the time spend in the push/pull_range is accounted for the peer and
330    *     removed from the current element
331    *   - this works for chains
332    *   - drawback is sink elements that block to sync have a high time usage
333    *     - we could rerun the ests with sync=false
334    * both:
335    *   - a.g. demuxers both push and pull. thus we subtract time for the pull
336    *     and the push operations, but never add anything.
337    *   - can we start a counter after push/pull in such elements and add then
338    *     time to the element upon next pad activity?
339    */
340 #if 1
341   /* this does not make sense for demuxers */
342   this_stats->treal -= elapsed;
343   peer_stats->treal += elapsed;
344 #else
345   /* this creates several >100% figures */
346   this_stats->treal += GST_CLOCK_DIFF (this_stats->last_ts, elapsed2) - elapsed;
347   peer_stats->treal += elapsed;
348   this_stats->last_ts = elapsed2;
349   peer_stats->last_ts = elapsed2;
350 #endif
351 }
352
353 /* hooks */
354
355 static void
356 do_push_buffer_pre (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
357     GstBuffer * buffer)
358 {
359   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
360   GstPad *that_pad = GST_PAD_PEER (this_pad);
361   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
362
363   do_buffer_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
364       buffer, ts);
365 }
366
367 static void
368 do_push_buffer_post (GstStatsTracer * self, guint64 ts, GstPad * pad,
369     GstFlowReturn res)
370 {
371   GstPadStats *stats = get_pad_stats (self, pad);
372
373   do_element_stats (self, pad, stats->last_ts, ts);
374 }
375
376 typedef struct
377 {
378   GstStatsTracer *self;
379   GstPad *this_pad;
380   GstPadStats *this_pad_stats;
381   GstPad *that_pad;
382   GstPadStats *that_pad_stats;
383   guint64 ts;
384 } DoPushBufferListArgs;
385
386 static gboolean
387 do_push_buffer_list_item (GstBuffer ** buffer, guint idx, gpointer user_data)
388 {
389   DoPushBufferListArgs *args = (DoPushBufferListArgs *) user_data;
390
391   do_buffer_stats (args->self, args->this_pad, args->this_pad_stats,
392       args->that_pad, args->that_pad_stats, *buffer, args->ts);
393   return TRUE;
394 }
395
396 static void
397 do_push_buffer_list_pre (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
398     GstBufferList * list)
399 {
400   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
401   GstPad *that_pad = GST_PAD_PEER (this_pad);
402   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
403   DoPushBufferListArgs args = { self, this_pad, this_pad_stats, that_pad,
404     that_pad_stats, ts
405   };
406
407   gst_buffer_list_foreach (list, do_push_buffer_list_item, &args);
408 }
409
410 static void
411 do_push_buffer_list_post (GstStatsTracer * self, guint64 ts, GstPad * pad,
412     GstFlowReturn res)
413 {
414   GstPadStats *stats = get_pad_stats (self, pad);
415
416   do_element_stats (self, pad, stats->last_ts, ts);
417 }
418
419 static void
420 do_pull_range_pre (GstStatsTracer * self, guint64 ts, GstPad * pad)
421 {
422   GstPadStats *stats = get_pad_stats (self, pad);
423   stats->last_ts = ts;
424 }
425
426 static void
427 do_pull_range_post (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
428     GstBuffer * buffer)
429 {
430   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
431   guint64 last_ts = this_pad_stats->last_ts;
432   GstPad *that_pad = GST_PAD_PEER (this_pad);
433   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
434
435   if (buffer != NULL) {
436     do_buffer_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
437         buffer, ts);
438   }
439   do_element_stats (self, this_pad, last_ts, ts);
440 }
441
442 static void
443 do_push_event_pre (GstStatsTracer * self, guint64 ts, GstPad * pad,
444     GstEvent * ev)
445 {
446   GstElement *elem = get_real_pad_parent (pad);
447   GstElementStats *elem_stats = get_element_stats (self, elem);
448   GstPadStats *pad_stats = get_pad_stats (self, pad);
449
450   elem_stats->last_ts = ts;
451   gst_tracer_record_log (tr_event, (guint64) g_thread_self (), ts,
452       pad_stats->index, elem_stats->index, GST_EVENT_TYPE_NAME (ev));
453 }
454
455 static void
456 do_post_message_pre (GstStatsTracer * self, guint64 ts, GstElement * elem,
457     GstMessage * msg)
458 {
459   GstElementStats *stats = get_element_stats (self, elem);
460   const GstStructure *msg_s = gst_message_get_structure (msg);
461
462   stats->last_ts = ts;
463   gst_tracer_record_log (tr_message, (guint64) g_thread_self (), ts,
464       stats->index, GST_MESSAGE_TYPE_NAME (msg),
465       (msg_s ? msg_s : gst_structure_new_empty ("dummy")));
466 }
467
468 static void
469 do_element_new (GstStatsTracer * self, guint64 ts, GstElement * elem)
470 {
471   GstElementStats *stats;
472
473   stats = create_element_stats (self, elem);
474   log_new_element_stats (stats, elem, ts);
475 }
476
477 static void
478 do_element_query_pre (GstStatsTracer * self, guint64 ts, GstElement * elem,
479     GstQuery * qry)
480 {
481   GstElementStats *stats = get_element_stats (self, elem);
482
483   stats->last_ts = ts;
484   gst_tracer_record_log (tr_element_query, (guint64) g_thread_self (), ts,
485       stats->index, GST_QUERY_TYPE_NAME (qry));
486 }
487
488 static void
489 do_query_pre (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
490     GstQuery * qry)
491 {
492   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
493   GstPad *that_pad = GST_PAD_PEER (this_pad);
494   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
495
496   do_query_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
497       qry, ts, FALSE, FALSE);
498 }
499
500 static void
501 do_query_post (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
502     GstQuery * qry, gboolean res)
503 {
504   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
505   GstPad *that_pad = GST_PAD_PEER (this_pad);
506   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
507
508   do_query_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
509       qry, ts, TRUE, res);
510 }
511
512 /* tracer class */
513
514 static void
515 gst_stats_tracer_class_init (GstStatsTracerClass * klass)
516 {
517   /* announce trace formats */
518   /* *INDENT-OFF* */
519   tr_buffer = gst_tracer_record_new (gst_structure_new ("buffer.class",
520       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
521           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
522           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
523           NULL),
524       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
525           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
526           "description", G_TYPE_STRING, "event ts",
527           NULL),
528       "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
529           "type", G_TYPE_GTYPE, G_TYPE_UINT,
530           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
531           NULL),
532       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
533           "type", G_TYPE_GTYPE, G_TYPE_UINT,
534           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
535           NULL),
536       "peer-pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
537           "type", G_TYPE_GTYPE, G_TYPE_UINT,
538           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
539           NULL),
540       "peer-element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
541           "type", G_TYPE_GTYPE, G_TYPE_UINT,
542           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
543           NULL),
544       "buffer-size", GST_TYPE_STRUCTURE, gst_structure_new ("value",
545           "type", G_TYPE_GTYPE, G_TYPE_UINT,
546           "description", G_TYPE_STRING, "size of buffer in bytes",
547           "min", G_TYPE_UINT, 0,
548           "max", G_TYPE_UINT, G_MAXUINT,
549           NULL),
550       "buffer-ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
551           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
552           "description", G_TYPE_STRING, "timestamp of the buffer in ns",
553           "min", G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
554           "max", G_TYPE_UINT64, G_MAXUINT64,
555           NULL),
556       "buffer-duration", GST_TYPE_STRUCTURE, gst_structure_new ("value",
557           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
558           "description", G_TYPE_STRING, "duration of the buffer in ns",
559           "min", G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
560           "max", G_TYPE_UINT64, G_MAXUINT64,
561           NULL),
562       /* TODO(ensonic): "buffer-flags" */
563       NULL));
564   tr_event = gst_tracer_record_new (gst_structure_new ("event.class",
565       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
566           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
567           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
568           NULL),
569       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
570           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
571           "description", G_TYPE_STRING, "event ts",
572           NULL),
573       "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
574           "type", G_TYPE_GTYPE, G_TYPE_UINT,
575           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
576           NULL),
577       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
578           "type", G_TYPE_GTYPE, G_TYPE_UINT,
579           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
580           NULL),
581       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
582           "type", G_TYPE_GTYPE, G_TYPE_STRING,
583           "description", G_TYPE_STRING, "name of the event",
584           NULL),
585       NULL));
586   tr_message = gst_tracer_record_new (gst_structure_new ("message.class",
587       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
588           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
589           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
590           NULL),
591       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
592           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
593           "description", G_TYPE_STRING, "event ts",
594           NULL),
595       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
596           "type", G_TYPE_GTYPE, G_TYPE_UINT,
597           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
598           NULL),
599       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
600           "type", G_TYPE_GTYPE, G_TYPE_STRING,
601           "description", G_TYPE_STRING, "name of the message",
602           NULL),
603       "structure", GST_TYPE_STRUCTURE, gst_structure_new ("structure",
604           "type", G_TYPE_GTYPE, GST_TYPE_STRUCTURE,
605           "description", G_TYPE_STRING, "message structure",
606           NULL),
607       NULL));
608   tr_element_query = gst_tracer_record_new (gst_structure_new (
609       "element-query.class",
610       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
611           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
612           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
613           NULL),
614       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
615           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
616           "description", G_TYPE_STRING, "event ts",
617           NULL),
618       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
619           "type", G_TYPE_GTYPE, G_TYPE_UINT,
620           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
621           NULL),
622       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
623           "type", G_TYPE_GTYPE, G_TYPE_STRING,
624           "description", G_TYPE_STRING, "name of the query",
625           NULL),
626       NULL));
627   tr_query = gst_tracer_record_new (gst_structure_new ("query.class",
628       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
629           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
630           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
631           NULL),
632       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
633           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
634           "description", G_TYPE_STRING, "event ts",
635           NULL),
636       "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
637           "type", G_TYPE_GTYPE, G_TYPE_UINT,
638           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
639           NULL),
640       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
641           "type", G_TYPE_GTYPE, G_TYPE_UINT,
642           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
643           NULL),
644       "peer-pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
645           "type", G_TYPE_GTYPE, G_TYPE_UINT,
646           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
647           NULL),
648       "peer-element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
649           "type", G_TYPE_GTYPE, G_TYPE_UINT,
650           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
651           NULL),
652       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
653           "type", G_TYPE_GTYPE, G_TYPE_STRING,
654           "description", G_TYPE_STRING, "name of the query",
655           NULL),
656       "structure", GST_TYPE_STRUCTURE, gst_structure_new ("value",
657           "type", G_TYPE_GTYPE, GST_TYPE_STRUCTURE,
658           "description", G_TYPE_STRING, "query structure",
659           NULL),
660       "have-res", GST_TYPE_STRUCTURE, gst_structure_new ("value",
661           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
662           "description", G_TYPE_STRING, "have query result",
663           NULL),
664       "res", GST_TYPE_STRUCTURE, gst_structure_new ("value",
665           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
666           "description", G_TYPE_STRING, "query result",
667           NULL),
668       /* TODO(ensonic): "buffer-flags" */
669       NULL));
670   tr_new_element = gst_tracer_record_new (gst_structure_new (
671       "new-element.class",
672       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
673           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
674           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
675           NULL),
676       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
677           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
678           "description", G_TYPE_STRING, "event ts",
679           NULL),
680       "ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
681           "type", G_TYPE_GTYPE, G_TYPE_UINT,
682           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
683           NULL),
684       "parent-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
685           "type", G_TYPE_GTYPE, G_TYPE_UINT,
686           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
687           NULL),
688       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
689           "type", G_TYPE_GTYPE, G_TYPE_STRING,
690           "description", G_TYPE_STRING, "name of the element",
691           NULL),
692       "type", GST_TYPE_STRUCTURE, gst_structure_new ("value",
693           "type", G_TYPE_GTYPE, G_TYPE_STRING,
694           "description", G_TYPE_STRING, "type name of the element",
695           NULL),
696       "is-bin", GST_TYPE_STRUCTURE, gst_structure_new ("value",
697           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
698           "description", G_TYPE_STRING, "is element a bin",
699           NULL),
700       NULL));
701   tr_new_pad = gst_tracer_record_new (gst_structure_new ("new-pad.class",
702       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
703           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
704           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_THREAD,
705           NULL),
706       "ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
707           "type", G_TYPE_GTYPE, G_TYPE_UINT,
708           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PAD,
709           NULL),
710       "parent-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
711           "type", G_TYPE_GTYPE, G_TYPE_UINT,
712           "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_ELEMENT,
713           NULL),
714       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
715           "type", G_TYPE_GTYPE, G_TYPE_STRING,
716           "description", G_TYPE_STRING, "name of the pad",
717           NULL),
718       "type", GST_TYPE_STRUCTURE, gst_structure_new ("value",
719           "type", G_TYPE_GTYPE, G_TYPE_STRING,
720           "description", G_TYPE_STRING, "type name of the pad",
721           NULL),
722       "is-ghostpad", GST_TYPE_STRUCTURE, gst_structure_new ("value",
723           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
724           "description", G_TYPE_STRING, "is pad a ghostpad",
725           NULL),
726       "pad-direction", GST_TYPE_STRUCTURE, gst_structure_new ("value",
727           "type", G_TYPE_GTYPE, GST_TYPE_PAD_DIRECTION,
728           "description", G_TYPE_STRING, "ipad direction",
729           NULL),
730       NULL));
731   /* *INDENT-ON* */
732 }
733
734 static void
735 gst_stats_tracer_init (GstStatsTracer * self)
736 {
737   GstTracer *tracer = GST_TRACER (self);
738
739   gst_tracing_register_hook (tracer, "pad-push-pre",
740       G_CALLBACK (do_push_buffer_pre));
741   gst_tracing_register_hook (tracer, "pad-push-post",
742       G_CALLBACK (do_push_buffer_post));
743   gst_tracing_register_hook (tracer, "pad-push-list-pre",
744       G_CALLBACK (do_push_buffer_list_pre));
745   gst_tracing_register_hook (tracer, "pad-push-list-post",
746       G_CALLBACK (do_push_buffer_list_post));
747   gst_tracing_register_hook (tracer, "pad-pull-range-pre",
748       G_CALLBACK (do_pull_range_pre));
749   gst_tracing_register_hook (tracer, "pad-pull-range-post",
750       G_CALLBACK (do_pull_range_post));
751   gst_tracing_register_hook (tracer, "pad-push-event-pre",
752       G_CALLBACK (do_push_event_pre));
753   gst_tracing_register_hook (tracer, "element-new",
754       G_CALLBACK (do_element_new));
755   gst_tracing_register_hook (tracer, "element-post-message-pre",
756       G_CALLBACK (do_post_message_pre));
757   gst_tracing_register_hook (tracer, "element-query-pre",
758       G_CALLBACK (do_element_query_pre));
759   gst_tracing_register_hook (tracer, "pad-query-pre",
760       G_CALLBACK (do_query_pre));
761   gst_tracing_register_hook (tracer, "pad-query-post",
762       G_CALLBACK (do_query_post));
763 }