Separate netbsd-specific from unix-specific projects
[eleutheria.git] / unix / malloc / mstat.c
blob2887ae56e2396ef76d439b641e8545a06283da2b
1 #include "mpool.h"
2 #include "mstat.h"
4 void mpool_stat_get_nodes(const mpool_t *mpool, size_t *avail, size_t *used)
6 const blkhead_t *phead;
7 const blknode_t *pnode;
8 size_t i;
10 *avail = 0;
11 *used = 0;
12 for (i = 0; i < mpool->nblocks; i++) {
13 phead = &mpool->blktable[i];
14 LIST_FOREACH(pnode, phead, next_chunk) {
15 /*if (pnode->flags & MP_NODE_AVAIL)*/
16 if (MPOOL_IS_AVAIL(pnode))
17 (*avail)++;
18 else
19 (*used)++;
24 void mpool_stat_get_bytes(const mpool_t *mpool, size_t *avail, size_t *used)
26 const blkhead_t *phead;
27 const blknode_t *pnode;
28 size_t i;
30 *avail = 0;
31 *used = 0;
32 for (i = 0; i < mpool->nblocks; i++) {
33 phead = &mpool->blktable[i];
34 LIST_FOREACH(pnode, phead, next_chunk) {
35 /*if (pnode->flags & MP_NODE_AVAIL)*/
36 if (MPOOL_IS_AVAIL(pnode))
37 *avail += 1 << pnode->logsize;
38 else
39 *used += 1 << pnode->logsize;
44 size_t mpool_stat_get_blocks(const mpool_t *mpool)
46 return mpool->nblocks;
49 size_t mpool_stat_get_block_length(const mpool_t *mpool, size_t pos)
51 const blknode_t *pnode;
52 size_t length;
54 if (pos >= mpool->nblocks)
55 return 0; /* FIXME: Better error handling */
57 length = 0;
58 LIST_FOREACH(pnode, &mpool->blktable[pos], next_chunk)
59 length++;
61 return length;
64 #ifdef MP_STATS
65 size_t mpool_stat_get_splits(const mpool_t *mpool)
67 return mpool->nsplits;
70 size_t mpool_stat_get_merges(const mpool_t *mpool)
72 return mpool->nmerges;
74 #endif