tr_dump.c File Reference

Trace dumping functions. More...

Include dependency graph for tr_dump.c:

Go to the source code of this file.

Functions

static void trace_dump_write (const char *buf, size_t size)
static void trace_dump_writes (const char *s)
static void trace_dump_writef (const char *format,...)
static void trace_dump_escape (const char *str)
static void trace_dump_indent (unsigned level)
static void trace_dump_newline (void)
static void trace_dump_tag (const char *name)
static void trace_dump_tag_begin (const char *name)
static void trace_dump_tag_begin1 (const char *name, const char *attr1, const char *value1)
static void trace_dump_tag_begin2 (const char *name, const char *attr1, const char *value1, const char *attr2, const char *value2)
static void trace_dump_tag_begin3 (const char *name, const char *attr1, const char *value1, const char *attr2, const char *value2, const char *attr3, const char *value3)
static void trace_dump_tag_end (const char *name)
static void trace_dump_trace_close (void)
boolean trace_dump_trace_begin ()
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)
void trace_dump_arg_begin (const char *name)
void trace_dump_arg_end (void)
void trace_dump_ret_begin (void)
void trace_dump_ret_end (void)
void trace_dump_bool (int value)
void trace_dump_int (long long int value)
void trace_dump_uint (long long unsigned value)
void trace_dump_float (double value)
void trace_dump_bytes (const void *data, long unsigned size)
void trace_dump_string (const char *str)
void trace_dump_enum (const char *value)
void trace_dump_array_begin (void)
void trace_dump_array_end (void)
void trace_dump_elem_begin (void)
void trace_dump_elem_end (void)
void trace_dump_struct_begin (const char *name)
void trace_dump_struct_end (void)
void trace_dump_member_begin (const char *name)
void trace_dump_member_end (void)
void trace_dump_null (void)
void trace_dump_ptr (const void *value)

Variables

static struct util_stream * stream = NULL
static unsigned refcount = 0
static pipe_mutex call_mutex
static long unsigned call_no = 0


Detailed Description

Trace dumping functions.

For now we just use standard XML for dumping the trace calls, as this is simple to write, parse, and visually inspect, but the actual representation is abstracted out of this file, so that we can switch to a binary representation if/when it becomes justified.

Author:
Jose Fonseca <jrfonseca@tungstengraphics.com>

Definition in file tr_dump.c.


Function Documentation

void trace_dump_arg_begin ( const char *  name  ) 

Definition at line 294 of file tr_dump.c.

References trace_dump_indent(), and trace_dump_tag_begin1().

00295 {
00296    trace_dump_indent(2);
00297    trace_dump_tag_begin1("arg", "name", name);
00298 }

void trace_dump_arg_end ( void   ) 

Definition at line 300 of file tr_dump.c.

References trace_dump_newline(), and trace_dump_tag_end().

00301 {
00302    trace_dump_tag_end("arg");
00303    trace_dump_newline();
00304 }

void trace_dump_array_begin ( void   ) 

Definition at line 369 of file tr_dump.c.

References trace_dump_writes().

00370 {
00371    trace_dump_writes("<array>");
00372 }

void trace_dump_array_end ( void   ) 

Definition at line 374 of file tr_dump.c.

References trace_dump_writes().

00375 {
00376    trace_dump_writes("</array>");
00377 }

void trace_dump_bool ( int  value  ) 

Definition at line 318 of file tr_dump.c.

References trace_dump_writef().

00319 {
00320    trace_dump_writef("<bool>%c</bool>", value ? '1' : '0');
00321 }

void trace_dump_bytes ( const void *  data,
long unsigned  size 
)

Definition at line 338 of file tr_dump.c.

References trace_dump_write(), and trace_dump_writes().

00340 {
00341    static const char hex_table[16] = "0123456789ABCDEF";
00342    const uint8_t *p = data;
00343    long unsigned i;
00344    trace_dump_writes("<bytes>");
00345    for(i = 0; i < size; ++i) {
00346       uint8_t byte = *p++;
00347       char hex[2];
00348       hex[0] = hex_table[byte >> 4];
00349       hex[1] = hex_table[byte & 0xf];
00350       trace_dump_write(hex, 2);
00351    }
00352    trace_dump_writes("</bytes>");
00353 }

void trace_dump_call_begin ( const char *  klass,
const char *  method 
)

