trace: Allow multiple screens. Flush after call.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Fri, 15 Aug 2008 09:24:09 +0000 (10:24 +0100)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Fri, 15 Aug 2008 09:35:19 +0000 (10:35 +0100)
src/gallium/drivers/trace/tr_dump.c
src/gallium/drivers/trace/tr_dump.h
src/gallium/drivers/trace/tr_stream.c
src/gallium/drivers/trace/tr_stream.h

index 6ebb639b7c716f82a6f0901abb7cc1b10c79e893..c711a56b947bdb8d9c570b253fbbe25c4c90a1c6 100644 (file)
@@ -52,6 +52,7 @@
 
 
 static struct trace_stream *stream = NULL;
+static unsigned refcount = 0;
 
 
 static INLINE void 
@@ -204,35 +205,54 @@ trace_dump_tag_end(const char *name)
    trace_dump_writes(">");
 }
 
+static void 
+trace_dump_trace_close(void)
+{
+   if(stream) {
+      trace_dump_writes("</trace>\n");
+      trace_stream_close(stream);
+      stream = NULL;
+      refcount = 0;
+   }
+}
+
 boolean trace_dump_trace_begin()
 {
    if(!debug_get_bool_option("GALLIUM_TRACE", FALSE))
       return FALSE;
    
-   stream = trace_stream_create("gallium", "trace");
-   if(!stream)
-      return FALSE;
-   
-   trace_dump_writes("<?xml version='1.0' encoding='UTF-8'?>\n");
-   trace_dump_writes("<?xml-stylesheet type='text/xsl' href='trace.xsl'?>\n");
-   trace_dump_writes("<trace version='0.1'>\n");
+   if(!stream) {
    
+      stream = trace_stream_create("gallium", "trace");
+      if(!stream)
+         return FALSE;
+      
+      trace_dump_writes("<?xml version='1.0' encoding='UTF-8'?>\n");
+      trace_dump_writes("<?xml-stylesheet type='text/xsl' href='trace.xsl'?>\n");
+      trace_dump_writes("<trace version='0.1'>\n");
+      
 #if defined(PIPE_OS_LINUX)
-   /* Linux applications rarely cleanup GL / Gallium resources so catch 
-    * application exit here */ 
-   atexit(trace_dump_trace_end);
+      /* Linux applications rarely cleanup GL / Gallium resources so catch 
+       * application exit here */ 
+      atexit(trace_dump_trace_close);
 #endif
+   }
+   
+   ++refcount;
    
    return TRUE;
 }
 
+boolean trace_dump_enabled(void)
+{
+   return stream ? TRUE : FALSE;
+}
+
 void trace_dump_trace_end(void)
 {
-   if(stream) {
-      trace_dump_writes("</trace>\n");
-      trace_stream_close(stream);
-      stream = NULL;
-   }
+   if(stream)
+      if(!--refcount)
+         trace_dump_trace_close();
 }
 
 void trace_dump_call_begin(const char *klass, const char *method)
@@ -247,6 +267,7 @@ void trace_dump_call_end(void)
    trace_dump_indent(1);
    trace_dump_tag_end("call");
    trace_dump_newline();
+   trace_stream_flush(stream);
 }
 
 void trace_dump_arg_begin(const char *name)
@@ -372,7 +393,7 @@ void trace_dump_null(void)
 void trace_dump_ptr(const void *value)
 {
    if(value)
-      trace_dump_writef("<ptr>%p</ptr>", value);
+      trace_dump_writef("<ptr>0x%08lx</ptr>", (unsigned long)(uintptr_t)value);
    else
       trace_dump_null();
 }
index 0beb1023b1515a51f2654404c1420cdd1d2a58c6..14176a78e9746675b3a85938a4c28a88f8bb3bfd 100644 (file)
@@ -39,6 +39,7 @@
 
 
 boolean trace_dump_trace_begin(void);
+boolean trace_dump_enabled(void);
 void trace_dump_trace_end(void);
 void trace_dump_call_begin(const char *klass, const char *method);
 void trace_dump_call_end(void);
index 14cc257e154bdca27b912d65f329b0eabb5078fa..aecc1286b8d2f1c4d4cac9e66347c188c361de35 100644 (file)
@@ -86,6 +86,18 @@ trace_stream_write(struct trace_stream *stream, const void *data, size_t size)
 }
 
 
+void
+trace_stream_flush(struct trace_stream *stream) 
+{
+   if(!stream)
+      return;
+   
+#if defined(PIPE_OS_LINUX)
+   fflush(stream->file);
+#endif
+}
+
+
 void
 trace_stream_close(struct trace_stream *stream) 
 {
index 53e854aa913792768a6965a42babc111ff21e0b1..679c4a725d775228041c4d424ddd421780ea0d82 100644 (file)
@@ -48,6 +48,9 @@ trace_stream_create(const char *name, const char *ext);
 boolean
 trace_stream_write(struct trace_stream *stream, const void *data, size_t size);
 
+void
+trace_stream_flush(struct trace_stream *stream);
+
 void
 trace_stream_close(struct trace_stream *stream);