tracerrecord: add a log record class
[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 #include <gst/gsttracerrecord.h>
34
35 #include <stdio.h>
36
37 GST_DEBUG_CATEGORY_STATIC (gst_stats_debug);
38 #define GST_CAT_DEFAULT gst_stats_debug
39
40 static GQuark data_quark;
41 G_LOCK_DEFINE (_elem_stats);
42 G_LOCK_DEFINE (_pad_stats);
43
44 #define _do_init \
45     GST_DEBUG_CATEGORY_INIT (gst_stats_debug, "stats", 0, "stats tracer"); \
46     data_quark = g_quark_from_static_string ("gststats:data");
47 #define gst_stats_tracer_parent_class parent_class
48 G_DEFINE_TYPE_WITH_CODE (GstStatsTracer, gst_stats_tracer, GST_TYPE_TRACER,
49     _do_init);
50
51 static GstTracerRecord *tr_new_element;
52 static GstTracerRecord *tr_new_pad;
53 static GstTracerRecord *tr_buffer;
54 static GstTracerRecord *tr_element_query;
55 static GstTracerRecord *tr_event;
56 static GstTracerRecord *tr_message;
57 static GstTracerRecord *tr_query;
58
59 typedef struct
60 {
61   /* we can't rely on the address to be unique over time */
62   guint index;
63   /* for pre + post */
64   GstClockTime last_ts;
65   /* hierarchy */
66   guint parent_ix;
67 } GstPadStats;
68
69 typedef struct
70 {
71   /* we can't rely on the address to be unique over time */
72   guint index;
73   /* for pre + post */
74   GstClockTime last_ts;
75   /* time spend in this element */
76   GstClockTime treal;
77   /* hierarchy */
78   guint parent_ix;
79 } GstElementStats;
80
81 /* data helper */
82
83 static GstElementStats no_elem_stats = { 0, };
84
85 static GstElementStats *
86 fill_element_stats (GstStatsTracer * self, GstElement * element)
87 {
88   GstElementStats *stats = g_slice_new0 (GstElementStats);
89
90   stats->index = self->num_elements++;
91   stats->parent_ix = G_MAXUINT;
92   return stats;
93 }
94
95 static void
96 log_new_element_stats (GstElementStats * stats, GstElement * element,
97     GstClockTime elapsed)
98 {
99   gst_tracer_record_log (tr_new_element, (guint64) g_thread_self (),
100       elapsed, stats->index, stats->parent_ix, GST_OBJECT_NAME (element),
101       G_OBJECT_TYPE_NAME (element), GST_IS_BIN (element));
102 }
103
104 static void
105 free_element_stats (gpointer data)
106 {
107   g_slice_free (GstElementStats, data);
108 }
109
110 static GstElementStats *
111 create_element_stats (GstStatsTracer * self, GstElement * element)
112 {
113   GstElementStats *stats;
114
115   stats = fill_element_stats (self, element);
116   g_object_set_qdata_full ((GObject *) element, data_quark, stats,
117       free_element_stats);
118
119   return stats;
120 }
121
122 static inline GstElementStats *
123 get_element_stats (GstStatsTracer * self, GstElement * element)
124 {
125   GstElementStats *stats;
126   gboolean is_new = FALSE;
127
128   if (!element) {
129     no_elem_stats.index = G_MAXUINT;
130     return &no_elem_stats;
131   }
132
133   G_LOCK (_elem_stats);
134   if (!(stats = g_object_get_qdata ((GObject *) element, data_quark))) {
135     stats = create_element_stats (self, element);
136     is_new = TRUE;
137   }
138   G_UNLOCK (_elem_stats);
139   if (G_UNLIKELY (stats->parent_ix == G_MAXUINT)) {
140     GstElement *parent = GST_ELEMENT_PARENT (element);
141     if (parent) {
142       GstElementStats *parent_stats = get_element_stats (self, parent);
143       stats->parent_ix = parent_stats->index;
144     }
145   }
146   if (G_UNLIKELY (is_new)) {
147     log_new_element_stats (stats, element, GST_CLOCK_TIME_NONE);
148   }
149   return stats;
150 }
151
152 /*
153  * Get the element/bin owning the pad.
154  *
155  * in: a normal pad
156  * out: the element
157  *
158  * in: a proxy pad
159  * out: the element that contains the peer of the proxy
160  *
161  * in: a ghost pad
162  * out: the bin owning the ghostpad
163  */
164 /* TODO(ensonic): gst_pad_get_parent_element() would not work here, should we
165  * add this as new api, e.g. gst_pad_find_parent_element();
166  */
167 static GstElement *
168 get_real_pad_parent (GstPad * pad)
169 {
170   GstObject *parent;
171
172   if (!pad)
173     return NULL;
174
175   parent = GST_OBJECT_PARENT (pad);
176
177   /* if parent of pad is a ghost-pad, then pad is a proxy_pad */
178   if (parent && GST_IS_GHOST_PAD (parent)) {
179     pad = GST_PAD_CAST (parent);
180     parent = GST_OBJECT_PARENT (pad);
181   }
182   return GST_ELEMENT_CAST (parent);
183 }
184
185 static GstPadStats no_pad_stats = { 0, };
186
187 static GstPadStats *
188 fill_pad_stats (GstStatsTracer * self, GstPad * pad)
189 {
190   GstPadStats *stats = g_slice_new0 (GstPadStats);
191
192   stats->index = self->num_pads++;
193   stats->parent_ix = G_MAXUINT;
194
195   return stats;
196 }
197
198 static void
199 log_new_pad_stats (GstPadStats * stats, GstPad * pad)
200 {
201   gst_tracer_record_log (tr_new_element, (guint64) g_thread_self (),
202       stats->index, stats->parent_ix, GST_OBJECT_NAME (pad),
203       G_OBJECT_TYPE_NAME (pad), GST_IS_GHOST_PAD (pad),
204       GST_PAD_DIRECTION (pad));
205 }
206
207 static void
208 free_pad_stats (gpointer data)
209 {
210   g_slice_free (GstPadStats, data);
211 }
212
213 static GstPadStats *
214 get_pad_stats (GstStatsTracer * self, GstPad * pad)
215 {
216   GstPadStats *stats;
217   gboolean is_new = FALSE;
218
219   if (!pad) {
220     no_pad_stats.index = G_MAXUINT;
221     return &no_pad_stats;
222   }
223
224   G_LOCK (_pad_stats);
225   if (!(stats = g_object_get_qdata ((GObject *) pad, data_quark))) {
226     stats = fill_pad_stats (self, pad);
227     g_object_set_qdata_full ((GObject *) pad, data_quark, stats,
228         free_pad_stats);
229     is_new = TRUE;
230   }
231   G_UNLOCK (_pad_stats);
232   if (G_UNLIKELY (stats->parent_ix == G_MAXUINT)) {
233     GstElement *elem = get_real_pad_parent (pad);
234     if (elem) {
235       GstElementStats *elem_stats = get_element_stats (self, elem);
236
237       stats->parent_ix = elem_stats->index;
238     }
239   }
240   if (G_UNLIKELY (is_new)) {
241     log_new_pad_stats (stats, pad);
242   }
243   return stats;
244 }
245
246 static void
247 do_buffer_stats (GstStatsTracer * self, GstPad * this_pad,
248     GstPadStats * this_pad_stats, GstPad * that_pad,
249     GstPadStats * that_pad_stats, GstBuffer * buf, GstClockTime elapsed)
250 {
251   GstElement *this_elem = get_real_pad_parent (this_pad);
252   GstElementStats *this_elem_stats = get_element_stats (self, this_elem);
253   GstElement *that_elem = get_real_pad_parent (that_pad);
254   GstElementStats *that_elem_stats = get_element_stats (self, that_elem);
255
256   gst_tracer_record_log (tr_buffer, (guint64) g_thread_self (), elapsed,
257       this_pad_stats->index, this_elem_stats->index, that_pad_stats->index,
258       that_elem_stats->index, gst_buffer_get_size (buf), GST_BUFFER_PTS (buf),
259       GST_BUFFER_DTS (buf), GST_BUFFER_DURATION (buf), 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) g_thread_self (), elapsed,
274       this_pad_stats->index, this_elem_stats->index, that_pad_stats->index,
275       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) 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
463   stats->last_ts = ts;
464   gst_tracer_record_log (tr_message, (guint64) g_thread_self (), ts,
465       stats->index, GST_MESSAGE_TYPE_NAME (msg),
466       (msg_s ? msg_s : gst_structure_new_empty ("dummy")));
467 }
468
469 static void
470 do_element_new (GstStatsTracer * self, guint64 ts, GstElement * elem)
471 {
472   GstElementStats *stats;
473
474   stats = create_element_stats (self, elem);
475   log_new_element_stats (stats, elem, ts);
476 }
477
478 static void
479 do_element_query_pre (GstStatsTracer * self, guint64 ts, GstElement * elem,
480     GstQuery * qry)
481 {
482   GstElementStats *stats = get_element_stats (self, elem);
483
484   stats->last_ts = ts;
485   gst_tracer_record_log (tr_element_query, (guint64) g_thread_self (), ts,
486       stats->index, GST_QUERY_TYPE_NAME (qry));
487 }
488
489 static void
490 do_query_pre (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
491     GstQuery * qry)
492 {
493   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
494   GstPad *that_pad = GST_PAD_PEER (this_pad);
495   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
496
497   do_query_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
498       qry, ts, FALSE, FALSE);
499 }
500
501 static void
502 do_query_post (GstStatsTracer * self, guint64 ts, GstPad * this_pad,
503     GstQuery * qry, gboolean res)
504 {
505   GstPadStats *this_pad_stats = get_pad_stats (self, this_pad);
506   GstPad *that_pad = GST_PAD_PEER (this_pad);
507   GstPadStats *that_pad_stats = get_pad_stats (self, that_pad);
508
509   do_query_stats (self, this_pad, this_pad_stats, that_pad, that_pad_stats,
510       qry, ts, TRUE, res);
511 }
512
513 /* tracer class */
514
515 static void
516 gst_stats_tracer_class_init (GstStatsTracerClass * klass)
517 {
518   /* announce trace formats */
519   /* *INDENT-OFF* */
520   tr_buffer = gst_tracer_record_new (gst_structure_new ("buffer.class",
521       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
522           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
523           "related-to", G_TYPE_STRING, "thread", /* TODO use genum */
524           NULL),
525       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
526           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
527           "description", G_TYPE_STRING, "event ts",
528           NULL),
529       "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
530           "type", G_TYPE_GTYPE, G_TYPE_UINT,
531           "related-to", G_TYPE_STRING, "pad",  /* TODO: use genum */
532           NULL),
533       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
534           "type", G_TYPE_GTYPE, G_TYPE_UINT,
535           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
536           NULL),
537       "peer-pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
538           "type", G_TYPE_GTYPE, G_TYPE_UINT,
539           "related-to", G_TYPE_STRING, "pad",  /* TODO: use genum */
540           NULL),
541       "peer-element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
542           "type", G_TYPE_GTYPE, G_TYPE_UINT,
543           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
544           NULL),
545       "buffer-size", GST_TYPE_STRUCTURE, gst_structure_new ("value",
546           "type", G_TYPE_GTYPE, G_TYPE_UINT,
547           "description", G_TYPE_STRING, "size of buffer in bytes",
548           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
549           "min", G_TYPE_UINT, 0,
550           "max", G_TYPE_UINT, G_MAXUINT,
551           NULL),
552       "buffer-ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
553           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
554           "description", G_TYPE_STRING, "timestamp of the buffer in ns",
555           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
556           "min", G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
557           "max", G_TYPE_UINT64, G_MAXUINT64,
558           NULL),
559       "buffer-duration", GST_TYPE_STRUCTURE, gst_structure_new ("value",
560           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
561           "description", G_TYPE_STRING, "duration of the buffer in ns",
562           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
563           "min", G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
564           "max", G_TYPE_UINT64, G_MAXUINT64,
565           NULL),
566       /* TODO(ensonic): "buffer-flags" */
567       NULL));
568   tr_event = gst_tracer_record_new (gst_structure_new ("event.class",
569       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
570           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
571           "related-to", G_TYPE_STRING, "thread", /* TODO use genum */
572           NULL),
573       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
574           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
575           "description", G_TYPE_STRING, "event ts",
576           NULL),
577       "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
578           "type", G_TYPE_GTYPE, G_TYPE_UINT,
579           "related-to", G_TYPE_STRING, "pad",  /* TODO: use genum */
580           NULL),
581       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
582           "type", G_TYPE_GTYPE, G_TYPE_UINT,
583           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
584           NULL),
585       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
586           "type", G_TYPE_GTYPE, G_TYPE_STRING,
587           "description", G_TYPE_STRING, "name of the event",
588           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
589           NULL),
590       NULL));
591   tr_message = gst_tracer_record_new (gst_structure_new ("message.class",
592       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
593           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
594           "related-to", G_TYPE_STRING, "thread", /* TODO use genum */
595           NULL),
596       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
597           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
598           "description", G_TYPE_STRING, "event ts",
599           NULL),
600       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
601           "type", G_TYPE_GTYPE, G_TYPE_UINT,
602           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
603           NULL),
604       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
605           "type", G_TYPE_GTYPE, G_TYPE_STRING,
606           "description", G_TYPE_STRING, "name of the message",
607           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
608           NULL),
609       "structure", GST_TYPE_STRUCTURE, gst_structure_new ("structure",
610           "type", G_TYPE_GTYPE, GST_TYPE_STRUCTURE,
611           "description", G_TYPE_STRING, "message structure",
612           NULL),
613       NULL));
614   tr_element_query = gst_tracer_record_new (gst_structure_new (
615       "element-query.class",
616       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
617           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
618           "related-to", G_TYPE_STRING, "thread", /* TODO use genum */
619           NULL),
620       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
621           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
622           "description", G_TYPE_STRING, "event ts",
623           NULL),
624       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
625           "type", G_TYPE_GTYPE, G_TYPE_UINT,
626           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
627           NULL),
628       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
629           "type", G_TYPE_GTYPE, G_TYPE_STRING,
630           "description", G_TYPE_STRING, "name of the query",
631           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
632           NULL),
633       NULL));
634   tr_query = gst_tracer_record_new (gst_structure_new ("query.class",
635       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
636           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
637           "related-to", G_TYPE_STRING, "thread", /* TODO use genum */
638           NULL),
639       "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value",
640           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
641           "description", G_TYPE_STRING, "event ts",
642           NULL),
643       "pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
644           "type", G_TYPE_GTYPE, G_TYPE_UINT,
645           "related-to", G_TYPE_STRING, "pad",  /* TODO: use genum */
646           NULL),
647       "element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
648           "type", G_TYPE_GTYPE, G_TYPE_UINT,
649           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
650           NULL),
651       "peer-pad-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
652           "type", G_TYPE_GTYPE, G_TYPE_UINT,
653           "related-to", G_TYPE_STRING, "pad",  /* TODO: use genum */
654           NULL),
655       "peer-element-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
656           "type", G_TYPE_GTYPE, G_TYPE_UINT,
657           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
658           NULL),
659       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
660           "type", G_TYPE_GTYPE, G_TYPE_STRING,
661           "description", G_TYPE_STRING, "name of the query",
662           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
663           NULL),
664       "structure", GST_TYPE_STRUCTURE, gst_structure_new ("value",
665           "type", G_TYPE_GTYPE, GST_TYPE_STRUCTURE,
666           "description", G_TYPE_STRING, "query structure",
667           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
668           NULL),
669       "have-res", GST_TYPE_STRUCTURE, gst_structure_new ("value",
670           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
671           "description", G_TYPE_STRING, "have query result",
672           NULL),
673       "res", GST_TYPE_STRUCTURE, gst_structure_new ("value",
674           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
675           "description", G_TYPE_STRING, "query result",
676           NULL),
677       /* TODO(ensonic): "buffer-flags" */
678       NULL));
679   tr_new_element = gst_tracer_record_new (gst_structure_new (
680       "new-element.class",
681       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
682           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
683           "related-to", G_TYPE_STRING, "thread", /* TODO use genum */
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", G_TYPE_STRING, "element",  /* TODO: use genum */
692           NULL),
693       "parent-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
694           "type", G_TYPE_GTYPE, G_TYPE_UINT,
695           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
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           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
701           NULL),
702       "type", GST_TYPE_STRUCTURE, gst_structure_new ("value",
703           "type", G_TYPE_GTYPE, G_TYPE_STRING,
704           "description", G_TYPE_STRING, "type name of the element",
705           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
706           NULL),
707       "is-bin", GST_TYPE_STRUCTURE, gst_structure_new ("value",
708           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
709           "description", G_TYPE_STRING, "is element a bin",
710           NULL),
711       NULL));
712   tr_new_pad = gst_tracer_record_new (gst_structure_new ("new-pad.class",
713       "thread-id", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
714           "type", G_TYPE_GTYPE, G_TYPE_UINT64,
715           "related-to", G_TYPE_STRING, "thread", /* TODO use genum */
716           NULL),
717       "ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
718           "type", G_TYPE_GTYPE, G_TYPE_UINT,
719           "related-to", G_TYPE_STRING, "pad",  /* TODO: use genum */
720           NULL),
721       "parent-ix", GST_TYPE_STRUCTURE, gst_structure_new ("scope",
722           "type", G_TYPE_GTYPE, G_TYPE_UINT,
723           "related-to", G_TYPE_STRING, "element",  /* TODO: use genum */
724           NULL),
725       "name", GST_TYPE_STRUCTURE, gst_structure_new ("value",
726           "type", G_TYPE_GTYPE, G_TYPE_STRING,
727           "description", G_TYPE_STRING, "name of the pad",
728           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
729           NULL),
730       "type", GST_TYPE_STRUCTURE, gst_structure_new ("value",
731           "type", G_TYPE_GTYPE, G_TYPE_STRING,
732           "description", G_TYPE_STRING, "type name of the pad",
733           "flags", G_TYPE_STRING, "",  /* TODO: use gflags */
734           NULL),
735       "is-ghostpad", GST_TYPE_STRUCTURE, gst_structure_new ("value",
736           "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
737           "description", G_TYPE_STRING, "is pad a ghostpad",
738           NULL),
739       "pad-direction", GST_TYPE_STRUCTURE, gst_structure_new ("value",
740           "type", G_TYPE_GTYPE, GST_TYPE_PAD_DIRECTION,
741           "description", G_TYPE_STRING, "ipad direction",
742           NULL),
743       NULL));
744   /* *INDENT-ON* */
745 }
746
747 static void
748 gst_stats_tracer_init (GstStatsTracer * self)
749 {
750   GstTracer *tracer = GST_TRACER (self);
751
752   gst_tracing_register_hook (tracer, "pad-push-pre",
753       G_CALLBACK (do_push_buffer_pre));
754   gst_tracing_register_hook (tracer, "pad-push-post",
755       G_CALLBACK (do_push_buffer_post));
756   gst_tracing_register_hook (tracer, "pad-push-list-pre",
757       G_CALLBACK (do_push_buffer_list_pre));
758   gst_tracing_register_hook (tracer, "pad-push-list-post",
759       G_CALLBACK (do_push_buffer_list_post));
760   gst_tracing_register_hook (tracer, "pad-pull-range-pre",
761       G_CALLBACK (do_pull_range_pre));
762   gst_tracing_register_hook (tracer, "pad-pull-range-post",
763       G_CALLBACK (do_pull_range_post));
764   gst_tracing_register_hook (tracer, "pad-push-event-pre",
765       G_CALLBACK (do_push_event_pre));
766   gst_tracing_register_hook (tracer, "element-new",
767       G_CALLBACK (do_element_new));
768   gst_tracing_register_hook (tracer, "element-post-message-pre",
769       G_CALLBACK (do_post_message_pre));
770   gst_tracing_register_hook (tracer, "element-query-pre",
771       G_CALLBACK (do_element_query_pre));
772   gst_tracing_register_hook (tracer, "pad-query-pre",
773       G_CALLBACK (do_query_pre));
774   gst_tracing_register_hook (tracer, "pad-query-post",
775       G_CALLBACK (do_query_post));
776 }