From 1d6dfe94fb970b51d96653da6c3361533d697fc3 Mon Sep 17 00:00:00 2001 From: "Anand V. Avati" Date: Fri, 17 Apr 2009 23:12:37 +0530 Subject: added 2 APIs iobuf_size and iobref_size to return the system memory usage by an iobuf, and by all iobufs in an iobref respectively --- libglusterfs/src/iobuf.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'libglusterfs/src/iobuf.c') diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c index a10dc6f84..84e3b5efe 100644 --- a/libglusterfs/src/iobuf.c +++ b/libglusterfs/src/iobuf.c @@ -570,3 +570,45 @@ iobref_merge (struct iobref *to, struct iobref *from) return ret; } + + +size_t +iobuf_size (struct iobuf *iobuf) +{ + size_t size = 0; + + if (!iobuf) + goto out; + + if (!iobuf->iobuf_arena) + goto out; + + if (!iobuf->iobuf_arena->iobuf_pool) + goto out; + + size = iobuf->iobuf_arena->iobuf_pool->page_size; +out: + return size; +} + + +size_t +iobref_size (struct iobref *iobref) +{ + size_t size = 0; + int i = 0; + + if (!iobref) + goto out; + + LOCK (&iobref->lock); + { + for (i = 0; i < 8; i++) { + if (iobref->iobrefs[i]) + size += iobuf_size (iobref->iobrefs[i]); + } + } + UNLOCK (&iobref->lock); +out: + return size; +} -- cgit