2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gsttrace.c: Tracing functions (deprecated)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 * @short_description: Tracing functionality
27 * Traces allows to track object allocation. They provide a instance counter per
28 * #GType. The counter is incremented for each object allocated and decremented
32 * <title>Tracing object instances</title>
34 * // trace un-freed object instances
35 * gst_alloc_trace_set_flags_all (GST_ALLOC_TRACE_LIVE);
36 * if (!gst_alloc_trace_available ()) {
37 * g_warning ("Trace not available (recompile with trace enabled).");
39 * gst_alloc_trace_print_live ();
40 * // do something here
41 * gst_alloc_trace_print_live ();
45 * Last reviewed on 2005-11-21 (0.9.5)
60 #if defined (_MSC_VER) && _MSC_VER >= 1400
64 #include "gst_private.h"
69 GMutex _gst_trace_mutex;
72 static GstAllocTraceFlags _gst_trace_flags = GST_ALLOC_TRACE_NONE;
74 /* list of registered tracers */
75 static GList *_gst_alloc_tracers = NULL;
81 _priv_gst_alloc_trace_dump ();
85 _priv_gst_alloc_trace_initialize (void)
89 trace = g_getenv ("GST_TRACE");
91 _gst_trace_flags = atoi (trace);
95 g_mutex_init (&_gst_trace_mutex);
99 _priv_gst_alloc_trace_deinit (void)
101 g_mutex_clear (&_gst_trace_mutex);
105 * _priv_gst_alloc_trace_register:
106 * @name: the name of the new alloc trace object.
107 * @offset: the offset in the object where a GType an be found. -1 when the
108 * object has no gtype.
110 * Register an get a handle to a GstAllocTrace object that
111 * can be used to trace memory allocations.
113 * Returns: A handle to a GstAllocTrace.
116 _priv_gst_alloc_trace_register (const gchar * name, goffset offset)
118 GstAllocTrace *trace;
120 g_return_val_if_fail (name, NULL);
122 trace = g_slice_new (GstAllocTrace);
123 trace->name = g_strdup (name);
125 trace->mem_live = NULL;
126 trace->flags = _gst_trace_flags;
127 trace->offset = offset;
129 _gst_alloc_tracers = g_list_prepend (_gst_alloc_tracers, trace);
135 compare_func (GstAllocTrace * a, GstAllocTrace * b)
137 return strcmp (a->name, b->name);
141 gst_alloc_trace_list_sorted (void)
145 ret = g_list_sort (g_list_copy (_gst_alloc_tracers),
146 (GCompareFunc) compare_func);
152 gst_alloc_trace_print (const GstAllocTrace * trace)
156 g_return_if_fail (trace != NULL);
158 if (trace->flags & GST_ALLOC_TRACE_LIVE) {
159 g_print ("%-22.22s : %d\n", trace->name, trace->live);
161 g_print ("%-22.22s : (no live count)\n", trace->name);
164 if (trace->flags & GST_ALLOC_TRACE_MEM_LIVE) {
165 mem_live = trace->mem_live;
168 gpointer data = mem_live->data;
169 const gchar *type_name;
171 if (G_IS_OBJECT (data)) {
172 type_name = G_OBJECT_TYPE_NAME (data);
173 } else if (trace->offset != -1) {
176 type = G_STRUCT_MEMBER (GType, data, trace->offset);
177 type_name = g_type_name (type);
182 g_print (" %-20.20s : %p\n", type_name, data);
184 mem_live = mem_live->next;
190 * _priv_gst_alloc_trace_dump:
192 * Print the status of all registered alloc trace objects.
195 _priv_gst_alloc_trace_dump (void)
199 orig = walk = gst_alloc_trace_list_sorted ();
202 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
204 gst_alloc_trace_print (trace);
206 walk = g_list_next (walk);