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 #define 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;
131 gst_trace_set_default (GstTrace * trace)
133 g_return_if_fail (trace != NULL);
134 _gst_trace_default = trace;
138 _gst_trace_add_entry (GstTrace * trace, guint32 seq, guint32 data, gchar * msg)
140 GstTraceEntry *entry;
143 trace = _gst_trace_default;
148 entry = trace->buf + trace->bufoffset;
149 read_tsc (&(entry->timestamp));
150 entry->sequence = seq;
152 strncpy (entry->message, msg, 112);
155 gst_trace_flush (trace);
160 static GstAllocTraceFlags _gst_trace_flags = 0;
161 /* list of registered tracers */
162 static GList *_gst_alloc_tracers = NULL;
165 * gst_alloc_trace_available:
167 * Check if alloc tracing was commiled into the core
169 * Returns: TRUE if the core was compiled with alloc
173 gst_alloc_trace_available (void)
175 #ifdef GST_DISABLE_ALLOC_TRACE
183 * _gst_alloc_trace_register:
184 * @name: the name of the new alloc trace object.
186 * Register an get a handle to a GstAllocTrace object that
187 * can be used to trace memory allocations.
189 * Returns: A handle to a GstAllocTrace.
192 _gst_alloc_trace_register (const gchar *name)
194 GstAllocTrace *trace;
196 g_return_val_if_fail (name, NULL);
198 trace = g_new0 (GstAllocTrace, 1);
199 trace->name = g_strdup (name);
201 trace->mem_live = NULL;
202 trace->flags = _gst_trace_flags;
204 _gst_alloc_tracers = g_list_prepend (_gst_alloc_tracers, trace);
210 * gst_alloc_trace_list:
212 * Get a list of all registered alloc trace objects.
214 * Returns: a GList of GstAllocTrace objects.
217 gst_alloc_trace_list (void)
219 return _gst_alloc_tracers;
223 * gst_alloc_trace_live_all:
225 * Returns the total number of live registered alloc trace objects.
228 gst_alloc_trace_live_all (void)
230 GList *walk = _gst_alloc_tracers;
234 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
238 walk = g_list_next (walk);
245 * gst_alloc_trace_print_all:
247 * Print the status of all registered alloc trace objectes.
250 gst_alloc_trace_print_all (void)
252 GList *walk = _gst_alloc_tracers;
255 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
257 gst_alloc_trace_print (trace);
259 walk = g_list_next (walk);
264 * gst_alloc_trace_set_flags_all:
265 * @flags: the options to enable
267 * Enable the specified options on all registered alloc trace
271 gst_alloc_trace_set_flags_all (GstAllocTraceFlags flags)
273 GList *walk = _gst_alloc_tracers;
276 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
278 g_print ("set flags on %p\n", trace);
279 gst_alloc_trace_set_flags (trace, flags);
281 walk = g_list_next (walk);
283 _gst_trace_flags = flags;
287 * gst_alloc_trace_get:
288 * @name: the name of the alloc trace object
290 * Get the named alloc trace object.
292 * Returns: a GstAllocTrace with the given name or NULL when
293 * no alloc tracer was registered with that name.
296 gst_alloc_trace_get (const gchar *name)
298 GList *walk = _gst_alloc_tracers;
300 g_return_val_if_fail (name, NULL);
303 GstAllocTrace *trace = (GstAllocTrace *) walk->data;
305 if (!strcmp (trace->name, name))
308 walk = g_list_next (walk);
314 * gst_alloc_trace_print:
315 * @trace: the GstAllocTrace to print
317 * Print the status of the given GstAllocTrace.
320 gst_alloc_trace_print (const GstAllocTrace *trace)
324 g_return_if_fail (trace != NULL);
326 g_print ("%s (%p): flags %d", trace->name, trace, trace->flags);
328 if (trace->flags & GST_ALLOC_TRACE_LIVE) {
329 g_print (", live %d", trace->live);
331 if (trace->flags & GST_ALLOC_TRACE_MEM_LIVE) {
332 mem_live = trace->mem_live;
335 g_print (", no live memory");
338 g_print (", dumping live memory: ");
341 g_print ("%p ", mem_live->data);
342 mem_live = g_slist_next (mem_live);
344 g_print ("\ntotal %d", g_slist_length (trace->mem_live));
351 * gst_alloc_trace_set_flags:
352 * @trace: the GstAllocTrace
353 * @flags: flags to set
355 * Enable the given features on the given GstAllocTrace object.
358 gst_alloc_trace_set_flags (GstAllocTrace *trace, GstAllocTraceFlags flags)
360 g_return_if_fail (trace != NULL);
362 trace->flags = flags;