asm_switchstackandcall change
[cacao.git] / mm / lifespan.c
index 249f065f4ddf954700199476876063dcf6b936c6..e2667f5466837937f95b024b40e089c29746f490 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * cacao/mm/lifespan.c
- * $Id: lifespan.c 99 1998-11-30 22:29:56Z phil $
+ * $Id: lifespan.c 115 1999-01-20 01:52:45Z phil $
  */
 
-@include "mm.h"
+#include "mm.h"
 #include "lifespan.h"
 #include <stdio.h>
 #include <stdlib.h>
 
 typedef struct {
        unsigned long time;
+       unsigned long number;
        unsigned long size;
 } lifespan_object;
 
 static unsigned long     current_time = 0;
+static unsigned long     current_number = 0;
 static lifespan_object** lifespan_objects = NULL;
 static lifespan_object** lifespan_objects_end = NULL;
 static void*             lifespan_objects_off = NULL;
 static FILE*             lifespan_file = NULL;
 
+static unsigned long     lifespan_histo_size[64] = { 0 };
+static unsigned long     lifespan_histo_lifespan[64] = { 0 };
+
 void lifespan_init(void* heap_base, unsigned long heap_size)
 {
        current_time = 0;
@@ -37,12 +42,39 @@ void lifespan_init(void* heap_base, unsigned long heap_size)
        memset(lifespan_objects, 0, heap_size);
 }
 
-static __inline__ void lifespan_free_object(lifespan_object** o)
+static inline void lifespan_free_object(lifespan_object** o)
 {
+       int size, high = 0;
        /* file format: alloc time, size, lifespan */
 
        if (*o) {
-               fprintf(lifespan_file, "%ld\t%ld\t%ld\n", (*o)->time, (*o)->size, current_time - (*o)->time);
+               fprintf(lifespan_file, 
+                               "%ld\t%ld\t%ld\t%ld\t%ld\n", 
+                               (*o)->number, 
+                               (*o)->time, 
+                               (*o)->size, 
+                               current_number - (*o)->number,
+                               current_time - (*o)->time);
+               
+               /* histo_size */
+               size = (*o)->size;
+               while (size) {
+                       ++high;
+                       size = size >> 1;
+               }
+
+               ++lifespan_histo_size[high];
+
+               /* histo_life */
+               high = 0;
+               size = current_time - (*o)->time;
+               while (size) {
+                       ++high;
+                       size = size >> 1;
+               }
+
+               ++lifespan_histo_lifespan[high];
+
                free(*o);
                *o = NULL;
        }
@@ -64,6 +96,26 @@ void lifespan_close()
 void lifespan_emit()
 {
        /* emit summary */
+       int i;
+
+       for (i = 4; i < 32; ++i)
+#if 0
+               fprintf(stderr, "%Lu-%Lu\t%Lu\n", 
+                               (1LL << (i-1)), 
+                               (1LL << i) - 1,
+                               lifespan_histo_size[i]);
+#else
+               fprintf(stderr, "%Lu\n", 
+                               lifespan_histo_size[i]);
+#endif
+
+       fprintf(stderr, "\n\n\n");
+
+       for (i = 4; i < 32; ++i)
+               fprintf(stderr, "%Lu-%Lu\t%Lu\n", 
+                               (1LL << (i-1)), 
+                               (1LL << i) - 1,
+                               lifespan_histo_lifespan[i]);
 }
 
 void lifespan_free(void** from, void** limit)
@@ -79,6 +131,7 @@ void lifespan_free(void** from, void** limit)
 
 void lifespan_alloc(void* addr, unsigned long size) 
 {
+       int high = 0;
        lifespan_object**  object;
        object = (lifespan_object**)((unsigned long)addr + (unsigned long)lifespan_objects_off);
 
@@ -89,6 +142,13 @@ void lifespan_alloc(void* addr, unsigned long size)
        }
        (*object)->time = current_time;
        (*object)->size = size;
+       (*object)->number = ++current_number;
+
+       while (size) {
+               ++high;
+               size = size >> 1;
+       }
+       ++lifespan_histo_size[high];
        
        current_time += size;
 }