950d9206916ada21714943aef5b4ac26152fff3d
[platform/upstream/gstreamer.git] / plugins / tracers / gstleaks.c
1 /* GStreamer
2  * Copyright (C) 2016 Collabora Ltd. <guillaume.desmottes@collabora.co.uk>
3  *
4  * gstleaks.c: tracing module detecting object leaks
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:gstleaks
23  * @short_description: detect GstObject and GstMiniObject leaks
24  *
25  * A tracing module tracking the lifetime of objects by logging those still
26  * alive when program is exiting and raising a warning.
27  * The type of objects tracked can be filtered using the parameters of the
28  * tracer, for example: GST_TRACERS=leaks(filters="GstEvent,GstMessage",print-traces=true)
29  */
30
31 #ifdef HAVE_CONFIG_H
32 #  include "config.h"
33 #endif
34
35 #include "gstleaks.h"
36
37 #ifdef G_OS_UNIX
38 #include <signal.h>
39 #endif /* G_OS_UNIX */
40
41 GST_DEBUG_CATEGORY_STATIC (gst_leaks_debug);
42 #define GST_CAT_DEFAULT gst_leaks_debug
43
44 #define _do_init \
45     GST_DEBUG_CATEGORY_INIT (gst_leaks_debug, "leaks", 0, "leaks tracer");
46 #define gst_leaks_tracer_parent_class parent_class
47 G_DEFINE_TYPE_WITH_CODE (GstLeaksTracer, gst_leaks_tracer,
48     GST_TYPE_TRACER, _do_init);
49
50 static GstTracerRecord *tr_alive;
51 static GstTracerRecord *tr_refings;
52 #ifdef G_OS_UNIX
53 static GstTracerRecord *tr_added = NULL;
54 static GstTracerRecord *tr_removed = NULL;
55 #endif /* G_OS_UNIX */
56 static GQueue instances = G_QUEUE_INIT;
57
58 typedef struct
59 {
60   gboolean reffed;
61   gchar *trace;
62   gint new_refcount;
63   GstClockTime ts;
64 } ObjectRefingInfo;
65
66 typedef struct
67 {
68   gchar *creation_trace;
69
70   GList *refing_infos;
71 } ObjectRefingInfos;
72
73 static void
74 object_refing_info_free (ObjectRefingInfo * refinfo)
75 {
76   g_free (refinfo->trace);
77   g_free (refinfo);
78 }
79
80 static void
81 object_refing_infos_free (ObjectRefingInfos * infos)
82 {
83   g_list_free_full (infos->refing_infos,
84       (GDestroyNotify) object_refing_info_free);
85
86   g_free (infos->creation_trace);
87   g_free (infos);
88 }
89
90 static void
91 set_print_stack_trace (GstLeaksTracer * self, GstStructure * params)
92 {
93   gchar *trace;
94   gboolean check_stack_trace =
95       g_getenv ("GST_LEAKS_TRACER_STACK_TRACE") != NULL;
96
97   if (!check_stack_trace && params)
98     gst_structure_get_boolean (params, "print-traces", &check_stack_trace);
99
100   if (!check_stack_trace)
101     return;
102
103
104   /* Test if we can retrieve backtrace */
105   trace = gst_debug_get_stack_trace (0);
106   if (trace) {
107     self->log_stack_trace = TRUE;
108     g_free (trace);
109   } else {
110     g_warning ("Can't retrieve backtrace on this system");
111   }
112 }
113
114 static void
115 set_filters (GstLeaksTracer * self, const gchar * filters)
116 {
117   guint i;
118   GStrv tmp = g_strsplit (filters, ",", -1);
119
120   self->filter = g_array_sized_new (FALSE, FALSE, sizeof (GType),
121       g_strv_length (tmp));
122   for (i = 0; tmp[i]; i++) {
123     GType type;
124
125     type = g_type_from_name (tmp[i]);
126     if (type == 0) {
127       /* The type may not yet be known by the type system, typically because
128        * the plugin implementing it as not yet be loaded. Save it for now as
129        * it will have another chance to be added to the filter later in
130        * should_handle_object_type() when/if the object type is actually
131        * used. */
132       if (!self->unhandled_filter)
133         self->unhandled_filter = g_hash_table_new (NULL, NULL);
134
135       g_hash_table_add (self->unhandled_filter,
136           GUINT_TO_POINTER (g_quark_from_string (tmp[i])));
137       g_atomic_int_inc (&self->unhandled_filter_count);
138       continue;
139     }
140
141     GST_DEBUG_OBJECT (self, "add filter on %s", tmp[i]);
142
143     g_array_append_val (self->filter, type);
144   }
145
146   g_strfreev (tmp);
147 }
148
149 static void
150 set_params_from_structure (GstLeaksTracer * self, GstStructure * params)
151 {
152   const gchar *filters = gst_structure_get_string (params, "filters");
153
154   if (filters)
155     set_filters (self, filters);
156   gst_structure_get_boolean (params, "check-refs", &self->check_refs);
157 }
158
159 static void
160 set_params (GstLeaksTracer * self)
161 {
162   gchar *params, *tmp;
163   GstStructure *params_struct = NULL;
164
165   g_object_get (self, "params", &params, NULL);
166   if (!params)
167     goto set_stacktrace;
168
169   tmp = g_strdup_printf ("leaks,%s", params);
170   params_struct = gst_structure_from_string (tmp, NULL);
171   g_free (tmp);
172
173   if (params_struct)
174     set_params_from_structure (self, params_struct);
175   else
176     set_filters (self, params);
177
178   g_free (params);
179
180 set_stacktrace:
181   set_print_stack_trace (self, params_struct);
182
183   if (params_struct)
184     gst_structure_free (params_struct);
185 }
186
187 static gboolean
188 should_handle_object_type (GstLeaksTracer * self, GType object_type)
189 {
190   guint i, len;
191
192   if (!self->filter)
193     /* No filtering, handle all types */
194     return TRUE;
195
196   if (g_atomic_int_get (&self->unhandled_filter_count)) {
197     GST_OBJECT_LOCK (self);
198     if (self->unhandled_filter) {
199       GQuark q;
200
201       q = g_type_qname (object_type);
202       if (g_hash_table_contains (self->unhandled_filter, GUINT_TO_POINTER (q))) {
203         g_array_append_val (self->filter, object_type);
204         g_hash_table_remove (self->unhandled_filter, GUINT_TO_POINTER (q));
205
206         if (g_atomic_int_dec_and_test (&self->unhandled_filter_count))
207           g_clear_pointer (&self->unhandled_filter, g_hash_table_unref);
208
209         GST_OBJECT_UNLOCK (self);
210         return TRUE;
211       }
212     }
213     GST_OBJECT_UNLOCK (self);
214   }
215
216   len = self->filter->len;
217   for (i = 0; i < len; i++) {
218     GType type = g_array_index (self->filter, GType, i);
219
220     if (g_type_is_a (object_type, type))
221       return TRUE;
222   }
223
224   return FALSE;
225 }
226
227 #ifdef G_OS_UNIX
228 /* The object may be destroyed when we log it using the checkpointing system so
229  * we have to save its type name */
230 typedef struct
231 {
232   gpointer object;
233   const gchar *type_name;
234 } ObjectLog;
235
236 static ObjectLog *
237 object_log_new (gpointer obj)
238 {
239   ObjectLog *o = g_slice_new (ObjectLog);
240
241   o->object = obj;
242
243   if (G_IS_OBJECT (obj))
244     o->type_name = G_OBJECT_TYPE_NAME (obj);
245   else
246     o->type_name = g_type_name (GST_MINI_OBJECT_TYPE (obj));
247
248   return o;
249 }
250
251 static void
252 object_log_free (ObjectLog * obj)
253 {
254   g_slice_free (ObjectLog, obj);
255 }
256 #endif /* G_OS_UNIX */
257
258 static void
259 handle_object_destroyed (GstLeaksTracer * self, gpointer object)
260 {
261   GST_OBJECT_LOCK (self);
262   if (self->done) {
263     g_warning
264         ("object %p destroyed while the leaks tracer was finalizing. Some threads are still running?",
265         object);
266     goto out;
267   }
268
269   g_hash_table_remove (self->objects, object);
270 #ifdef G_OS_UNIX
271   if (self->removed)
272     g_hash_table_add (self->removed, object_log_new (object));
273 #endif /* G_OS_UNIX */
274 out:
275   GST_OBJECT_UNLOCK (self);
276 }
277
278 static void
279 object_weak_cb (gpointer data, GObject * object)
280 {
281   GstLeaksTracer *self = data;
282
283   handle_object_destroyed (self, object);
284 }
285
286 static void
287 mini_object_weak_cb (gpointer data, GstMiniObject * object)
288 {
289   GstLeaksTracer *self = data;
290
291   handle_object_destroyed (self, object);
292 }
293
294 static void
295 handle_object_created (GstLeaksTracer * self, gpointer object, GType type,
296     gboolean gobject)
297 {
298   ObjectRefingInfos *infos;
299
300
301   if (!should_handle_object_type (self, type))
302     return;
303
304   infos = g_malloc0 (sizeof (ObjectRefingInfos));
305   if (gobject)
306     g_object_weak_ref ((GObject *) object, object_weak_cb, self);
307   else
308     gst_mini_object_weak_ref (GST_MINI_OBJECT_CAST (object),
309         mini_object_weak_cb, self);
310
311   GST_OBJECT_LOCK (self);
312   if (self->log_stack_trace)
313     infos->creation_trace = gst_debug_get_stack_trace (0);
314
315   g_hash_table_insert (self->objects, object, infos);
316
317 #ifdef G_OS_UNIX
318   if (self->added)
319     g_hash_table_add (self->added, object_log_new (object));
320 #endif /* G_OS_UNIX */
321   GST_OBJECT_UNLOCK (self);
322 }
323
324 static void
325 mini_object_created_cb (GstTracer * tracer, GstClockTime ts,
326     GstMiniObject * object)
327 {
328   GstLeaksTracer *self = GST_LEAKS_TRACER_CAST (tracer);
329
330   handle_object_created (self, object, GST_MINI_OBJECT_TYPE (object), FALSE);
331 }
332
333 static void
334 object_created_cb (GstTracer * tracer, GstClockTime ts, GstObject * object)
335 {
336   GstLeaksTracer *self = GST_LEAKS_TRACER_CAST (tracer);
337   GType object_type = G_OBJECT_TYPE (object);
338
339   /* Can't track tracers as they may be disposed after the leak tracer itself */
340   if (g_type_is_a (object_type, GST_TYPE_TRACER))
341     return;
342
343   handle_object_created (self, object, object_type, TRUE);
344 }
345
346 static void
347 handle_object_reffed (GstLeaksTracer * self, gpointer object, gint new_refcount,
348     gboolean reffed, GstClockTime ts)
349 {
350   ObjectRefingInfos *infos;
351   ObjectRefingInfo *refinfo;
352
353   if (!self->check_refs)
354     return;
355
356   GST_OBJECT_LOCK (self);
357   infos = g_hash_table_lookup (self->objects, object);
358   if (!infos)
359     goto out;
360
361   refinfo = g_malloc0 (sizeof (ObjectRefingInfo));
362   refinfo->ts = ts;
363   refinfo->new_refcount = new_refcount;
364   refinfo->reffed = reffed;
365   if (self->log_stack_trace)
366     refinfo->trace = gst_debug_get_stack_trace (0);
367
368   infos->refing_infos = g_list_prepend (infos->refing_infos, refinfo);
369
370 out:
371   GST_OBJECT_UNLOCK (self);
372 }
373
374 static void
375 object_reffed_cb (GstTracer * tracer, GstClockTime ts, GstObject * object,
376     gint new_refcount)
377 {
378   GstLeaksTracer *self = GST_LEAKS_TRACER_CAST (tracer);
379
380   handle_object_reffed (self, object, new_refcount, TRUE, ts);
381 }
382
383 static void
384 object_unreffed_cb (GstTracer * tracer, GstClockTime ts, GstObject * object,
385     gint new_refcount)
386 {
387   GstLeaksTracer *self = GST_LEAKS_TRACER_CAST (tracer);
388
389   handle_object_reffed (self, object, new_refcount, FALSE, ts);
390 }
391
392 static void
393 mini_object_reffed_cb (GstTracer * tracer, GstClockTime ts,
394     GstMiniObject * object, gint new_refcount)
395 {
396   GstLeaksTracer *self = GST_LEAKS_TRACER_CAST (tracer);
397
398   handle_object_reffed (self, object, new_refcount, TRUE, ts);
399 }
400
401 static void
402 mini_object_unreffed_cb (GstTracer * tracer, GstClockTime ts,
403     GstMiniObject * object, gint new_refcount)
404 {
405   GstLeaksTracer *self = GST_LEAKS_TRACER_CAST (tracer);
406
407   handle_object_reffed (self, object, new_refcount, FALSE, ts);
408 }
409
410 static void
411 gst_leaks_tracer_init (GstLeaksTracer * self)
412 {
413   self->objects = g_hash_table_new_full (NULL, NULL, NULL,
414       (GDestroyNotify) object_refing_infos_free);
415
416   g_queue_push_tail (&instances, self);
417 }
418
419 static void
420 gst_leaks_tracer_constructed (GObject * object)
421 {
422   GstLeaksTracer *self = GST_LEAKS_TRACER (object);
423   GstTracer *tracer = GST_TRACER (object);
424
425   set_params (self);
426
427   gst_tracing_register_hook (tracer, "mini-object-created",
428       G_CALLBACK (mini_object_created_cb));
429   gst_tracing_register_hook (tracer, "object-created",
430       G_CALLBACK (object_created_cb));
431
432   if (self->check_refs) {
433     gst_tracing_register_hook (tracer, "object-reffed",
434         G_CALLBACK (object_reffed_cb));
435     gst_tracing_register_hook (tracer, "mini-object-reffed",
436         G_CALLBACK (mini_object_reffed_cb));
437     gst_tracing_register_hook (tracer, "mini-object-unreffed",
438         G_CALLBACK (mini_object_unreffed_cb));
439     gst_tracing_register_hook (tracer, "object-unreffed",
440         G_CALLBACK (object_unreffed_cb));
441   }
442
443   /* We rely on weak pointers rather than (mini-)object-destroyed hooks so we
444    * are notified of objects being destroyed even during the shuting down of
445    * the tracing system. */
446
447   ((GObjectClass *) gst_leaks_tracer_parent_class)->constructed (object);
448 }
449
450 typedef struct
451 {
452   gpointer obj;
453   const gchar *type_name;
454   guint ref_count;
455   gchar *desc;
456   ObjectRefingInfos *infos;
457 } Leak;
458
459 /* The content of the returned Leak struct is valid until the self->objects
460  * hash table has been modified. */
461 static Leak *
462 leak_new (gpointer obj, GType type, guint ref_count, ObjectRefingInfos * infos)
463 {
464   Leak *leak = g_slice_new (Leak);
465
466   leak->obj = obj;
467   leak->type_name = g_type_name (type);
468   leak->ref_count = ref_count;
469   leak->desc = gst_info_strdup_printf ("%" GST_PTR_FORMAT, obj);
470   leak->infos = infos;
471
472   return leak;
473 }
474
475 static void
476 leak_free (Leak * leak)
477 {
478   g_free (leak->desc);
479   g_slice_free (Leak, leak);
480 }
481
482 static gint
483 sort_leaks (gconstpointer _a, gconstpointer _b)
484 {
485   const Leak *a = _a, *b = _b;
486
487   return g_strcmp0 (a->type_name, b->type_name);
488 }
489
490 static GList *
491 create_leaks_list (GstLeaksTracer * self)
492 {
493   GList *l = NULL;
494   GHashTableIter iter;
495   gpointer obj, infos;
496
497   g_hash_table_iter_init (&iter, self->objects);
498   while (g_hash_table_iter_next (&iter, &obj, &infos)) {
499     GType type;
500     guint ref_count;
501
502     if (GST_IS_OBJECT (obj)) {
503       if (GST_OBJECT_FLAG_IS_SET (obj, GST_OBJECT_FLAG_MAY_BE_LEAKED))
504         continue;
505
506       type = G_OBJECT_TYPE (obj);
507       ref_count = ((GObject *) obj)->ref_count;
508     } else {
509       if (GST_MINI_OBJECT_FLAG_IS_SET (obj, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED))
510         continue;
511
512       type = GST_MINI_OBJECT_TYPE (obj);
513       ref_count = ((GstMiniObject *) obj)->refcount;
514     }
515
516     l = g_list_prepend (l, leak_new (obj, type, ref_count, infos));
517   }
518
519   /* Sort leaks by type name so they are grouped together making the output
520    * easier to read */
521   l = g_list_sort (l, sort_leaks);
522
523   return l;
524 }
525
526 /* Return TRUE if at least one leaked object has been logged */
527 static gboolean
528 log_leaked (GstLeaksTracer * self)
529 {
530   GList *ref, *leaks, *l;
531
532   leaks = create_leaks_list (self);
533   if (!leaks)
534     return FALSE;
535
536   for (l = leaks; l != NULL; l = g_list_next (l)) {
537     Leak *leak = l->data;
538
539     gst_tracer_record_log (tr_alive, leak->type_name, leak->obj, leak->desc,
540         leak->ref_count,
541         leak->infos->creation_trace ? leak->infos->creation_trace : "");
542
543     leak->infos->refing_infos = g_list_reverse (leak->infos->refing_infos);
544     for (ref = leak->infos->refing_infos; ref; ref = ref->next) {
545       ObjectRefingInfo *refinfo = (ObjectRefingInfo *) ref->data;
546
547       gst_tracer_record_log (tr_refings, refinfo->ts, leak->type_name,
548           leak->obj, refinfo->reffed ? "reffed" : "unreffed",
549           refinfo->new_refcount, refinfo->trace ? refinfo->trace : "");
550     }
551   }
552
553   g_list_free_full (leaks, (GDestroyNotify) leak_free);
554
555   return TRUE;
556 }
557
558 static void
559 gst_leaks_tracer_finalize (GObject * object)
560 {
561   GstLeaksTracer *self = GST_LEAKS_TRACER (object);
562   gboolean leaks;
563   GHashTableIter iter;
564   gpointer obj;
565
566   self->done = TRUE;
567
568   /* Tracers are destroyed as part of gst_deinit() so now is a good time to
569    * report all the objects which are still alive. */
570   leaks = log_leaked (self);
571
572   /* Remove weak references */
573   g_hash_table_iter_init (&iter, self->objects);
574   while (g_hash_table_iter_next (&iter, &obj, NULL)) {
575     if (GST_IS_OBJECT (obj))
576       g_object_weak_unref (obj, object_weak_cb, self);
577     else
578       gst_mini_object_weak_unref (GST_MINI_OBJECT_CAST (obj),
579           mini_object_weak_cb, self);
580   }
581
582   g_clear_pointer (&self->objects, g_hash_table_unref);
583   if (self->filter)
584     g_array_free (self->filter, TRUE);
585   g_clear_pointer (&self->added, g_hash_table_unref);
586   g_clear_pointer (&self->removed, g_hash_table_unref);
587   g_clear_pointer (&self->unhandled_filter, g_hash_table_unref);
588
589   g_queue_remove (&instances, self);
590
591   if (leaks)
592     g_warning ("Leaks detected");
593
594   ((GObjectClass *) gst_leaks_tracer_parent_class)->finalize (object);
595 }
596
597 #define RECORD_FIELD_TYPE_TS \
598     "ts", GST_TYPE_STRUCTURE, gst_structure_new ("value", \
599         "type", G_TYPE_GTYPE, GST_TYPE_CLOCK_TIME, \
600         "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PROCESS, \
601         NULL)
602 #define RECORD_FIELD_TYPE_NAME \
603     "type-name", GST_TYPE_STRUCTURE, gst_structure_new ("value", \
604         "type", G_TYPE_GTYPE, G_TYPE_STRING, \
605         "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PROCESS, \
606         NULL)
607 #define RECORD_FIELD_ADDRESS \
608     "address", GST_TYPE_STRUCTURE, gst_structure_new ("value", \
609         "type", G_TYPE_GTYPE, G_TYPE_POINTER, \
610         "related-to", GST_TYPE_TRACER_VALUE_SCOPE, \
611         GST_TRACER_VALUE_SCOPE_PROCESS, \
612         NULL)
613 #define RECORD_FIELD_DESC \
614     "description", GST_TYPE_STRUCTURE, gst_structure_new ("value", \
615         "type", G_TYPE_GTYPE, G_TYPE_STRING, \
616         "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PROCESS, \
617         NULL)
618 #define RECORD_FIELD_REF_COUNT \
619     "ref-count", GST_TYPE_STRUCTURE, gst_structure_new ("value", \
620         "type", G_TYPE_GTYPE, G_TYPE_UINT, \
621         "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PROCESS, \
622         NULL)
623 #define RECORD_FIELD_TRACE \
624     "trace", GST_TYPE_STRUCTURE, gst_structure_new ("value", \
625         "type", G_TYPE_GTYPE, G_TYPE_STRING, \
626         "related-to", GST_TYPE_TRACER_VALUE_SCOPE, GST_TRACER_VALUE_SCOPE_PROCESS, \
627         NULL)
628
629 #ifdef G_OS_UNIX
630 static void
631 sig_usr1_handler_foreach (gpointer data, gpointer user_data)
632 {
633   GstLeaksTracer *tracer = data;
634
635   GST_OBJECT_LOCK (tracer);
636   GST_TRACE_OBJECT (tracer, "start listing currently alive objects");
637   log_leaked (tracer);
638   GST_TRACE_OBJECT (tracer, "done listing currently alive objects");
639   GST_OBJECT_UNLOCK (tracer);
640 }
641
642 static void
643 sig_usr1_handler (G_GNUC_UNUSED int signal)
644 {
645   g_queue_foreach (&instances, sig_usr1_handler_foreach, NULL);
646 }
647
648 static void
649 log_checkpoint (GHashTable * hash, GstTracerRecord * record)
650 {
651   GHashTableIter iter;
652   gpointer o;
653
654   g_hash_table_iter_init (&iter, hash);
655   while (g_hash_table_iter_next (&iter, &o, NULL)) {
656     ObjectLog *obj = o;
657
658     gst_tracer_record_log (record, obj->type_name, obj->object);
659   }
660 }
661
662 static void
663 do_checkpoint (GstLeaksTracer * self)
664 {
665   GST_TRACE_OBJECT (self, "listing objects created since last checkpoint");
666   log_checkpoint (self->added, tr_added);
667   GST_TRACE_OBJECT (self, "listing objects removed since last checkpoint");
668   log_checkpoint (self->removed, tr_removed);
669
670   g_hash_table_remove_all (self->added);
671   g_hash_table_remove_all (self->removed);
672 }
673
674 static void
675 sig_usr2_handler_foreach (gpointer data, gpointer user_data)
676 {
677   GstLeaksTracer *tracer = data;
678
679   GST_OBJECT_LOCK (tracer);
680
681   if (!tracer->added) {
682     GST_TRACE_OBJECT (tracer, "First checkpoint, start tracking objects");
683
684     tracer->added = g_hash_table_new_full (NULL, NULL,
685         (GDestroyNotify) object_log_free, NULL);
686     tracer->removed = g_hash_table_new_full (NULL, NULL,
687         (GDestroyNotify) object_log_free, NULL);
688   } else {
689     do_checkpoint (tracer);
690   }
691
692   GST_OBJECT_UNLOCK (tracer);
693 }
694
695 static void
696 sig_usr2_handler (G_GNUC_UNUSED int signal)
697 {
698   g_queue_foreach (&instances, sig_usr2_handler_foreach, NULL);
699 }
700
701 static void
702 setup_signals (void)
703 {
704   tr_added = gst_tracer_record_new ("object-added.class",
705       RECORD_FIELD_TYPE_NAME, RECORD_FIELD_ADDRESS, NULL);
706   GST_OBJECT_FLAG_SET (tr_added, GST_OBJECT_FLAG_MAY_BE_LEAKED);
707
708   tr_removed = gst_tracer_record_new ("object-removed.class",
709       RECORD_FIELD_TYPE_NAME, RECORD_FIELD_ADDRESS, NULL);
710   GST_OBJECT_FLAG_SET (tr_removed, GST_OBJECT_FLAG_MAY_BE_LEAKED);
711
712   signal (SIGUSR1, sig_usr1_handler);
713   signal (SIGUSR2, sig_usr2_handler);
714 }
715 #endif /* G_OS_UNIX */
716
717 static void
718 gst_leaks_tracer_class_init (GstLeaksTracerClass * klass)
719 {
720   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
721
722   gobject_class->constructed = gst_leaks_tracer_constructed;
723   gobject_class->finalize = gst_leaks_tracer_finalize;
724
725   tr_alive = gst_tracer_record_new ("object-alive.class",
726       RECORD_FIELD_TYPE_NAME, RECORD_FIELD_ADDRESS, RECORD_FIELD_DESC,
727       RECORD_FIELD_REF_COUNT, RECORD_FIELD_TRACE, NULL);
728   GST_OBJECT_FLAG_SET (tr_alive, GST_OBJECT_FLAG_MAY_BE_LEAKED);
729
730   tr_refings = gst_tracer_record_new ("object-refings.class",
731       RECORD_FIELD_TYPE_TS, RECORD_FIELD_TYPE_NAME, RECORD_FIELD_ADDRESS,
732       RECORD_FIELD_DESC, RECORD_FIELD_REF_COUNT, RECORD_FIELD_TRACE, NULL);
733   GST_OBJECT_FLAG_SET (tr_alive, GST_OBJECT_FLAG_MAY_BE_LEAKED);
734
735   if (g_getenv ("GST_LEAKS_TRACER_SIG")) {
736 #ifdef G_OS_UNIX
737     setup_signals ();
738 #else
739     g_warning ("System doesn't support POSIX signals");
740 #endif /* G_OS_UNIX */
741   }
742 }