]> mj.ucw.cz Git - libucw.git/commitdiff
Mempool: Implemented statistics about allocated bytes from memory pool to application.
authorPavel Charvat <pchar@ucw.cz>
Tue, 20 May 2014 09:08:15 +0000 (11:08 +0200)
committerPavel Charvat <pchar@ucw.cz>
Tue, 20 May 2014 09:08:15 +0000 (11:08 +0200)
ucw/mempool.c
ucw/mempool.h

index 564a8e9f0bb26166be3371ed2e32de8f7705427c..9e5d62b0022909d20dc1254fbddd0c1f4128b47f 100644 (file)
@@ -219,6 +219,9 @@ mp_stats(struct mempool *pool, struct mempool_stats *stats)
   mp_stats_chain(pool->state.last[1], stats, 1);
   mp_stats_chain(pool->unused, stats, 2);
   ASSERT(stats->total_size == pool->total_size);
+  stats->used_size = stats->chain_size[0] + stats->chain_size[1]
+    - MP_CHUNK_TAIL * (stats->chain_count[0] + stats->chain_count[1])
+    - pool->state.free[0] - pool->state.free[1];
 }
 
 u64
index 562d8f99936feab4af41c80784ad32f2a26fdf81..9d0c97d18e0cd7510c58b7a6545f0a73b0c0b2b6 100644 (file)
@@ -77,6 +77,7 @@ struct mempool {
 
 struct mempool_stats {                 /** Mempool statistics. See @mp_stats(). **/
   u64 total_size;                      /* Real allocated size in bytes */
+  u64 used_size;                       /* Estimated size allocated from mempool to application */
   uns chain_count[3];                  /* Number of allocated chunks in small/big/unused chains */
   uns chain_size[3];                   /* Size of allocated chunks in small/big/unused chains */
 };