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