X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Ftrace%2Ftr_dump.c;h=b173b8abf894f0bb6f4eda575d1ba499f3e81d04;hb=676931640fe6c97f6a5702196c39f8de36b22a64;hp=90befb09b6bb2719b4a7ea4168a19f8270977005;hpb=ce10624e9e827921b503962e2eb04ce0eb06246a;p=mesa.git diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c index 90befb09b6b..b173b8abf89 100644 --- a/src/gallium/drivers/trace/tr_dump.c +++ b/src/gallium/drivers/trace/tr_dump.c @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2008 VMware, Inc. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -18,7 +18,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -35,7 +35,7 @@ * is abstracted out of this file, so that we can switch to a binary * representation if/when it becomes justified. * - * @author Jose Fonseca + * @author Jose Fonseca */ #include "pipe/p_config.h" @@ -45,6 +45,7 @@ #include "pipe/p_compiler.h" #include "os/os_thread.h" +#include "os/os_time.h" #include "util/u_debug.h" #include "util/u_memory.h" #include "util/u_string.h" @@ -56,14 +57,14 @@ #include "tr_texture.h" +static boolean close_stream = FALSE; static FILE *stream = NULL; -static unsigned refcount = 0; pipe_static_mutex(call_mutex); static long unsigned call_no = 0; static boolean dumping = FALSE; -static INLINE void +static inline void trace_dump_write(const char *buf, size_t size) { if (stream) { @@ -72,14 +73,14 @@ trace_dump_write(const char *buf, size_t size) } -static INLINE void +static inline void trace_dump_writes(const char *s) { trace_dump_write(s, strlen(s)); } -static INLINE void +static inline void trace_dump_writef(const char *format, ...) { static char buf[1024]; @@ -92,7 +93,7 @@ trace_dump_writef(const char *format, ...) } -static INLINE void +static inline void trace_dump_escape(const char *str) { const unsigned char *p = (const unsigned char *)str; @@ -116,7 +117,7 @@ trace_dump_escape(const char *str) } -static INLINE void +static inline void trace_dump_indent(unsigned level) { unsigned i; @@ -125,14 +126,14 @@ trace_dump_indent(unsigned level) } -static INLINE void +static inline void trace_dump_newline(void) { trace_dump_writes("\n"); } -static INLINE void +static inline void trace_dump_tag(const char *name) { trace_dump_writes("<"); @@ -141,7 +142,7 @@ trace_dump_tag(const char *name) } -static INLINE void +static inline void trace_dump_tag_begin(const char *name) { trace_dump_writes("<"); @@ -149,7 +150,7 @@ trace_dump_tag_begin(const char *name) trace_dump_writes(">"); } -static INLINE void +static inline void trace_dump_tag_begin1(const char *name, const char *attr1, const char *value1) { @@ -163,7 +164,7 @@ trace_dump_tag_begin1(const char *name, } -static INLINE void +static inline void trace_dump_tag_begin2(const char *name, const char *attr1, const char *value1, const char *attr2, const char *value2) @@ -182,7 +183,7 @@ trace_dump_tag_begin2(const char *name, } -static INLINE void +static inline void trace_dump_tag_begin3(const char *name, const char *attr1, const char *value1, const char *attr2, const char *value2, @@ -206,7 +207,7 @@ trace_dump_tag_begin3(const char *name, } -static INLINE void +static inline void trace_dump_tag_end(const char *name) { trace_dump_writes("\n"); - fclose(stream); - stream = NULL; - refcount = 0; + if (close_stream) { + fclose(stream); + close_stream = FALSE; + stream = NULL; + } call_no = 0; } } -boolean trace_dump_trace_begin() + +static void +trace_dump_call_time(int64_t time) +{ + if (stream) { + trace_dump_indent(2); + trace_dump_tag_begin("time"); + trace_dump_int(time); + trace_dump_tag_end("time"); + trace_dump_newline(); + } +} + + +boolean +trace_dump_trace_begin(void) { const char *filename; filename = debug_get_option("GALLIUM_TRACE", NULL); - if(!filename) + if (!filename) return FALSE; - if(!stream) { - - stream = fopen(filename, "wt"); - if(!stream) - return FALSE; + if (!stream) { + + if (strcmp(filename, "stderr") == 0) { + close_stream = FALSE; + stream = stderr; + } + else if (strcmp(filename, "stdout") == 0) { + close_stream = FALSE; + stream = stdout; + } + else { + close_stream = TRUE; + stream = fopen(filename, "wt"); + if (!stream) + return FALSE; + } trace_dump_writes("\n"); trace_dump_writes("\n"); trace_dump_writes("\n"); -#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) - /* Linux applications rarely cleanup GL / Gallium resources so catch - * application exit here */ + /* Many applications don't exit cleanly, others may create and destroy a + * screen multiple times, so we only write tag and close at exit + * time. + */ atexit(trace_dump_trace_close); -#endif } - ++refcount; - return TRUE; } @@ -269,13 +296,6 @@ boolean trace_dump_trace_enabled(void) return stream ? TRUE : FALSE; } -void trace_dump_trace_end(void) -{ - if(stream) - if(!--refcount) - trace_dump_trace_close(); -} - /* * Call lock */ @@ -336,6 +356,8 @@ boolean trace_dumping_enabled(void) * Dump functions */ +static int64_t call_start_time = 0; + void trace_dump_call_begin_locked(const char *klass, const char *method) { if (!dumping) @@ -351,13 +373,20 @@ void trace_dump_call_begin_locked(const char *klass, const char *method) trace_dump_escape(method); trace_dump_writes("\'>"); trace_dump_newline(); + + call_start_time = os_time_get(); } void trace_dump_call_end_locked(void) { + int64_t call_end_time; + if (!dumping) return; + call_end_time = os_time_get(); + + trace_dump_call_time(call_end_time - call_start_time); trace_dump_indent(1); trace_dump_tag_end("call"); trace_dump_newline(); @@ -466,19 +495,28 @@ void trace_dump_bytes(const void *data, } void trace_dump_box_bytes(const void *data, - enum pipe_format format, + struct pipe_resource *resource, const struct pipe_box *box, unsigned stride, unsigned slice_stride) { size_t size; - if (slice_stride) - size = box->depth * slice_stride; - else if (stride) - size = util_format_get_nblocksy(format, box->height) * stride; - else { - size = util_format_get_nblocksx(format, box->width) * util_format_get_blocksize(format); + /* + * Only dump buffer transfers to avoid huge files. + * TODO: Make this run-time configurable + */ + if (resource->target != PIPE_BUFFER) { + size = 0; + } else { + enum pipe_format format = resource->format; + if (slice_stride) + size = box->depth * slice_stride; + else if (stride) + size = util_format_get_nblocksy(format, box->height) * stride; + else { + size = util_format_get_nblocksx(format, box->width) * util_format_get_blocksize(format); + } } trace_dump_bytes(data, size);