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);
70 trace->fd = open (trace->filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
71 perror ("opening trace file");
72 g_return_val_if_fail (trace->fd > 0, NULL);
73 trace->buf = g_malloc (size * sizeof (GstTraceEntry));
74 g_return_val_if_fail (trace->buf != NULL, NULL);
75 trace->bufsize = size;
82 gst_trace_destroy (GstTrace * trace)
84 g_return_if_fail (trace != NULL);
85 g_return_if_fail (trace->buf != NULL);
87 if (gst_trace_get_remaining (trace) > 0)
88 gst_trace_flush (trace);
95 gst_trace_flush (GstTrace * trace)
98 trace = _gst_trace_default;
103 write (trace->fd, trace->buf, trace->bufoffset * sizeof (GstTraceEntry));
104 trace->bufoffset = 0;
108 gst_trace_text_flush (GstTrace * trace)
111 const int strsize = 20 + 1 + 10 + 1 + 10 + 1 + 112 + 1 + 1;
115 trace = _gst_trace_default;
120 for (i = 0; i < trace->bufoffset; i++) {
121 snprintf (str, strsize, "%20" G_GINT64_FORMAT " %10d %10d %s\n",
122 trace->buf[i].timestamp,
123 trace->buf[i].sequence, trace->buf[i].data, trace->buf[i].message);
124 write (trace->fd, str, strlen (str));
126 trace->bufoffset = 0;
130 gst_trace_set_default (GstTrace * trace)
132 g_return_if_fail (trace != NULL);
133 _gst_trace_default = trace;
137 _gst_trace_add_entry (GstTrace * trace, guint32 seq, guint32 data, gchar * msg)
139 GstTraceEntry *entry;
142 trace = _gst_trace_default;
147 entry = trace->buf + trace->bufoffset;
148 read_tsc (&(entry->timestamp));
149 entry->sequence = seq;
151 strncpy (entry->message, msg, 112);
154 gst_trace_flush (trace);
159 static GstAllocTraceFlags _gst_trace_flags = 0;
160 /* list of registered tracers */
161 static GList *_gst_alloc_tracers = NULL;
164 * gst_alloc_trace_available:
166 * Check if alloc tracing was commiled into the core
168 * Returns: TRUE if the core was compiled with alloc
172 gst_alloc_trace_available (void)
174 #ifdef GST_DISABLE_ALLOC_TRACE
182 * _gst_alloc_trace_register:
183 * @name: the name of the new alloc trace object.
185 * Register an get a handle to a GstAllocTrace object that
186 * can be used to trace memory allocations.
188 * Returns: A handle to a GstAllocTrace.
191 _gst_alloc_trace_register (const gchar *name)
193 GstAllocTrace *trace;
195 g_return_val_if_fail (name, NULL);
197 trace = g_new0 (GstAllocTrace, 1);
198 trace->name = g_strdup (name);
200 trace->mem_live = NULL;
201 trace->flags = _gst_trace_flags;
203 _gst_alloc_tracers = g_list_prepend (_gst_alloc_tracers, trace);
209 * gst_alloc_trace_list:
211 * Get a list of all registered alloc trace objects.
213 * Returns: a GList of GstAllocTrace objects.
216 gst_alloc_trace_list (void)
218 return _gst_alloc_tracers;
222 * gst_alloc_trace_live_all:
224 * Returns the total number of live registered alloc trace objects.
227 gst_alloc_trace_live_all (void)
229 GList *walk = _gst_alloc_tracers;
233 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
237 walk = g_list_next (walk);
244 * gst_alloc_trace_print_all:
246 * Print the status of all registered alloc trace objectes.
249 gst_alloc_trace_print_all (void)
251 GList *walk = _gst_alloc_tracers;
254 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
256 gst_alloc_trace_print (trace);
258 walk = g_list_next (walk);
263 * gst_alloc_trace_set_flags_all:
264 * @flags: the options to enable
266 * Enable the specified options on all registered alloc trace
270 gst_alloc_trace_set_flags_all (GstAllocTraceFlags flags)
272 GList *walk = _gst_alloc_tracers;
275 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
277 g_print ("set flags on %p\n", trace);
278 gst_alloc_trace_set_flags (trace, flags);
280 walk = g_list_next (walk);
282 _gst_trace_flags = flags;
286 * gst_alloc_trace_get:
287 * @name: the name of the alloc trace object
289 * Get the named alloc trace object.
291 * Returns: a GstAllocTrace with the given name or NULL when
292 * no alloc tracer was registered with that name.
295 gst_alloc_trace_get (const gchar *name)
297 GList *walk = _gst_alloc_tracers;
299 g_return_val_if_fail (name, NULL);
302 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
304 if (!strcmp (trace->name, name))
307 walk = g_list_next (walk);
313 * gst_alloc_trace_print:
314 * @trace: the GstAllocTrace to print
316 * Print the status of the given GstAllocTrace.
319 gst_alloc_trace_print (const GstAllocTrace *trace)
323 g_return_if_fail (trace != NULL);
325 g_print ("%s (%p): flags %d", trace->name, trace, trace->flags);
327 if (trace->flags & GST_ALLOC_TRACE_LIVE) {
328 g_print (", live %d", trace->live);
330 if (trace->flags & GST_ALLOC_TRACE_MEM_LIVE) {
331 mem_live = trace->mem_live;
334 g_print (", no live memory");
337 g_print (", dumping live memory: ");
340 g_print ("%p ", mem_live->data);
341 mem_live = g_slist_next (mem_live);
343 g_print ("\ntotal %d", g_slist_length (trace->mem_live));
350 * gst_alloc_trace_set_flags:
351 * @trace: the GstAllocTrace
352 * @flags: flags to set
354 * Enable the given features on the given GstAllocTrace object.
357 gst_alloc_trace_set_flags (GstAllocTrace *trace, GstAllocTraceFlags flags)
359 g_return_if_fail (trace != NULL);
361 trace->flags = flags;