Insert MPOOL_GET_{LEFT|RIGHT}_BUDDY() macros
[eleutheria.git] / buddy / mstat.c
blob3fe1f439020f503f4accab33a62ef28f97c117cb
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 (MPOOL_IS_AVAIL(pnode))
16 (*avail)++;
17 else
18 (*used)++;
23 void mpool_stat_get_bytes(const mpool_t *mpool, size_t *avail, size_t *used)
25 const blkhead_t *phead;
26 const blknode_t *pnode;
27 size_t i;
29 *avail = 0;
30 *used = 0;
31 for (i = 0; i < mpool->nblocks; i++) {
32 phead = &mpool->blktable[i];
33 LIST_FOREACH(pnode, phead, next_chunk) {
34 if (MPOOL_IS_AVAIL(pnode))
35 *avail += 1 << pnode->logsize;
36 else
37 *used += 1 << pnode->logsize;
42 size_t mpool_stat_get_blocks(const mpool_t *mpool)
44 return mpool->nblocks;
47 size_t mpool_stat_get_block_length(const mpool_t *mpool, size_t pos)
49 const blknode_t *pnode;
50 size_t length;
52 if (pos >= mpool->nblocks)
53 return 0; /* FIXME: Better error handling */
55 length = 0;
56 LIST_FOREACH(pnode, &mpool->blktable[pos], next_chunk)
57 length++;
59 return length;
62 #ifdef MPOOL_STATS
63 size_t mpool_stat_get_splits(const mpool_t *mpool)
65 return mpool->nsplits;
68 size_t mpool_stat_get_merges(const mpool_t *mpool)
70 return mpool->nmerges;
72 #endif