From: Paolo Molaro Date: Wed, 10 Nov 2010 09:48:26 +0000 (+0100) Subject: Log profiler: fixed timeout heapshot mode and sorted heapshots. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=25002af4f69213769141100c6145a00364e74d99;p=mono.git Log profiler: fixed timeout heapshot mode and sorted heapshots. * proflog.c: fixed heapshot timeout mode (setting the last time it was performed). * decode.c: sort heap shot list according to the time sequence. --- diff --git a/mono/profiler/decode.c b/mono/profiler/decode.c index fc2c13fa7e3..bab67c1d65f 100644 --- a/mono/profiler/decode.c +++ b/mono/profiler/decode.c @@ -246,23 +246,18 @@ struct _HeapShot { static HeapShot *heap_shots = NULL; static HeapShot *current_heap_shot = NULL; +static int num_heap_shots = 0; static HeapShot* new_heap_shot (uint64_t timestamp) { - HeapShot *p; HeapShot *hs = calloc (sizeof (HeapShot), 1); hs->hash_size = 4; hs->class_hash = calloc (sizeof (void*), hs->hash_size); hs->timestamp = timestamp; - /* append it to the list */ - p = heap_shots; - while (p && p->next) - p = p->next; - if (p) - p->next = hs; - else - heap_shots = hs; + num_heap_shots++; + hs->next = heap_shots; + heap_shots = hs; return hs; } @@ -1588,18 +1583,36 @@ heap_shot_summary (HeapShot *hs, int hs_num, HeapShot *last_hs) } } +static int +compare_heap_shots (const void *a, const void *b) +{ + HeapShot *const*A = a; + HeapShot *const*B = b; + if ((*B)->timestamp == (*A)->timestamp) + return 0; + if ((*B)->timestamp > (*A)->timestamp) + return -1; + return 1; +} + static void dump_heap_shots (void) { + HeapShot **hs_sorted; HeapShot *hs; HeapShot *last_hs = NULL; int i; if (!heap_shots) return; + hs_sorted = malloc (num_heap_shots * sizeof (void*)); fprintf (outfile, "\nHeap shot summary\n"); i = 0; - for (hs = heap_shots; hs; hs = hs->next) { - heap_shot_summary (hs, i++, last_hs); + for (hs = heap_shots; hs; hs = hs->next) + hs_sorted [i++] = hs; + qsort (hs_sorted, num_heap_shots, sizeof (void*), compare_heap_shots); + for (i = 0; i < num_heap_shots; ++i) { + hs = hs_sorted [i]; + heap_shot_summary (hs, i, last_hs); last_hs = hs; } } diff --git a/mono/profiler/proflog.c b/mono/profiler/proflog.c index c09157c24e9..7ba7627d745 100644 --- a/mono/profiler/proflog.c +++ b/mono/profiler/proflog.c @@ -521,6 +521,7 @@ heap_walk (MonoProfiler *profiler) now = current_time (); emit_byte (logbuffer, TYPE_HEAP_END | TYPE_HEAP); emit_time (logbuffer, now); + last_hs_time = now; } static void