--------------------- PatchSet 1658 Date: 2001/02/25 20:47:34 Author: hno Branch: eventio Tag: (none) Log: Rewrote MemPool reporting to output a IOBuf instead of a StoreEntry. Members: src/MemPool.c:1.5.12.1->1.5.12.2 src/tools.c:1.10.12.3->1.10.12.4 Index: squid/src/MemPool.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/MemPool.c,v retrieving revision 1.5.12.1 retrieving revision 1.5.12.2 diff -u -r1.5.12.1 -r1.5.12.2 --- squid/src/MemPool.c 24 Feb 2001 23:48:43 -0000 1.5.12.1 +++ squid/src/MemPool.c 25 Feb 2001 20:47:34 -0000 1.5.12.2 @@ -1,6 +1,6 @@ /* - * $Id: MemPool.c,v 1.5.12.1 2001/02/24 23:48:43 hno Exp $ + * $Id: MemPool.c,v 1.5.12.2 2001/02/25 20:47:34 hno Exp $ * * DEBUG: section 63 Low Level Memory Pool Management * AUTHOR: Alex Rousskov @@ -157,13 +157,12 @@ /* MemPoolMeter */ -#if 0 static void memPoolMeterReport(const MemPoolMeter * pm, size_t obj_size, - int alloc_count, int inuse_count, int idle_count, StoreEntry * e) + int alloc_count, int inuse_count, int idle_count, MemBuf *out) { assert(pm); - storeAppendPrintf(e, "%d\t %d\t %d\t %.2f\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %.2f\t %.2f\t %.2f\t %d\n", + memBufPrintf(out, "%d\t %d\t %d\t %.2f\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %.2f\t %.2f\t %.2f\t %d\n", /* alloc */ alloc_count, toKB(obj_size * pm->alloc.level), @@ -188,7 +187,6 @@ pm->total.count); } -#endif /* MemMeter */ void @@ -325,30 +323,31 @@ return TheMeter.alloc.level; } -#if 0 -void -memPoolReport(const MemPool * pool, StoreEntry * e) +static void +memPoolReport(const MemPool * pool, MemBuf *out) { assert(pool); - storeAppendPrintf(e, "%-20s\t %4d\t ", + memBufPrintf(out, "%-20s\t %4d\t ", pool->label, pool->obj_size); memPoolMeterReport(&pool->meter, pool->obj_size, pool->meter.alloc.level, pool->meter.inuse.level, pool->meter.idle.level, - e); + out); } -void -memReport(StoreEntry * e) +IOBuf * +memReport(void) { + IOBuf *out; size_t overhd_size = 0; int alloc_count = 0; int inuse_count = 0; int idle_count = 0; int i; + out = IOBufAlloc(8192); /* caption */ - storeAppendPrintf(e, "Current memory usage:\n"); + memBufPrintf(out, "Current memory usage:\n"); /* heading */ - storeAppendPrintf(e, "Pool\t Obj Size\t" + memBufPrintf(out, "Pool\t Obj Size\t" "Allocated\t\t\t\t\t In Use\t\t\t\t Idle\t\t\t Allocations Saved\t\t\t Hit Rate\t\n" " \t (bytes)\t" "(#)\t (KB)\t high (KB)\t high (hrs)\t impact (%%total)\t" @@ -362,7 +361,7 @@ for (i = 0; i < Pools.count; i++) { const MemPool *pool = Pools.items[i]; if (memPoolWasUsed(pool)) { - memPoolReport(pool, e); + memPoolReport(pool, out); alloc_count += pool->meter.alloc.level; inuse_count += pool->meter.inuse.level; idle_count += pool->meter.idle.level; @@ -373,18 +372,19 @@ } overhd_size += sizeof(Pools) + Pools.capacity * sizeof(MemPool *); /* totals */ - storeAppendPrintf(e, "%-20s\t %-4s\t ", "Total", "-"); - memPoolMeterReport(&TheMeter, 1, alloc_count, inuse_count, idle_count, e); - storeAppendPrintf(e, "Cumulative allocated volume: %s\n", gb_to_str(&mem_traffic_volume)); + memBufPrintf(out, "%-20s\t %-4s\t ", "Total", "-"); + memPoolMeterReport(&TheMeter, 1, alloc_count, inuse_count, idle_count, out); + memBufPrintf(out, "Cumulative allocated volume: %s\n", gb_to_str(&mem_traffic_volume)); /* overhead */ - storeAppendPrintf(e, "Current overhead: %d bytes (%.3f%%)\n", + memBufPrintf(out, "Current overhead: %d bytes (%.3f%%)\n", overhd_size, xpercent(overhd_size, TheMeter.inuse.level)); /* limits */ - storeAppendPrintf(e, "Idle pool limit: %.2f MB\n", toMB(mem_idle_limit)); - storeAppendPrintf(e, "memPoolAlloc calls: %d\n", mem_pool_alloc_calls); - storeAppendPrintf(e, "memPoolFree calls: %d\n", mem_pool_free_calls); + memBufPrintf(out, "Idle pool limit: %.2f MB\n", toMB(mem_idle_limit)); + memBufPrintf(out, "memPoolAlloc calls: %d\n", mem_pool_alloc_calls); + memBufPrintf(out, "memPoolFree calls: %d\n", mem_pool_free_calls); + return out; } -#endif + void gb_flush(gb_t * g) { @@ -392,3 +392,33 @@ g->bytes &= (1 << 30) - 1; } +double +gb_to_double(const gb_t * g) +{ + return ((double) g->gb) * ((double) (1 << 30)) + ((double) g->bytes); +} + +const char * +gb_to_str(const gb_t * g) +{ + /* + * it is often convenient to call gb_to_str several times for _one_ printf + */ +#define max_cc_calls 5 + typedef char GbBuf[32]; + static GbBuf bufs[max_cc_calls]; + static int call_id = 0; + double value = gb_to_double(g); + char *buf = bufs[call_id++]; + if (call_id >= max_cc_calls) + call_id = 0; + /* select format */ + if (value < 1e9) + snprintf(buf, sizeof(GbBuf), "%.2f MB", value / 1e6); + else if (value < 1e12) + snprintf(buf, sizeof(GbBuf), "%.2f GB", value / 1e9); + else + snprintf(buf, sizeof(GbBuf), "%.2f TB", value / 1e12); + return buf; +} + Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.10.12.3 retrieving revision 1.10.12.4 diff -u -r1.10.12.3 -r1.10.12.4 --- squid/src/tools.c 24 Feb 2001 23:48:43 -0000 1.10.12.3 +++ squid/src/tools.c 25 Feb 2001 20:47:34 -0000 1.10.12.4 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.10.12.3 2001/02/24 23:48:43 hno Exp $ + * $Id: tools.c,v 1.10.12.4 2001/02/25 20:47:34 hno Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -770,36 +770,6 @@ k->bytes &= 0x3FF; } -double -gb_to_double(const gb_t * g) -{ - return ((double) g->gb) * ((double) (1 << 30)) + ((double) g->bytes); -} - -const char * -gb_to_str(const gb_t * g) -{ - /* - * it is often convenient to call gb_to_str several times for _one_ printf - */ -#define max_cc_calls 5 - typedef char GbBuf[32]; - static GbBuf bufs[max_cc_calls]; - static int call_id = 0; - double value = gb_to_double(g); - char *buf = bufs[call_id++]; - if (call_id >= max_cc_calls) - call_id = 0; - /* select format */ - if (value < 1e9) - snprintf(buf, sizeof(GbBuf), "%.2f MB", value / 1e6); - else if (value < 1e12) - snprintf(buf, sizeof(GbBuf), "%.2f GB", value / 1e9); - else - snprintf(buf, sizeof(GbBuf), "%.2f TB", value / 1e12); - return buf; -} - void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm) {