| 1 |
/* print stats; common for heap, stock and pool */ |
| 2 |
|
| 3 |
#include <stdio.h> |
| 4 |
|
| 5 |
#include "utilmeminfo.h" |
| 6 |
|
| 7 |
#define UINT(i) ((unsigned long)(i)) |
| 8 |
|
| 9 |
void show_mem_info (mem_info *info) |
| 10 |
{ |
| 11 |
size_t totalwaste, totalmem, averagechunk, singlemem; |
| 12 |
double ftotalwaste, fblockwaste, fghostwaste, ftailwaste, fsinglewaste; |
| 13 |
double funused, fsingles, fsinglemem, fsingleeff; |
| 14 |
|
| 15 |
totalwaste = info->ghosts + info->blockghosts + info->left; |
| 16 |
totalmem = info->used + totalwaste; |
| 17 |
|
| 18 |
ftotalwaste = totalmem > 0 ? totalwaste * 100.0 / totalmem : 0; |
| 19 |
fblockwaste = totalmem > 0 ? (info->blockghosts - info->singleghosts) * 100.0 / totalmem : 0; |
| 20 |
fsinglewaste = totalmem > 0 ? info->singleghosts * 100.0 / totalmem : 0; |
| 21 |
fghostwaste = totalmem > 0 ? info->ghosts * 100.0 / totalmem : 0; |
| 22 |
ftailwaste = totalmem > 0 ? info->left * 100.0 / totalmem : 0; |
| 23 |
|
| 24 |
averagechunk = info->chunks > 0 ? info->used / info->chunks : 0; |
| 25 |
funused = info->chunks > 0 ? info->unused * 100.0 / info->chunks : 0.0; |
| 26 |
|
| 27 |
fsingles = info->blocks > 0 ? info->singles * 100.0 / info->blocks : 0; |
| 28 |
fsinglemem = info->used > 0 ? info->singleused * 100.0 / info->used : 0; |
| 29 |
singlemem = info->singleused + info->singleghosts; |
| 30 |
fsingleeff = singlemem > 0 ? info->singleused * 100.0 / singlemem : 0; |
| 31 |
|
| 32 |
printf("total: %lu + %lu = %lu\n", UINT(info->used), UINT(totalwaste), UINT(totalmem)); |
| 33 |
printf("chunks: %lu of average size %lu, unused %lu[%.2f%%]\n", UINT(info->chunks), UINT(averagechunk), UINT(info->unused), funused); |
| 34 |
printf("blocks: %lu, singles %lu[%.2f%%], %.2f%% of allocs, efficiency %.2f%%\n", |
| 35 |
UINT(info->blocks), UINT(info->singles), fsingles, fsinglemem, fsingleeff); |
| 36 |
printf("waste: %lu[%0.2f%%], block ghosts %0.2f%%, single ghosts %.2f%%, chunk ghosts %0.2f%%, tails %0.2f%%\n\n", |
| 37 |
UINT(totalwaste), ftotalwaste, fblockwaste, fsinglewaste, fghostwaste, ftailwaste); |
| 38 |
} |