static union overhead *nextf[NBUCKETS];
extern char *sbrk();
-#ifdef MSTATS
+#ifdef DEBUGGING_MSTATS
/*
* nmalloc[i] is the difference between the number of mallocs and frees
* for a given block size.
nextf[bucket] = p->ov_next;
p->ov_magic = MAGIC;
p->ov_index= bucket;
-#ifdef MSTATS
+#ifdef DEBUGGING_MSTATS
nmalloc[bucket]++;
#endif
#ifdef RCHECK
}
}
-void
+Free_t
free(mp)
Malloc_t mp;
{
size = op->ov_index;
op->ov_next = nextf[size];
nextf[size] = op;
-#ifdef MSTATS
+#ifdef DEBUGGING_MSTATS
nmalloc[size]--;
#endif
}
return (-1);
}
-#ifdef MSTATS
+#ifdef DEBUGGING_MSTATS
/*
* mstats - print out statistics about malloc
*
* frees for each size category.
*/
void
-mstats(s)
+dump_mstats(s)
char *s;
{
register int i, j;
register union overhead *p;
- int totfree = 0,
- totused = 0;
+ int topbucket=0, totfree=0, totused=0;
+ u_int nfree[NBUCKETS];
- fprintf(stderr, "Memory allocation statistics %s\nfree:\t", s);
- for (i = 0; i < NBUCKETS; i++) {
+ for (i=0; i < NBUCKETS; i++) {
for (j = 0, p = nextf[i]; p; p = p->ov_next, j++)
;
- fprintf(stderr, " %d", j);
- totfree += j * (1 << (i + 3));
- }
- fprintf(stderr, "\nused:\t");
- for (i = 0; i < NBUCKETS; i++) {
- fprintf(stderr, " %d", nmalloc[i]);
+ nfree[i] = j;
+ totfree += nfree[i] * (1 << (i + 3));
totused += nmalloc[i] * (1 << (i + 3));
+ if (nfree[i] || nmalloc[i])
+ topbucket = i;
+ }
+ if (s)
+ fprintf(stderr, "Memory allocation statistics %s (buckets 8..%d)\n",
+ s, (1 << (topbucket + 3)) );
+ fprintf(stderr, " %7d free: ", totfree);
+ for (i=0; i <= topbucket; i++) {
+ fprintf(stderr, (i<5)?" %5d":" %3d", nfree[i]);
+ }
+ fprintf(stderr, "\n %7d used: ", totused);
+ for (i=0; i <= topbucket; i++) {
+ fprintf(stderr, (i<5)?" %5d":" %3d", nmalloc[i]);
}
- fprintf(stderr, "\n\tTotal in use: %d, total free: %d\n",
- totused, totfree);
+ fprintf(stderr, "\n");
+}
+#else
+void
+dump_mstats(s)
+ char *s;
+{
}
#endif
#endif /* lint */