2000-12-28 22:12:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gsttrace.c: Tracing functions (depracated)
|
2000-01-30 09:03:00 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
2000-12-15 01:57:34 +00:00
|
|
|
|
2000-12-28 22:12:02 +00:00
|
|
|
#include "gst_private.h"
|
|
|
|
|
2001-09-13 23:06:47 +00:00
|
|
|
#include "gstlog.h"
|
2000-12-15 01:57:34 +00:00
|
|
|
#include "gsttrace.h"
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
static __inline__ void
|
|
|
|
read_tsc (guint64 * dst)
|
|
|
|
{
|
2001-05-16 05:04:44 +00:00
|
|
|
#ifdef HAVE_RDTSC
|
|
|
|
guint64 tsc;
|
2001-12-04 22:12:50 +00:00
|
|
|
__asm__ __volatile__ ("rdtsc":"=A" (tsc));
|
|
|
|
|
2001-05-16 05:04:44 +00:00
|
|
|
*dst = tsc;
|
2000-08-18 22:15:58 +00:00
|
|
|
#else
|
2001-05-16 05:04:44 +00:00
|
|
|
*dst = 0;
|
2000-08-18 22:15:58 +00:00
|
|
|
#endif
|
2001-05-16 05:04:44 +00:00
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
void
|
|
|
|
gst_trace_read_tsc (guint64 * dst)
|
|
|
|
{
|
|
|
|
read_tsc (dst);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GstTrace *_gst_trace_default = NULL;
|
|
|
|
gint _gst_trace_on = 1;
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GstTrace *
|
|
|
|
gst_trace_new (guchar * filename, gint size)
|
|
|
|
{
|
|
|
|
GstTrace *trace = g_malloc (sizeof (GstTrace));
|
|
|
|
|
|
|
|
g_return_val_if_fail (trace != NULL, NULL);
|
|
|
|
trace->filename = g_strdup (filename);
|
|
|
|
g_print ("opening '%s'\n", trace->filename);
|
|
|
|
trace->fd = open (trace->filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
|
|
|
perror ("opening trace file");
|
|
|
|
g_return_val_if_fail (trace->fd > 0, NULL);
|
|
|
|
trace->buf = g_malloc (size * sizeof (GstTraceEntry));
|
|
|
|
g_return_val_if_fail (trace->buf != NULL, NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
trace->bufsize = size;
|
|
|
|
trace->bufoffset = 0;
|
|
|
|
|
|
|
|
return trace;
|
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
void
|
|
|
|
gst_trace_destroy (GstTrace * trace)
|
|
|
|
{
|
|
|
|
g_return_if_fail (trace != NULL);
|
|
|
|
g_return_if_fail (trace->buf != NULL);
|
|
|
|
|
|
|
|
if (gst_trace_get_remaining (trace) > 0)
|
|
|
|
gst_trace_flush (trace);
|
|
|
|
close (trace->fd);
|
|
|
|
g_free (trace->buf);
|
|
|
|
g_free (trace);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
void
|
|
|
|
gst_trace_flush (GstTrace * trace)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
if (!trace) {
|
|
|
|
trace = _gst_trace_default;
|
2001-12-04 22:12:50 +00:00
|
|
|
if (!trace)
|
|
|
|
return;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
write (trace->fd, trace->buf, trace->bufoffset * sizeof (GstTraceEntry));
|
2000-01-30 09:03:00 +00:00
|
|
|
trace->bufoffset = 0;
|
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
void
|
|
|
|
gst_trace_text_flush (GstTrace * trace)
|
|
|
|
{
|
2001-05-16 05:04:44 +00:00
|
|
|
int i;
|
2001-12-04 22:12:50 +00:00
|
|
|
const int strsize = 20 + 1 + 10 + 1 + 10 + 1 + 112 + 1 + 1;
|
2001-05-16 05:04:44 +00:00
|
|
|
char str[strsize];
|
|
|
|
|
|
|
|
if (!trace) {
|
|
|
|
trace = _gst_trace_default;
|
2001-12-04 22:12:50 +00:00
|
|
|
if (!trace)
|
|
|
|
return;
|
2001-05-16 05:04:44 +00:00
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
for (i = 0; i < trace->bufoffset; i++) {
|
|
|
|
snprintf (str, strsize, "%20lld %10d %10d %s\n",
|
|
|
|
trace->buf[i].timestamp,
|
|
|
|
trace->buf[i].sequence, trace->buf[i].data, trace->buf[i].message);
|
|
|
|
write (trace->fd, str, strlen (str));
|
2001-05-16 05:04:44 +00:00
|
|
|
}
|
|
|
|
trace->bufoffset = 0;
|
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
void
|
|
|
|
gst_trace_set_default (GstTrace * trace)
|
|
|
|
{
|
|
|
|
g_return_if_fail (trace != NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
_gst_trace_default = trace;
|
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
void
|
|
|
|
_gst_trace_add_entry (GstTrace * trace, guint32 seq, guint32 data, gchar * msg)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstTraceEntry *entry;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
if (!trace) {
|
|
|
|
trace = _gst_trace_default;
|
2001-12-04 22:12:50 +00:00
|
|
|
if (!trace)
|
|
|
|
return;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
entry = trace->buf + trace->bufoffset;
|
2001-12-04 22:12:50 +00:00
|
|
|
read_tsc (&(entry->timestamp));
|
2000-01-30 09:03:00 +00:00
|
|
|
entry->sequence = seq;
|
|
|
|
entry->data = data;
|
2001-12-04 22:12:50 +00:00
|
|
|
strncpy (entry->message, msg, 112);
|
2000-01-30 09:03:00 +00:00
|
|
|
trace->bufoffset++;
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_trace_flush (trace);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|