From: wessels <> Date: Tue, 10 Jan 2006 03:22:31 +0000 (+0000) Subject: This patch adds sorting to cachemgr:mem output to make it easier to find X-Git-Tag: SQUID_3_0_PRE4~381 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=729102f4ec5b72f2d9f8333c4b4d954fa3e09031;p=thirdparty%2Fsquid.git This patch adds sorting to cachemgr:mem output to make it easier to find classes/objects that leak memory. --- diff --git a/src/mem.cc b/src/mem.cc index ae72d782b4..01538b832f 100644 --- a/src/mem.cc +++ b/src/mem.cc @@ -1,6 +1,6 @@ /* - * $Id: mem.cc,v 1.89 2006/01/03 17:22:31 wessels Exp $ + * $Id: mem.cc,v 1.90 2006/01/09 20:22:31 wessels Exp $ * * DEBUG: section 13 High Level Memory Pool Management * AUTHOR: Harvest Derived @@ -578,7 +578,7 @@ Mem::PoolReport(const MemPoolStats * mp_st, const MemPoolMeter * AllMeter, Store storeAppendPrintf(e, "%d\t %ld\t %ld\t %.2f\t %.1f\t" /* alloc */ - "%d\t %ld\t %ld\t %.1f\t" /* in use */ + "%d\t %ld\t %ld\t %.2f\t %.1f\t" /* in use */ "%d\t %ld\t %ld\t" /* idle */ "%.0f\t %.1f\t %.1f\t %.1f\n", /* saved */ /* alloc */ @@ -591,6 +591,7 @@ Mem::PoolReport(const MemPoolStats * mp_st, const MemPoolMeter * AllMeter, Store mp_st->items_inuse, (long) toKB(mp_st->obj_size * pm->inuse.level), (long) toKB(mp_st->obj_size * pm->inuse.hwater_level), + (double) ((squid_curtime - pm->inuse.hwater_stamp) / 3600.), xpercent(pm->inuse.level, pm->alloc.level), /* idle */ mp_st->items_idle, @@ -604,6 +605,37 @@ Mem::PoolReport(const MemPoolStats * mp_st, const MemPoolMeter * AllMeter, Store pm->gb_osaved.count = pm->gb_saved.count; } +static int +MemPoolReportSorter(const void *a, const void *b) +{ + const MemPoolStats *A = (MemPoolStats *) a; + const MemPoolStats *B = (MemPoolStats *) b; + + // use this to sort on %Total Allocated + // + double pa = (double) A->obj_size * A->meter->alloc.level; + double pb = (double) B->obj_size * B->meter->alloc.level; + + if (pa > pb) + return -1; + + if (pb > pa) + return 1; + +#if 0 + // use this to sort on In Use high(hrs) + // + if (A->meter->inuse.hwater_stamp > B->meter->inuse.hwater_stamp) + return -1; + + if (B->meter->inuse.hwater_stamp > A->meter->inuse.hwater_stamp) + return 1; + +#endif + + return 0; +} + void Mem::Report(StoreEntry * e) { @@ -621,7 +653,7 @@ Mem::Report(StoreEntry * e) "Pool\t Obj Size\t" "Chunks\t\t\t\t\t\t\t" "Allocated\t\t\t\t\t" - "In Use\t\t\t\t" + "In Use\t\t\t\t\t" "Idle\t\t\t" "Allocations Saved\t\t\t" "Hit Rate\t" @@ -630,7 +662,7 @@ Mem::Report(StoreEntry * e) "KB/ch\t obj/ch\t" "(#)\t used\t free\t part\t %%Frag\t " "(#)\t (KB)\t high (KB)\t high (hrs)\t %%Tot\t" - "(#)\t (KB)\t high (KB)\t %%alloc\t" + "(#)\t (KB)\t high (KB)\t high (hrs)\t %%alloc\t" "(#)\t (KB)\t high (KB)\t" "(#)\t %%cnt\t %%vol\t" "(#) / sec\t" @@ -641,6 +673,9 @@ Mem::Report(StoreEntry * e) /* Get stats for Totals report line */ memPoolGetGlobalStats(&mp_total); + MemPoolStats *sortme = (MemPoolStats *) xcalloc(mp_total.tot_pools_alloc ,sizeof(*sortme)); + int npools = 0; + /* main table */ iter = memPoolIterate(); @@ -651,13 +686,21 @@ Mem::Report(StoreEntry * e) continue; if (mp_stats.pool->getMeter().gb_saved.count > 0) /* this pool has been used */ - PoolReport(&mp_stats, mp_total.TheMeter, e); + sortme[npools++] = mp_stats; else not_used++; } memPoolIterateDone(&iter); + qsort(sortme, npools, sizeof(*sortme), MemPoolReportSorter); + + for (int i = 0; i< npools; i++) { + PoolReport(&sortme[i], mp_total.TheMeter, e); + } + + xfree(sortme); + mp_stats.pool = NULL; mp_stats.label = "Total"; mp_stats.meter = mp_total.TheMeter;