Definition at line 270 of file tr_dump.c.

References call_mutex, call_no, pipe_mutex_lock, trace_dump_escape(), trace_dump_indent(), trace_dump_newline(), trace_dump_writef(), and trace_dump_writes().

00271 {
00272    pipe_mutex_lock(call_mutex);
00273    ++call_no;
00274    trace_dump_indent(1);
00275    trace_dump_writes("<call no=\'");
00276    trace_dump_writef("%lu", call_no);
00277    trace_dump_writes("\' class =\'");
00278    trace_dump_escape(klass);
00279    trace_dump_writes("\' method=\'");
00280    trace_dump_escape(method);
00281    trace_dump_writes("\'>");
00282    trace_dump_newline();
00283 }

void trace_dump_call_end ( void   ) 

Definition at line 285 of file tr_dump.c.

References call_mutex, pipe_mutex_unlock, stream, trace_dump_indent(), trace_dump_newline(), trace_dump_tag_end(), and util_stream_flush().

00286 {
00287    trace_dump_indent(1);
00288    trace_dump_tag_end("call");
00289    trace_dump_newline();
00290    util_stream_flush(stream);
00291    pipe_mutex_unlock(call_mutex);
00292 }

void trace_dump_elem_begin ( void   ) 

Definition at line 379 of file tr_dump.c.

References trace_dump_writes().

00380 {
00381    trace_dump_writes("<elem>");
00382 }

void trace_dump_elem_end ( void   ) 

Definition at line 384 of file tr_dump.c.

References trace_dump_writes().

00385 {
00386    trace_dump_writes("</elem>");
00387 }

boolean trace_dump_enabled ( void   ) 

Definition at line 258 of file tr_dump.c.

References FALSE, stream, and TRUE.

00259 {
00260    return stream ? TRUE : FALSE;
00261 }

void trace_dump_enum ( const char *  value  ) 

Definition at line 362 of file tr_dump.c.

References trace_dump_escape(), and trace_dump_writes().

00363 {
00364    trace_dump_writes("<enum>");
00365    trace_dump_escape(value);
00366    trace_dump_writes("</enum>");
00367 }

static void trace_dump_escape ( const char *  str  )  [static]

Definition at line 92 of file tr_dump.c.

References trace_dump_writef(), and trace_dump_writes().

00093 {
00094    const unsigned char *p = (const unsigned char *)str;
00095    unsigned char c;
00096    while((c = *p++) != 0) {
00097       if(c == '<')
00098          trace_dump_writes("&lt;");
00099       else if(c == '>')
00100          trace_dump_writes("&gt;");
00101       else if(c == '&')
00102          trace_dump_writes("&amp;");
00103       else if(c == '\'')
00104          trace_dump_writes("&apos;");
00105       else if(c == '\"')
00106          trace_dump_writes("&quot;");
00107       else if(c >= 0x20 && c <= 0x7e)
00108          trace_dump_writef("%c", c);
00109       else
00110          trace_dump_writef("&#%u;", c);
00111    }
00112 }

void trace_dump_float ( double  value  ) 

Definition at line 333 of file tr_dump.c.

References trace_dump_writef().

00334 {
00335    trace_dump_writef("<float>%g</float>", value);
00336 }

static void trace_dump_indent ( unsigned  level  )  [static]

Definition at line 116 of file tr_dump.c.

References trace_dump_writes().

00117 {
00118    unsigned i;
00119    for(i = 0; i < level; ++i)
00120       trace_dump_writes("\t");
00121 }

void trace_dump_int ( long long int  value  ) 

Definition at line 323 of file tr_dump.c.

References trace_dump_writef().

00324 {
00325    trace_dump_writef("<int>%lli</int>", value);
00326 }

void trace_dump_member_begin ( const char *  name  ) 

Definition at line 399 of file tr_dump.c.

References trace_dump_writef().

00400 {
00401    trace_dump_writef("<member name='%s'>", name);
00402 }

void trace_dump_member_end ( void   ) 

Definition at line 404 of file tr_dump.c.

References trace_dump_writes().

00405 {
00406    trace_dump_writes("</member>");
00407 }

static void trace_dump_newline ( void   )  [static]

Definition at line 125 of file tr_dump.c.

References trace_dump_writes().

