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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
35 #if defined (_MSC_VER) && _MSC_VER >= 1400
39 #include "gst_private.h"
44 GMutex _gst_trace_mutex;
47 static GstAllocTraceFlags _gst_trace_flags = GST_ALLOC_TRACE_NONE;
49 /* list of registered tracers */
50 static GList *_gst_alloc_tracers = NULL;
56 _priv_gst_alloc_trace_dump ();
60 _priv_gst_alloc_trace_initialize (void)
64 trace = g_getenv ("GST_TRACE");
66 const GDebugKey keys[] = {
67 {"live", GST_ALLOC_TRACE_LIVE},
68 {"mem-live", GST_ALLOC_TRACE_MEM_LIVE},
70 _gst_trace_flags = g_parse_debug_string (trace, keys, G_N_ELEMENTS (keys));
74 g_mutex_init (&_gst_trace_mutex);
78 _priv_gst_alloc_trace_deinit (void)
80 g_mutex_clear (&_gst_trace_mutex);
84 * _priv_gst_alloc_trace_register:
85 * @name: the name of the new alloc trace object.
86 * @offset: the offset in the object where a GType an be found. -1 when the
87 * object has no gtype.
89 * Register an get a handle to a GstAllocTrace object that
90 * can be used to trace memory allocations.
92 * Returns: A handle to a GstAllocTrace.
95 _priv_gst_alloc_trace_register (const gchar * name, goffset offset)
99 g_return_val_if_fail (name, NULL);
101 trace = g_slice_new (GstAllocTrace);
102 trace->name = g_strdup (name);
104 trace->mem_live = NULL;
105 trace->flags = _gst_trace_flags;
106 trace->offset = offset;
108 _gst_alloc_tracers = g_list_prepend (_gst_alloc_tracers, trace);
114 compare_func (GstAllocTrace * a, GstAllocTrace * b)
116 return strcmp (a->name, b->name);
120 gst_alloc_trace_list_sorted (void)
124 ret = g_list_sort (g_list_copy (_gst_alloc_tracers),
125 (GCompareFunc) compare_func);
131 gst_alloc_trace_print (const GstAllocTrace * trace)
135 g_return_if_fail (trace != NULL);
137 if (trace->flags & GST_ALLOC_TRACE_LIVE) {
138 g_print ("%-22.22s : %d\n", trace->name, trace->live);
140 g_print ("%-22.22s : (no live count)\n", trace->name);
143 if (trace->flags & GST_ALLOC_TRACE_MEM_LIVE) {
144 mem_live = trace->mem_live;
147 gpointer data = mem_live->data;
148 const gchar *type_name;
152 if (trace->offset == -2) {
153 if (G_IS_OBJECT (data)) {
154 type_name = G_OBJECT_TYPE_NAME (data);
155 refcount = G_OBJECT (data)->ref_count;
157 type_name = "<invalid>";
158 } else if (trace->offset == -1) {
159 type_name = "<unknown>";
163 type = G_STRUCT_MEMBER (GType, data, trace->offset);
164 type_name = g_type_name (type);
166 if (type == GST_TYPE_CAPS) {
167 extra = gst_caps_to_string (data);
169 refcount = GST_MINI_OBJECT_REFCOUNT_VALUE (data);
173 g_print (" %-20.20s : (%d) %p (\"%s\")\n", type_name, refcount, data,
177 g_print (" %-20.20s : (%d) %p\n", type_name, refcount, data);
179 mem_live = mem_live->next;
185 * _priv_gst_alloc_trace_dump:
187 * Print the status of all registered alloc trace objects.
190 _priv_gst_alloc_trace_dump (void)
194 orig = walk = gst_alloc_trace_list_sorted ();
197 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
199 gst_alloc_trace_print (trace);
201 walk = g_list_next (walk);