135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca/**************************************************************************
235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca *
335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * All Rights Reserved.
535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca *
635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * Permission is hereby granted, free of charge, to any person obtaining a
735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * copy of this software and associated documentation files (the
835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * "Software"), to deal in the Software without restriction, including
935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * without limitation the rights to use, copy, modify, merge, publish,
1035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * distribute, sub license, and/or sell copies of the Software, and to
1135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * permit persons to whom the Software is furnished to do so, subject to
1235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * the following conditions:
1335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca *
1435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * The above copyright notice and this permission notice (including the
1535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * next paragraph) shall be included in all copies or substantial portions
1635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * of the Software.
1735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca *
1835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
2235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca *
2635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca **************************************************************************/
2735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
2835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
2935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca/**
3035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * @file
3135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * Trace dumping functions.
32422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz *
3335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * For now we just use standard XML for dumping the trace calls, as this is
34422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz * simple to write, parse, and visually inspect, but the actual representation
35422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz * is abstracted out of this file, so that we can switch to a binary
3635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca * representation if/when it becomes justified.
37422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz *
38422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
3935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca */
4035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
41196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca#include "pipe/p_config.h"
42196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca
4357f8e26ca87a2846f192682c84eccbf8b4500bfcJosé Fonseca#include <stdio.h>
44196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca#include <stdlib.h>
4535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
4635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca#include "pipe/p_compiler.h"
472aaca1df9df6980ec88180c8866c8987b31db91aJosé Fonseca#include "os/os_thread.h"
48ea4bf267e4b023b08043f91ac44592fed1736e7fJosé Fonseca#include "util/u_debug.h"
494f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h"
5035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca#include "util/u_string.h"
51b77583203e44a8937577bf3b813dc66cea1a2005José Fonseca#include "util/u_math.h"
52b77583203e44a8937577bf3b813dc66cea1a2005José Fonseca#include "util/u_format.h"
5335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
5435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca#include "tr_dump.h"
55808f32279964f4e80f0708f737fdf3a901ff51e5Jakob Bornecrantz#include "tr_screen.h"
5653e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz#include "tr_texture.h"
5735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
5835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
5957f8e26ca87a2846f192682c84eccbf8b4500bfcJosé Fonsecastatic FILE *stream = NULL;
60f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonsecastatic unsigned refcount = 0;
61e640eec9ba9e2ff0e462671f6a3c548d2e0c40cfJosé Fonsecapipe_static_mutex(call_mutex);
62d2cdf6253cf06fbed6a5ca7ae17ddadf644afe26José Fonsecastatic long unsigned call_no = 0;
63f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzstatic boolean dumping = FALSE;
64196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca
65196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca
66422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
67196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecatrace_dump_write(const char *buf, size_t size)
6835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
6957f8e26ca87a2846f192682c84eccbf8b4500bfcJosé Fonseca   if (stream) {
7057f8e26ca87a2846f192682c84eccbf8b4500bfcJosé Fonseca      fwrite(buf, size, 1, stream);
7157f8e26ca87a2846f192682c84eccbf8b4500bfcJosé Fonseca   }
7235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
7335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
7435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
75422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
76196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecatrace_dump_writes(const char *s)
7735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
78196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_write(s, strlen(s));
79196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca}
80196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca
81196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca
82422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
83196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecatrace_dump_writef(const char *format, ...)
84196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca{
85196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   static char buf[1024];
86196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   unsigned len;
8735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca   va_list ap;
8835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca   va_start(ap, format);
89196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   len = util_vsnprintf(buf, sizeof(buf), format, ap);
9035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca   va_end(ap);
91196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_write(buf, len);
9235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
9335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
9435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
95422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
96422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantztrace_dump_escape(const char *str)
9735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
9835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca   const unsigned char *p = (const unsigned char *)str;
9935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca   unsigned char c;
10035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca   while((c = *p++) != 0) {
10135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca      if(c == '<')
102196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca         trace_dump_writes("&lt;");
10335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca      else if(c == '>')
104196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca         trace_dump_writes("&gt;");
10535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca      else if(c == '&')
106196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca         trace_dump_writes("&amp;");
10735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca      else if(c == '\'')
108196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca         trace_dump_writes("&apos;");
10935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca      else if(c == '\"')
110196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca         trace_dump_writes("&quot;");
11135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca      else if(c >= 0x20 && c <= 0x7e)
112196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca         trace_dump_writef("%c", c);
11335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca      else
114196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca         trace_dump_writef("&#%u;", c);
11535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca   }
11635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
11735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
11835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
119422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
120196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecatrace_dump_indent(unsigned level)
12135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
12235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca   unsigned i;
12335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca   for(i = 0; i < level; ++i)
124196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca      trace_dump_writes("\t");
12535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
12635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
12735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
128422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
129422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantztrace_dump_newline(void)
13035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
131196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("\n");
13235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
13335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
13435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
135422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
136196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecatrace_dump_tag(const char *name)
13735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
138196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<");
139196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(name);
140196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("/>");
14135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
14235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
14335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
144422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
145196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecatrace_dump_tag_begin(const char *name)
14635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
147196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<");
148196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(name);
149196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(">");
15035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
15135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
152422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
153422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantztrace_dump_tag_begin1(const char *name,
15435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca                      const char *attr1, const char *value1)
15535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
156196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<");
157196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(name);
158196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(" ");
159196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(attr1);
160196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("='");
161196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_escape(value1);
162196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("'>");
16335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
16435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
16535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
166422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
167422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantztrace_dump_tag_begin2(const char *name,
16835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca                      const char *attr1, const char *value1,
16935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca                      const char *attr2, const char *value2)
17035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
171196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<");
172196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(name);
173196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(" ");
174196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(attr1);
175196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("=\'");
176196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_escape(value1);
177196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("\' ");
178196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(attr2);
179196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("=\'");
180196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_escape(value2);
181196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("\'>");
18235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
18335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
18435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
185422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic INLINE void
186422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantztrace_dump_tag_begin3(const char *name,
18735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca                      const char *attr1, const char *value1,
18835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca                      const char *attr2, const char *value2,
18935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca                      const char *attr3, const char *value3)
19035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
191196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<");
192196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(name);
193196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(" ");
194196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(attr1);
195196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("=\'");
196196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_escape(value1);
197196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("\' ");
198196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(attr2);
199196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("=\'");
200196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_escape(value2);
201196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("\' ");
202196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(attr3);
203196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("=\'");
204196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_escape(value3);
205196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("\'>");
20635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
20735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
20835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
20935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonsecastatic INLINE void
210196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecatrace_dump_tag_end(const char *name)
211196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca{
212196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("</");
213196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(name);
214196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes(">");
215196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca}
216196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca
217422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantzstatic void
218f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonsecatrace_dump_trace_close(void)
219f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca{
220f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca   if(stream) {
221f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      trace_dump_writes("</trace>\n");
22257f8e26ca87a2846f192682c84eccbf8b4500bfcJosé Fonseca      fclose(stream);
223f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      stream = NULL;
224f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      refcount = 0;
225d2cdf6253cf06fbed6a5ca7ae17ddadf644afe26José Fonseca      call_no = 0;
226f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca   }
227f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca}
228f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca
229196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecaboolean trace_dump_trace_begin()
230196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca{
2316a31bb6ad8251ae977327e64562f373a89f55c70José Fonseca   const char *filename;
232422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz
2336a31bb6ad8251ae977327e64562f373a89f55c70José Fonseca   filename = debug_get_option("GALLIUM_TRACE", NULL);
2346a31bb6ad8251ae977327e64562f373a89f55c70José Fonseca   if(!filename)
235196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca      return FALSE;
236422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz
237f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca   if(!stream) {
238422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz
23957f8e26ca87a2846f192682c84eccbf8b4500bfcJosé Fonseca      stream = fopen(filename, "wt");
240f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      if(!stream)
241f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca         return FALSE;
242422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz
243f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      trace_dump_writes("<?xml version='1.0' encoding='UTF-8'?>\n");
244f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      trace_dump_writes("<?xml-stylesheet type='text/xsl' href='trace.xsl'?>\n");
245f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      trace_dump_writes("<trace version='0.1'>\n");
246422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz
247f6ca26e5a7ad0dddf7990aa2a3420ff0f1cc93aaVinson Lee#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE)
248422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz      /* Linux applications rarely cleanup GL / Gallium resources so catch
249422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz       * application exit here */
250f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      atexit(trace_dump_trace_close);
251196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca#endif
252f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca   }
253422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz
254f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca   ++refcount;
255422512050312a880439ed4e8eb99b8e362d5071fJakob Bornecrantz
256196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   return TRUE;
257196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca}
258196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca
259f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzboolean trace_dump_trace_enabled(void)
260f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca{
261f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca   return stream ? TRUE : FALSE;
262f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca}
263f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca
264196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_trace_end(void)
265196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca{
266f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca   if(stream)
267f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      if(!--refcount)
268f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca         trace_dump_trace_close();
26935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
27035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
271f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz/*
272f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz * Call lock
273f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz */
274f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
275f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dump_call_lock(void)
276f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
277f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   pipe_mutex_lock(call_mutex);
278f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
279f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
280f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dump_call_unlock(void)
281f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
282f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   pipe_mutex_unlock(call_mutex);
283f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
284f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
285f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz/*
286f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz * Dumping control
287f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz */
288f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
289f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dumping_start_locked(void)
290f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
291f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   dumping = TRUE;
292f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
293f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
294f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dumping_stop_locked(void)
295f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
296f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   dumping = FALSE;
297f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
298f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
299f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzboolean trace_dumping_enabled_locked(void)
300f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
301f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   return dumping;
302f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
303f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
304f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dumping_start(void)
305f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
306f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   pipe_mutex_lock(call_mutex);
307f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   trace_dumping_start_locked();
308f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   pipe_mutex_unlock(call_mutex);
309f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
310f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
311f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dumping_stop(void)
31235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
313e0e5d5014e84c10d3270afc9700a69c867ed282dJosé Fonseca   pipe_mutex_lock(call_mutex);
314f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   trace_dumping_stop_locked();
315f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   pipe_mutex_unlock(call_mutex);
316f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
317f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
318f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzboolean trace_dumping_enabled(void)
319f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
320f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   boolean ret;
321f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   pipe_mutex_lock(call_mutex);
322f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   ret = trace_dumping_enabled_locked();
323f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   pipe_mutex_unlock(call_mutex);
324f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   return ret;
325f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
326f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
327f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz/*
328f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz * Dump functions
329f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz */
330f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
331f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dump_call_begin_locked(const char *klass, const char *method)
332f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
333f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
334f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
335f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
336d2cdf6253cf06fbed6a5ca7ae17ddadf644afe26José Fonseca   ++call_no;
337196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_indent(1);
33858351b5023c2d87c22e21a27fd238212040dab8bJosé Fonseca   trace_dump_writes("<call no=\'");
339d2cdf6253cf06fbed6a5ca7ae17ddadf644afe26José Fonseca   trace_dump_writef("%lu", call_no);
34010430f47a49884ec59eca5942fdaee80119684afJosé Fonseca   trace_dump_writes("\' class=\'");
34158351b5023c2d87c22e21a27fd238212040dab8bJosé Fonseca   trace_dump_escape(klass);
34258351b5023c2d87c22e21a27fd238212040dab8bJosé Fonseca   trace_dump_writes("\' method=\'");
34358351b5023c2d87c22e21a27fd238212040dab8bJosé Fonseca   trace_dump_escape(method);
34458351b5023c2d87c22e21a27fd238212040dab8bJosé Fonseca   trace_dump_writes("\'>");
345196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_newline();
34635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
34735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
348f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dump_call_end_locked(void)
34935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
350f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
351f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
352f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
353196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_indent(1);
354196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_tag_end("call");
355196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_newline();
35657f8e26ca87a2846f192682c84eccbf8b4500bfcJosé Fonseca   fflush(stream);
357f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
358f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
359f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dump_call_begin(const char *klass, const char *method)
360f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
361f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   pipe_mutex_lock(call_mutex);
362f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   trace_dump_call_begin_locked(klass, method);
363f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz}
364f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
365f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantzvoid trace_dump_call_end(void)
366f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz{
367f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   trace_dump_call_end_locked();
368e0e5d5014e84c10d3270afc9700a69c867ed282dJosé Fonseca   pipe_mutex_unlock(call_mutex);
36935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
37035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
371196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_arg_begin(const char *name)
37235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
373f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
374f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
375f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
376196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_indent(2);
377196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_tag_begin1("arg", "name", name);
37835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
37935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
380196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_arg_end(void)
38135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
382f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
383f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
384f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
385196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_tag_end("arg");
386196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_newline();
38735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
38835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
389196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_ret_begin(void)
39035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
391f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
392f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
393f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
394196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_indent(2);
395196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_tag_begin("ret");
39635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
39735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
398196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_ret_end(void)
39935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
400f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
401f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
402f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
403196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_tag_end("ret");
404196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_newline();
40535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
40635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
407196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_bool(int value)
40835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
409f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
410f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
411f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
412196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writef("<bool>%c</bool>", value ? '1' : '0');
41335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
41435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
415d042f415fc9edcc174573fc2cc06afa373a7ef9bJosé Fonsecavoid trace_dump_int(long long int value)
41635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
417f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
418f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
419f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
420d042f415fc9edcc174573fc2cc06afa373a7ef9bJosé Fonseca   trace_dump_writef("<int>%lli</int>", value);
42135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
42235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
423d042f415fc9edcc174573fc2cc06afa373a7ef9bJosé Fonsecavoid trace_dump_uint(long long unsigned value)
42435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
425f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
426f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
427f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
428d042f415fc9edcc174573fc2cc06afa373a7ef9bJosé Fonseca   trace_dump_writef("<uint>%llu</uint>", value);
42935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
43035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
431196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_float(double value)
43235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
433f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
434f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
435f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
436196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writef("<float>%g</float>", value);
43735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
43835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
439196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_bytes(const void *data,
440d609df1daec552113a8385330b680b293ef862ebJosé Fonseca                      size_t size)
441b65259de6c0a2e77550bbef6b291c6d09dfb5867José Fonseca{
442e5a606883f24980dd8e2378c25e6fb3b8f1937ceJosé Fonseca   static const char hex_table[16] = "0123456789ABCDEF";
443b65259de6c0a2e77550bbef6b291c6d09dfb5867José Fonseca   const uint8_t *p = data;
444d609df1daec552113a8385330b680b293ef862ebJosé Fonseca   size_t i;
445f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
446f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
447f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
448f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
449196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<bytes>");
450b65259de6c0a2e77550bbef6b291c6d09dfb5867José Fonseca   for(i = 0; i < size; ++i) {
451b65259de6c0a2e77550bbef6b291c6d09dfb5867José Fonseca      uint8_t byte = *p++;
452e5a606883f24980dd8e2378c25e6fb3b8f1937ceJosé Fonseca      char hex[2];
453e5a606883f24980dd8e2378c25e6fb3b8f1937ceJosé Fonseca      hex[0] = hex_table[byte >> 4];
454e5a606883f24980dd8e2378c25e6fb3b8f1937ceJosé Fonseca      hex[1] = hex_table[byte & 0xf];
455196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca      trace_dump_write(hex, 2);
456b65259de6c0a2e77550bbef6b291c6d09dfb5867José Fonseca   }
457196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("</bytes>");
458b65259de6c0a2e77550bbef6b291c6d09dfb5867José Fonseca}
459b65259de6c0a2e77550bbef6b291c6d09dfb5867José Fonseca
460287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid trace_dump_box_bytes(const void *data,
461b77583203e44a8937577bf3b813dc66cea1a2005José Fonseca			  enum pipe_format format,
462287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell			  const struct pipe_box *box,
463287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell			  unsigned stride,
464287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell			  unsigned slice_stride)
465287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell{
46653c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca   size_t size;
46753c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca
46853c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca   if (slice_stride)
46953c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca      size = box->depth * slice_stride;
47053c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca   else if (stride)
47153c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca      size = util_format_get_nblocksy(format, box->height) * stride;
47253c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca   else {
47353c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca      size = util_format_get_nblocksx(format, box->width) * util_format_get_blocksize(format);
47453c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca   }
47553c3c914a786a4a579532671bd9cb79b41cae78dJosé Fonseca
476b77583203e44a8937577bf3b813dc66cea1a2005José Fonseca   trace_dump_bytes(data, size);
477287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell}
478287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
479196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_string(const char *str)
48035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
481f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
482f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
483f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
484196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<string>");
485196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_escape(str);
486196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("</string>");
48735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
48835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
489196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_enum(const char *value)
490ce2137a6a4c2648a77b9697a3aa0479c9c61baccJosé Fonseca{
491f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
492f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
493f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
494196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<enum>");
495196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_escape(value);
496196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("</enum>");
497ce2137a6a4c2648a77b9697a3aa0479c9c61baccJosé Fonseca}
498ce2137a6a4c2648a77b9697a3aa0479c9c61baccJosé Fonseca
499196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_array_begin(void)
50035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
501f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
502f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
503f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
504196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<array>");
50535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
50635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
507196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_array_end(void)
50835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
509f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
510f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
511f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
512196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("</array>");
51335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
51435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
515196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_elem_begin(void)
51635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
517f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
518f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
519f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
520196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<elem>");
52135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
52235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
523196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_elem_end(void)
52435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
525f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
526f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
527f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
528196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("</elem>");
52935355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
53035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
531196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_struct_begin(const char *name)
53235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
533f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
534f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
535f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
536196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writef("<struct name='%s'>", name);
53735355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
53835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
539196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_struct_end(void)
54035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
541f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
542f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
543f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
544196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("</struct>");
54535355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
54635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
547196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_member_begin(const char *name)
54835355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
549f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
550f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
551f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
552196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writef("<member name='%s'>", name);
55335355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
55435355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
555196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_member_end(void)
55635355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
557f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
558f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
559f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
560196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("</member>");
56135355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
56235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca
563196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_null(void)
5649dee60969df7ff263e05430e69ef26982fe2bd94José Fonseca{
565f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
566f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
567f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
568196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca   trace_dump_writes("<null/>");
5699dee60969df7ff263e05430e69ef26982fe2bd94José Fonseca}
5709dee60969df7ff263e05430e69ef26982fe2bd94José Fonseca
571196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonsecavoid trace_dump_ptr(const void *value)
57235355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca{
573f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
574f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
575f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
5769dee60969df7ff263e05430e69ef26982fe2bd94José Fonseca   if(value)
577f121d0e54f39d8f6361dcf0bf4d938ccb5ae4b5eJosé Fonseca      trace_dump_writef("<ptr>0x%08lx</ptr>", (unsigned long)(uintptr_t)value);
5789dee60969df7ff263e05430e69ef26982fe2bd94José Fonseca   else
579196167e9d5c84f9f6dfe6f15b3e2f2c3ec6825dcJosé Fonseca      trace_dump_null();
58035355f7610b69dcd2fdba451db4554478fe0acaaJosé Fonseca}
58153e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz
58253e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz
583287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid trace_dump_resource_ptr(struct pipe_resource *_resource)
58453e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz{
585f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
586f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
587f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
588287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   if (_resource) {
589287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell      struct trace_resource *tr_resource = trace_resource(_resource);
590287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell      trace_dump_ptr(tr_resource->resource);
59153e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz   } else {
59253e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz      trace_dump_null();
59353e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz   }
59453e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz}
59553e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz
59653e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantzvoid trace_dump_surface_ptr(struct pipe_surface *_surface)
59753e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz{
598f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
599f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
600f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
60153e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz   if (_surface) {
602927eb8fe4cc8a5ed583aad1dafa98d091d7602f4José Fonseca      struct trace_surface *tr_surf = trace_surface(_surface);
60353e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz      trace_dump_ptr(tr_surf->surface);
60453e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz   } else {
60553e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz      trace_dump_null();
60653e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz   }
60753e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz}
60853e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz
60953e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantzvoid trace_dump_transfer_ptr(struct pipe_transfer *_transfer)
61053e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz{
611f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz   if (!dumping)
612f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz      return;
613f2d2b3d8e2d9059c162ae7215344b9171f68632bJakob Bornecrantz
61453e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz   if (_transfer) {
615927eb8fe4cc8a5ed583aad1dafa98d091d7602f4José Fonseca      struct trace_transfer *tr_tran = trace_transfer(_transfer);
61653e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz      trace_dump_ptr(tr_tran->transfer);
61753e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz   } else {
61853e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz      trace_dump_null();
61953e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz   }
62053e5248b0a71b1e72b1a613046a1b3e5d145d072Jakob Bornecrantz}
621