00126 {
00127    trace_dump_writes("\n");
00128 }

void trace_dump_null ( void   ) 

Definition at line 409 of file tr_dump.c.

References trace_dump_writes().

00410 {
00411    trace_dump_writes("<null/>");
00412 }

void trace_dump_ptr ( const void *  value  ) 

Definition at line 414 of file tr_dump.c.

References trace_dump_null(), and trace_dump_writef().

00415 {
00416    if(value)
00417       trace_dump_writef("<ptr>0x%08lx</ptr>", (unsigned long)(uintptr_t)value);
00418    else
00419       trace_dump_null();
00420 }

void trace_dump_ret_begin ( void   ) 

Definition at line 306 of file tr_dump.c.

References trace_dump_indent(), and trace_dump_tag_begin().

00307 {
00308    trace_dump_indent(2);
00309    trace_dump_tag_begin("ret");
00310 }

void trace_dump_ret_end ( void   ) 

Definition at line 312 of file tr_dump.c.

References trace_dump_newline(), and trace_dump_tag_end().

00313 {
00314    trace_dump_tag_end("ret");
00315    trace_dump_newline();
00316 }

void trace_dump_string ( const char *  str  ) 

Definition at line 355 of file tr_dump.c.

References trace_dump_escape(), and trace_dump_writes().

00356 {
00357    trace_dump_writes("<string>");
00358    trace_dump_escape(str);
00359    trace_dump_writes("</string>");
00360 }

void trace_dump_struct_begin ( const char *  name  ) 

Definition at line 389 of file tr_dump.c.

References trace_dump_writef().

00390 {
00391    trace_dump_writef("<struct name='%s'>", name);
00392 }

void trace_dump_struct_end ( void   ) 

Definition at line 394 of file tr_dump.c.

References trace_dump_writes().

00395 {
00396    trace_dump_writes("</struct>");
00397 }

static void trace_dump_tag ( const char *  name  )  [static]

Definition at line 132 of file tr_dump.c.

References trace_dump_writes().

00133 {
00134    trace_dump_writes("<");
00135    trace_dump_writes(name);
00136    trace_dump_writes("/>");
00137 }

static void trace_dump_tag_begin ( const char *  name  )  [static]

Definition at line 141 of file tr_dump.c.

References trace_dump_writes().

00142 {
00143    trace_dump_writes("<");
00144    trace_dump_writes(name);
00145    trace_dump_writes(">");
00146 }

static void trace_dump_tag_begin1 ( const char *  name,
const char *  attr1,
const char *  value1 
) [static]

Definition at line 149 of file tr_dump.c.

References trace_dump_escape(), and trace_dump_writes().

00151 {
00152    trace_dump_writes("<");
00153    trace_dump_writes(name);
00154    trace_dump_writes(" ");
00155    trace_dump_writes(attr1);
00156    trace_dump_writes("='");
00157    trace_dump_escape(value1);
00158    trace_dump_writes("'>");
00159 }

static void trace_dump_tag_begin2 ( const char *  name,
const char *  attr1,
const char *  value1,
const char *  attr2,
const char *  value2 
) [static]

Definition at line 163 of file tr_dump.c.

References trace_dump_escape(), and trace_dump_writes().

00166 {
00167    trace_dump_writes("<");
00168    trace_dump_writes(name);
00169    trace_dump_writes(" ");
00170    trace_dump_writes(attr1);
00171    trace_dump_writes("=\'");
00172    trace_dump_escape(value1);
00173    trace_dump_writes("\' ");
00174    trace_dump_writes(attr2);
00175    trace_dump_writes("=\'");
00176    trace_dump_escape(value2);
00177    trace_dump_writes("\'>");
00178 }

static void trace_dump_tag_begin3 ( const char *  name,
const char *  attr1,
const char *  value1,
const char *  attr2,
const char *  value2,
const char *  attr3,
const char *  value3 
) [static]

Definition at line 182 of file tr_dump.c.

References trace_dump_escape(), and trace_dump_writes().

00186 {
00187    trace_dump_writes("<");
00188    trace_dump_writes(name);
00189    trace_dump_writes(" ");
00190    trace_dump_writes(attr1);
00191    trace_dump_writes("=\'");
00192    trace_dump_escape(value1);
00193    trace_dump_writes("\' ");
00194    trace_dump_writes(attr2);
00195    trace_dump_writes("=\'");
00196    trace_dump_escape(value2);
00197    trace_dump_writes("\' ");
00198    trace_dump_writes(attr3);
00199    trace_dump_writes("=\'");
00200    trace_dump_escape(value3);
00201    trace_dump_writes("\'>");
00202 }

