2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gsttrace.c: Tracing functions (depracated)
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.
26 #include <sys/types.h>
31 #include "gst_private.h"
41 read_tsc (gint64 * dst)
45 __asm__ __volatile__ ("rdtsc":"=A" (tsc));
54 gst_trace_read_tsc (gint64 * dst)
59 GstTrace *_gst_trace_default = NULL;
60 gint _gst_trace_on = 1;
63 gst_trace_new (gchar * filename, gint size)
65 GstTrace *trace = g_malloc (sizeof (GstTrace));
67 g_return_val_if_fail (trace != NULL, NULL);
68 trace->filename = g_strdup (filename);
69 g_print ("opening '%s'\n", trace->filename);
71 open (trace->filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
72 perror ("opening trace file");
73 g_return_val_if_fail (trace->fd > 0, NULL);
74 trace->buf = g_malloc (size * sizeof (GstTraceEntry));
75 g_return_val_if_fail (trace->buf != NULL, NULL);
76 trace->bufsize = size;
83 gst_trace_destroy (GstTrace * trace)
85 g_return_if_fail (trace != NULL);
86 g_return_if_fail (trace->buf != NULL);
88 if (gst_trace_get_remaining (trace) > 0)
89 gst_trace_flush (trace);
96 gst_trace_flush (GstTrace * trace)
99 trace = _gst_trace_default;
104 write (trace->fd, trace->buf, trace->bufoffset * sizeof (GstTraceEntry));
105 trace->bufoffset = 0;
109 gst_trace_text_flush (GstTrace * trace)
113 #define STRSIZE (20 + 1 + 10 + 1 + 10 + 1 + 112 + 1 + 1)
117 trace = _gst_trace_default;
122 for (i = 0; i < trace->bufoffset; i++) {
123 snprintf (str, STRSIZE, "%20" G_GINT64_FORMAT " %10d %10d %s\n",
124 trace->buf[i].timestamp,
125 trace->buf[i].sequence, trace->buf[i].data, trace->buf[i].message);
126 write (trace->fd, str, strlen (str));
128 trace->bufoffset = 0;
133 gst_trace_set_default (GstTrace * trace)
135 g_return_if_fail (trace != NULL);
136 _gst_trace_default = trace;
140 _gst_trace_add_entry (GstTrace * trace, guint32 seq, guint32 data, gchar * msg)
142 GstTraceEntry *entry;
145 trace = _gst_trace_default;
150 entry = trace->buf + trace->bufoffset;
151 read_tsc (&(entry->timestamp));
152 entry->sequence = seq;
154 strncpy (entry->message, msg, 112);
157 gst_trace_flush (trace);
162 static GstAllocTraceFlags _gst_trace_flags = 0;
164 /* list of registered tracers */
165 static GList *_gst_alloc_tracers = NULL;
168 * gst_alloc_trace_available:
170 * Check if alloc tracing was commiled into the core
172 * Returns: TRUE if the core was compiled with alloc
176 gst_alloc_trace_available (void)
178 #ifdef GST_DISABLE_ALLOC_TRACE
186 * _gst_alloc_trace_register:
187 * @name: the name of the new alloc trace object.
189 * Register an get a handle to a GstAllocTrace object that
190 * can be used to trace memory allocations.
192 * Returns: A handle to a GstAllocTrace.
195 _gst_alloc_trace_register (const gchar * name)
197 GstAllocTrace *trace;
199 g_return_val_if_fail (name, NULL);
201 trace = g_new0 (GstAllocTrace, 1);
202 trace->name = g_strdup (name);
204 trace->mem_live = NULL;
205 trace->flags = _gst_trace_flags;
207 _gst_alloc_tracers = g_list_prepend (_gst_alloc_tracers, trace);
213 * gst_alloc_trace_list:
215 * Get a list of all registered alloc trace objects.
217 * Returns: a GList of GstAllocTrace objects.
220 gst_alloc_trace_list (void)
222 return _gst_alloc_tracers;
226 * gst_alloc_trace_live_all:
228 * Returns the total number of live registered alloc trace objects.
231 gst_alloc_trace_live_all (void)
233 GList *walk = _gst_alloc_tracers;
237 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
241 walk = g_list_next (walk);
248 * gst_alloc_trace_print_all:
250 * Print the status of all registered alloc trace objectes.
253 gst_alloc_trace_print_all (void)
255 GList *walk = _gst_alloc_tracers;
258 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
260 gst_alloc_trace_print (trace);
262 walk = g_list_next (walk);
267 * gst_alloc_trace_set_flags_all:
268 * @flags: the options to enable
270 * Enable the specified options on all registered alloc trace
274 gst_alloc_trace_set_flags_all (GstAllocTraceFlags flags)
276 GList *walk = _gst_alloc_tracers;
279 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
281 g_print ("set flags on %p\n", trace);
282 gst_alloc_trace_set_flags (trace, flags);
284 walk = g_list_next (walk);
286 _gst_trace_flags = flags;
290 * gst_alloc_trace_get:
291 * @name: the name of the alloc trace object
293 * Get the named alloc trace object.
295 * Returns: a GstAllocTrace with the given name or NULL when
296 * no alloc tracer was registered with that name.
299 gst_alloc_trace_get (const gchar * name)
301 GList *walk = _gst_alloc_tracers;
303 g_return_val_if_fail (name, NULL);
306 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
308 if (!strcmp (trace->name, name))
311 walk = g_list_next (walk);
317 * gst_alloc_trace_print:
318 * @trace: the GstAllocTrace to print
320 * Print the status of the given GstAllocTrace.
323 gst_alloc_trace_print (const GstAllocTrace * trace)
327 g_return_if_fail (trace != NULL);
329 g_print ("%s (%p): flags %d", trace->name, trace, trace->flags);
331 if (trace->flags & GST_ALLOC_TRACE_LIVE) {
332 g_print (", live %d", trace->live);
334 if (trace->flags & GST_ALLOC_TRACE_MEM_LIVE) {
335 mem_live = trace->mem_live;
338 g_print (", no live memory");
340 g_print (", dumping live memory: ");
343 g_print ("%p ", mem_live->data);
344 mem_live = g_slist_next (mem_live);
346 g_print ("\ntotal %d", g_slist_length (trace->mem_live));
353 * gst_alloc_trace_set_flags:
354 * @trace: the GstAllocTrace
355 * @flags: flags to set
357 * Enable the given features on the given GstAllocTrace object.
360 gst_alloc_trace_set_flags (GstAllocTrace * trace, GstAllocTraceFlags flags)
362 g_return_if_fail (trace != NULL);
364 trace->flags = flags;