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);