Add some debugging code to tmreader and temporarily turn it on to debug tinderbox orange.
authordbaron@dbaron.org
Tue, 03 Apr 2007 16:46:45 -0700
changeset 308 575e080e3b20543206e2664cbadc2e8d26a77c27
parent 307 8cbac12020439c67030a67e535605c58f5b5a250
child 309 503b4a4f93bba4ee0aeda47244397c40481399cb
push idunknown
push userunknown
push dateunknown
milestone1.9a4pre
Add some debugging code to tmreader and temporarily turn it on to debug tinderbox orange.
tools/trace-malloc/tmreader.c
--- a/tools/trace-malloc/tmreader.c
+++ b/tools/trace-malloc/tmreader.c
@@ -51,16 +51,18 @@
 /* make sure this happens before tmreader.h */
 #define PL_ARENA_CONST_ALIGN_MASK 2
 #include "plarena.h"
 
 #include "prnetdb.h"
 #include "nsTraceMalloc.h"
 #include "tmreader.h"
 
+#define DEBUG_tmreader
+
 static int accum_byte(FILE *fp, uint32 *uip)
 {
     int c = getc(fp);
     if (c == EOF)
         return 0;
     *uip = (*uip << 8) | c;
     return 1;
 }
@@ -149,61 +151,88 @@ static int get_tmevent(FILE *fp, tmevent
     if (!get_uint32(fp, &event->serial))
         return 0;
     switch (c) {
       case TM_EVENT_LIBRARY:
         s = get_string(fp);
         if (!s)
             return 0;
         event->u.libname = s;
+#ifdef DEBUG_tmreader
+        printf("tmevent %c %u libname=\"%s\"\n", event->type, event->serial,
+               event->u.libname);
+#endif
         break;
 
       case TM_EVENT_FILENAME:
         s = get_string(fp);
         if (!s)
             return 0;
         event->u.srcname = s;
+#ifdef DEBUG_tmreader
+        printf("tmevent %c %u srcname=\"%s\"\n", event->type, event->serial,
+               event->u.srcname);
+#endif
         break;
 
       case TM_EVENT_METHOD:
         if (!get_uint32(fp, &event->u.method.library))
             return 0;
         if (!get_uint32(fp, &event->u.method.filename))
             return 0;
         if (!get_uint32(fp, &event->u.method.linenumber))
             return 0;
         s = get_string(fp);
         if (!s)
             return 0;
         event->u.method.name = s;
+#ifdef DEBUG_tmreader
+        printf("tmevent %c %u library=%u filename=%u linenumber=%u "
+               "name=\"%s\"\n",
+               event->type, event->serial,
+               event->u.method.library, event->u.method.filename,
+               event->u.method.linenumber, event->u.method.name);
+#endif
         break;
 
       case TM_EVENT_CALLSITE:
         if (!get_uint32(fp, &event->u.site.parent))
             return 0;
         if (!get_uint32(fp, &event->u.site.method))
             return 0;
         if (!get_uint32(fp, &event->u.site.offset))
             return 0;
+#ifdef DEBUG_tmreader
+        printf("tmevent %c %u parent=%u method=%u offset=%u\n",
+               event->type, event->serial,
+               event->u.site.parent, event->u.site.method,
+               event->u.site.offset);
+#endif
         break;
 
       case TM_EVENT_MALLOC:
       case TM_EVENT_CALLOC:
       case TM_EVENT_FREE:
         if (!get_uint32(fp, &event->u.alloc.interval))
             return 0;
         if (!get_uint32(fp, &event->u.alloc.cost))
             return 0;
         if (!get_uint32(fp, &event->u.alloc.ptr))
             return 0;
         if (!get_uint32(fp, &event->u.alloc.size))
             return 0;
         event->u.alloc.oldserial = 0;
         event->u.alloc.oldptr = 0;
         event->u.alloc.oldsize = 0;
+#ifdef DEBUG_tmreader
+        printf("tmevent %c %u interval=%u cost=%u ptr=0x%x size=%u\n",
+               event->type, event->serial,
+               event->u.alloc.interval, event->u.alloc.cost,
+               event->u.alloc.ptr, event->u.alloc.size);
+#endif
 #if defined(DEBUG_dp)
         if (c == TM_EVENT_MALLOC)
             printf("%d malloc %d 0x%p\n", event->u.alloc.cost,
                    event->u.alloc.size, event->u.alloc.ptr);
         else if (c == TM_EVENT_CALLOC)
             printf("%d calloc %d 0x%p\n", event->u.alloc.cost,
                    event->u.alloc.size, event->u.alloc.ptr);
         else
@@ -222,16 +251,25 @@ static int get_tmevent(FILE *fp, tmevent
         if (!get_uint32(fp, &event->u.alloc.size))
             return 0;
         if (!get_uint32(fp, &event->u.alloc.oldserial))
             return 0;
         if (!get_uint32(fp, &event->u.alloc.oldptr))
             return 0;
         if (!get_uint32(fp, &event->u.alloc.oldsize))
             return 0;
+#ifdef DEBUG_tmreader
+        printf("tmevent %c %u interval=%u cost=%u ptr=0x%x size=%u "
+               "oldserial=%u oldptr=0x%x oldsize=%u\n",
+               event->type, event->serial,
+               event->u.alloc.interval, event->u.alloc.cost,
+               event->u.alloc.ptr, event->u.alloc.size,
+               event->u.alloc.oldserial, event->u.alloc.oldptr,
+               event->u.alloc.oldsize);
+#endif
 #if defined(DEBUG_dp)
         printf("%d realloc %d 0x%p %d\n", event->u.alloc.cost,
                event->u.alloc.size, event->u.alloc.ptr, event->u.alloc.oldsize);
 #endif
         break;
 
       case TM_EVENT_STATS:
         if (!get_uint32(fp, &event->u.stats.tmstats.calltree_maxstack))
@@ -273,17 +311,23 @@ static int get_tmevent(FILE *fp, tmevent
         if (!get_uint32(fp, &event->u.stats.tmstats.free_calls))
             return 0;
         if (!get_uint32(fp, &event->u.stats.tmstats.null_free_calls))
             return 0;
         if (!get_uint32(fp, &event->u.stats.calltree_maxkids_parent))
             return 0;
         if (!get_uint32(fp, &event->u.stats.calltree_maxstack_top))
             return 0;
+#ifdef DEBUG_tmreader
+        printf("tmevent %c %u\n", event->type, event->serial);
+#endif
         break;
+      default:
+        fprintf(stderr, "Unknown event type %c\n", event->type);
+        return 0;
     }
     return 1;
 }
 
 static void *arena_alloc(void* pool, PRSize size)
 {
     PLArenaPool* arena = (PLArenaPool*)pool;
     void* result;