Log profiler: updated to the new heap walk API.
authorPaolo Molaro <lupus@oddwiz.org>
Fri, 12 Nov 2010 19:02:10 +0000 (20:02 +0100)
committerPaolo Molaro <lupus@oddwiz.org>
Fri, 12 Nov 2010 20:38:05 +0000 (21:38 +0100)
The GC now provides also offset information for each referenced object
in the heap walk API: this info is saved in the profile data now.
Updated the data version for the file format change.

mono/profiler/decode.c
mono/profiler/proflog.c
mono/profiler/proflog.h

index 44d3ad1f3ed869b2bf7114faa17453e7abbe5331..a7d442806263b29bae685c09cb34df001c90a5c6 100644 (file)
@@ -1299,6 +1299,7 @@ decode_buffer (ProfContext *ctx)
                                uint64_t size = decode_uleb128 (p, &p);
                                uintptr_t num = decode_uleb128 (p, &p);
                                uintptr_t ref_offset;
+                               uintptr_t last_obj_offset = 0;
                                ClassDesc *cd = lookup_class (ptr_base + ptrdiff);
                                if (size) {
                                        HeapClassDesc *hcd = add_heap_shot_class (thread->current_heap_shot, cd, size);
@@ -1315,7 +1316,9 @@ decode_buffer (ProfContext *ctx)
                                        /* FIXME: use object distance to measure how good
                                         * the GC is at keeping related objects close
                                         */
+                                       uintptr_t offset = ctx->data_version > 1? last_obj_offset + decode_uleb128 (p, &p): -1;
                                        intptr_t obj1diff = decode_sleb128 (p, &p);
+                                       last_obj_offset = offset;
                                        if (collect_traces)
                                                ho->refs [ref_offset + i] = OBJ_ADDR (obj1diff);
                                        if (num_tracked_objects)
@@ -1482,7 +1485,7 @@ load_file (char *name)
        if (!load_data (ctx, 32))
                return NULL;
        p = ctx->buf;
-       if (read_int32 (p) != LOG_HEADER_ID || p [6] != LOG_DATA_VERSION)
+       if (read_int32 (p) != LOG_HEADER_ID || p [6] > LOG_DATA_VERSION)
                return NULL;
        ctx->version_major = p [4];
        ctx->version_minor = p [5];
index 303b9a716c1ee2b24226039f3ce210f48db81543..46059226c4ef02010658ff65a2a0b0ac08848d85 100644 (file)
@@ -215,6 +215,9 @@ typedef struct _LogBuffer LogBuffer;
  *     [class: sleb128] the object MonoClass* as a difference from ptr_base
  *     [size: uleb128] size of the object on the heap
  *     [num_refs: uleb128] number of object references
+ *     if (format version > 1) each referenced objref is preceded by a
+ *     uleb128 encoded offset: the first offset is from the object address
+ *     and each next offset is relative to the previous one
  *     [objrefs: sleb128]+ object referenced as a difference from obj_base
  *
  */
@@ -480,9 +483,10 @@ safe_dump (MonoProfiler *profiler, LogBuffer *logbuffer)
 }
 
 static int
-gc_reference (MonoObject *obj, MonoClass *klass, uintptr_t size, uintptr_t num, MonoObject **refs, void *data)
+gc_reference (MonoObject *obj, MonoClass *klass, uintptr_t size, uintptr_t num, MonoObject **refs, uintptr_t *offsets, void *data)
 {
        int i;
+       uintptr_t last_offset = 0;
        //const char *name = mono_class_get_name (klass);
        LogBuffer *logbuffer = ensure_logbuf (20 + num * 8);
        emit_byte (logbuffer, TYPE_HEAP_OBJECT | TYPE_HEAP);
@@ -493,8 +497,11 @@ gc_reference (MonoObject *obj, MonoClass *klass, uintptr_t size, uintptr_t num,
        size &= ~7;
        emit_value (logbuffer, size);
        emit_value (logbuffer, num);
-       for (i = 0; i < num; ++i)
+       for (i = 0; i < num; ++i) {
+               emit_value (logbuffer, offsets [i] - last_offset);
+               last_offset = offsets [i];
                emit_obj (logbuffer, refs [i]);
+       }
        //if (num)
        //      printf ("obj: %p, klass: %s, refs: %d, size: %d\n", obj, name, (int)num, (int)size);
        return 0;
index 5aaf6a4ce5a5c5c09d6a36769cdcb3837e013df4..86124a0e2c079fb3bc3e267b2b174048e4e5e52f 100644 (file)
@@ -5,7 +5,7 @@
 #define LOG_HEADER_ID 0x4D505A01
 #define LOG_VERSION_MAJOR 0
 #define LOG_VERSION_MINOR 2
-#define LOG_DATA_VERSION 1
+#define LOG_DATA_VERSION 2
 
 enum {
        TYPE_ALLOC,