static void trace_dump_tag_end ( const char *  name  )  [static]

Definition at line 206 of file tr_dump.c.

References trace_dump_writes().

00207 {
00208    trace_dump_writes("</");
00209    trace_dump_writes(name);
00210    trace_dump_writes(">");
00211 }

boolean trace_dump_trace_begin ( void   ) 

Definition at line 226 of file tr_dump.c.

References call_mutex, debug_get_option(), FALSE, pipe_mutex_init, refcount, stream, trace_dump_trace_close(), trace_dump_writes(), TRUE, and util_stream_create().

00227 {
00228    const char *filename;
00229    
00230    filename = debug_get_option("GALLIUM_TRACE", NULL);
00231    if(!filename)
00232       return FALSE;
00233    
00234    if(!stream) {
00235    
00236       stream = util_stream_create(filename, 0);
00237       if(!stream)
00238          return FALSE;
00239       
00240       pipe_mutex_init(call_mutex);
00241 
00242       trace_dump_writes("<?xml version='1.0' encoding='UTF-8'?>\n");
00243       trace_dump_writes("<?xml-stylesheet type='text/xsl' href='trace.xsl'?>\n");
00244       trace_dump_writes("<trace version='0.1'>\n");
00245       
00246 #if defined(PIPE_OS_LINUX)
00247       /* Linux applications rarely cleanup GL / Gallium resources so catch 
00248        * application exit here */ 
00249       atexit(trace_dump_trace_close);
00250 #endif
00251    }
00252    
00253    ++refcount;
00254    
00255    return TRUE;
00256 }

static void trace_dump_trace_close ( void   )  [static]

Definition at line 214 of file tr_dump.c.

References call_mutex, call_no, pipe_mutex_destroy, refcount, stream, trace_dump_writes(), and util_stream_close().

00215 {
00216    if(stream) {
00217       trace_dump_writes("</trace>\n");
00218       util_stream_close(stream);
00219       stream = NULL;
00220       refcount = 0;
00221       call_no = 0;
00222       pipe_mutex_destroy(call_mutex);
00223    }
00224 }

void trace_dump_trace_end ( void   ) 

Definition at line 263 of file tr_dump.c.

References refcount, stream, and trace_dump_trace_close().

00264 {
00265    if(stream)
00266       if(!--refcount)
00267          trace_dump_trace_close();
00268 }

void trace_dump_uint ( long long unsigned  value  ) 

Definition at line 328 of file tr_dump.c.

References trace_dump_writef().

00329 {
00330    trace_dump_writef("<uint>%llu</uint>", value);
00331 }

static void trace_dump_write ( const char *  buf,
size_t  size 
) [static]

Definition at line 64 of file tr_dump.c.

References stream, and util_stream_write().

00065 {
00066    if(stream)
00067       util_stream_write(stream, buf, size);
00068 }

static void trace_dump_writef ( const char *  format,
  ... 
) [static]

Definition at line 79 of file tr_dump.c.

References trace_dump_write(), and util_vsnprintf.

00080 {
00081    static char buf[1024];
00082    unsigned len;
00083    va_list ap;
00084    va_start(ap, format);
00085    len = util_vsnprintf(buf, sizeof(buf), format, ap);
00086    va_end(ap);
00087    trace_dump_write(buf, len);
00088 }

static void trace_dump_writes ( const char *  s  )  [static]

Definition at line 72 of file tr_dump.c.

References trace_dump_write().

00073 {
00074    trace_dump_write(s, strlen(s));
00075 }


Variable Documentation

pipe_mutex call_mutex [static]

Definition at line 59 of file tr_dump.c.

long unsigned call_no = 0 [static]

Definition at line 60 of file tr_dump.c.

unsigned refcount = 0 [static]

Definition at line 58 of file tr_dump.c.

struct util_stream* stream = NULL [static]

Definition at line 57 of file tr_dump.c.


Generated on Tue Sep 29 06:25:42 2009 for Gallium3D by  doxygen 1.5.4