[add code to track number of allocations of each size.
John Meacham <john@repetae.net>**20080313114637] hunk ./data/rts/jhc_rts_alloc.c 12
+#if _JHC_PROFILE
+
+#define BUCKETS 7
+
+static unsigned alloced[BUCKETS];
+static unsigned alloced_atomic[BUCKETS];
+
+static void
+alloc_count(int n,int atomic)
+{
+        n = n ? ((n - 1)/sizeof(void *)) + 1 : 0;
+        n = n > BUCKETS - 1 ? BUCKETS - 1 : n;
+        (atomic ? alloced_atomic : alloced)[n]++;
+}
+
+
+static void
+print_alloc_size_stats(void) {
+        char fmt[] = "%10s %10s %10s %10s %10s\n";
+        char fmt2[] = "%10u %10u %10u %10u %10u\n";
+        fprintf(stderr,fmt,"Size","Normal","Atomic","Total","Accum");
+        fprintf(stderr,fmt,"----","------","------","-----","-----");
+        unsigned accum = 0;
+        for(int i = 0; i < BUCKETS; i++) {
+                accum += alloced[i] + alloced_atomic[i];
+                fprintf(stderr,fmt2,i,alloced[i],alloced_atomic[i],alloced_atomic[i] + alloced[i], accum);
+        }
+}
+
+
+#else
+
+#define alloc_count(x,y)
+#define print_alloc_size_stats()
+
+#endif
hunk ./data/rts/jhc_rts_alloc.c 63
-static void *jhc_current_chunk;
-static unsigned mem_chunks,mem_offset;
-
hunk ./data/rts/jhc_rts_alloc.c 66
+static char initial_chunk[JHC_MEM_CHUNK_SIZE];
+
+static void *jhc_current_chunk = initial_chunk;
+static unsigned mem_chunks,mem_offset;
+
+
hunk ./data/rts/jhc_rts_alloc.c 77
-        fprintf(stderr, "Memory Allocated: %llu bytes\n", (JHC_MEM_CHUNK_SIZE*((unsigned long long)mem_chunks - 1)) + mem_offset);
-
+        fprintf(stderr, "Memory Allocated: %u bytes\n", (JHC_MEM_CHUNK_SIZE*(mem_chunks)) + mem_offset);
+        print_alloc_size_stats();
hunk ./data/rts/jhc_rts_alloc.c 106
-#define jhc_malloc(n) jhc_malloc_debug(n,__LINE__)
+#define jhc_malloc(n) jhc_malloc_debug(n,__LINE__,0)
+#undef jhc_malloc_atomic
+#define jhc_malloc_atomic(n) jhc_malloc_debug(n,__LINE__,1)
hunk ./data/rts/jhc_rts_alloc.c 111
-jhc_malloc_debug(size_t n,int line) {
+jhc_malloc_debug(size_t n,int line,int atomic) {
+        alloc_count(n,atomic);
hunk ./data/rts/jhc_rts_alloc.c 121
-jhc_malloc(size_t n) { return jhc_malloc_basic(n); }
+jhc_malloc(size_t n) {
+        alloc_count(n,0);
+        return jhc_malloc_basic(n);
+}
+
+#undef jhc_malloc_atomic
+static inline void * A_MALLOC
+jhc_malloc_atomic(size_t n) {
+        alloc_count(n,1);
+        return jhc_malloc_basic(n);
+}