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.
35 #include "gst_private.h"
44 read_tsc (gint64 * dst)
48 __asm__ __volatile__ ("rdtsc":"=A" (tsc));
57 gst_trace_read_tsc (gint64 * dst)
62 GstTrace *_gst_trace_default = NULL;
63 gint _gst_trace_on = 1;
66 gst_trace_new (gchar * filename, gint size)
68 GstTrace *trace = g_malloc (sizeof (GstTrace));
70 g_return_val_if_fail (trace != NULL, NULL);
71 trace->filename = g_strdup (filename);
72 g_print ("opening '%s'\n", trace->filename);
74 #define S_IWUSR S_IWRITE
77 #define S_IDUSR S_IREAD
80 open (trace->filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
81 perror ("opening trace file");
82 g_return_val_if_fail (trace->fd > 0, NULL);
83 trace->buf = g_malloc (size * sizeof (GstTraceEntry));
84 g_return_val_if_fail (trace->buf != NULL, NULL);
85 trace->bufsize = size;
92 gst_trace_destroy (GstTrace * trace)
94 g_return_if_fail (trace != NULL);
95 g_return_if_fail (trace->buf != NULL);
97 if (gst_trace_get_remaining (trace) > 0)
98 gst_trace_flush (trace);
105 gst_trace_flush (GstTrace * trace)
108 trace = _gst_trace_default;
113 write (trace->fd, trace->buf, trace->bufoffset * sizeof (GstTraceEntry));
114 trace->bufoffset = 0;
118 gst_trace_text_flush (GstTrace * trace)
122 #define STRSIZE (20 + 1 + 10 + 1 + 10 + 1 + 112 + 1 + 1)
126 trace = _gst_trace_default;
131 for (i = 0; i < trace->bufoffset; i++) {
132 g_snprintf (str, STRSIZE, "%20" G_GINT64_FORMAT " %10d %10d %s\n",
133 trace->buf[i].timestamp,
134 trace->buf[i].sequence, trace->buf[i].data, trace->buf[i].message);
135 write (trace->fd, str, strlen (str));
137 trace->bufoffset = 0;
142 gst_trace_set_default (GstTrace * trace)
144 g_return_if_fail (trace != NULL);
145 _gst_trace_default = trace;
149 _gst_trace_add_entry (GstTrace * trace, guint32 seq, guint32 data, gchar * msg)
151 GstTraceEntry *entry;
154 trace = _gst_trace_default;
159 entry = trace->buf + trace->bufoffset;
160 read_tsc (&(entry->timestamp));
161 entry->sequence = seq;
163 strncpy (entry->message, msg, 112);
166 gst_trace_flush (trace);
171 static GstAllocTraceFlags _gst_trace_flags = 0;
173 /* list of registered tracers */
174 static GList *_gst_alloc_tracers = NULL;
177 * gst_alloc_trace_available:
179 * Check if alloc tracing was commiled into the core
181 * Returns: TRUE if the core was compiled with alloc
185 gst_alloc_trace_available (void)
187 #ifdef GST_DISABLE_ALLOC_TRACE
195 * _gst_alloc_trace_register:
196 * @name: the name of the new alloc trace object.
198 * Register an get a handle to a GstAllocTrace object that
199 * can be used to trace memory allocations.
201 * Returns: A handle to a GstAllocTrace.
204 _gst_alloc_trace_register (const gchar * name)
206 GstAllocTrace *trace;
208 g_return_val_if_fail (name, NULL);
210 trace = g_new0 (GstAllocTrace, 1);
211 trace->name = g_strdup (name);
213 trace->mem_live = NULL;
214 trace->flags = _gst_trace_flags;
216 _gst_alloc_tracers = g_list_prepend (_gst_alloc_tracers, trace);
222 * gst_alloc_trace_list:
224 * Get a list of all registered alloc trace objects.
226 * Returns: a GList of GstAllocTrace objects.
229 gst_alloc_trace_list (void)
231 return _gst_alloc_tracers;
235 * gst_alloc_trace_live_all:
237 * Returns the total number of live registered alloc trace objects.
240 gst_alloc_trace_live_all (void)
242 GList *walk = _gst_alloc_tracers;
246 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
250 walk = g_list_next (walk);
257 * gst_alloc_trace_print_all:
259 * Print the status of all registered alloc trace objectes.
262 gst_alloc_trace_print_all (void)
264 GList *walk = _gst_alloc_tracers;
267 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
269 gst_alloc_trace_print (trace);
271 walk = g_list_next (walk);
276 * gst_alloc_trace_set_flags_all:
277 * @flags: the options to enable
279 * Enable the specified options on all registered alloc trace
283 gst_alloc_trace_set_flags_all (GstAllocTraceFlags flags)
285 GList *walk = _gst_alloc_tracers;
288 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
290 g_print ("set flags on %p\n", trace);
291 gst_alloc_trace_set_flags (trace, flags);
293 walk = g_list_next (walk);
295 _gst_trace_flags = flags;
299 * gst_alloc_trace_get:
300 * @name: the name of the alloc trace object
302 * Get the named alloc trace object.
304 * Returns: a GstAllocTrace with the given name or NULL when
305 * no alloc tracer was registered with that name.
308 gst_alloc_trace_get (const gchar * name)
310 GList *walk = _gst_alloc_tracers;
312 g_return_val_if_fail (name, NULL);
315 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
317 if (!strcmp (trace->name, name))
320 walk = g_list_next (walk);
326 * gst_alloc_trace_print:
327 * @trace: the GstAllocTrace to print
329 * Print the status of the given GstAllocTrace.
332 gst_alloc_trace_print (const GstAllocTrace * trace)
336 g_return_if_fail (trace != NULL);
338 g_print ("%s (%p): flags %d", trace->name, trace, trace->flags);
340 if (trace->flags & GST_ALLOC_TRACE_LIVE) {
341 g_print (", live %d", trace->live);
343 if (trace->flags & GST_ALLOC_TRACE_MEM_LIVE) {
344 mem_live = trace->mem_live;
347 g_print (", no live memory");
349 g_print (", dumping live memory: ");
352 g_print ("%p ", mem_live->data);
353 mem_live = g_slist_next (mem_live);
355 g_print ("\ntotal %d", g_slist_length (trace->mem_live));
362 * gst_alloc_trace_set_flags:
363 * @trace: the GstAllocTrace
364 * @flags: flags to set
366 * Enable the given features on the given GstAllocTrace object.
369 gst_alloc_trace_set_flags (GstAllocTrace * trace, GstAllocTraceFlags flags)
371 g_return_if_fail (trace != NULL);
373 trace->flags = flags;