From: des Date: Mon, 25 Jun 2007 14:24:09 +0000 (+0000) Subject: Maintain statistics about the number of allocations made and the amount of X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae5e3372dba5895b1f3143e0f24bd95815694253;p=varnish Maintain statistics about the number of allocations made and the amount of allocated and free space. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1565 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index b531fc04..b1d24c1e 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -442,7 +442,7 @@ alloc_smf(struct smf_sc *sc, size_t bytes) } /*-------------------------------------------------------------------- - * Free a range. Attemt merge forward and backward, then sort into + * Free a range. Attempt merge forward and backward, then sort into * free list according to age. */ @@ -613,6 +613,8 @@ smf_open(struct stevedore *st) if (sum < MINPAGES * (uintmax_t)getpagesize()) exit (2); MTX_INIT(&sc->mtx); + + VSL_stats->sm_bfree += sc->filesize; } /*--------------------------------------------------------------------*/ @@ -627,8 +629,12 @@ smf_alloc(struct stevedore *st, size_t size) size += (sc->pagesize - 1); size &= ~(sc->pagesize - 1); LOCK(&sc->mtx); + VSL_stats->sm_nreq++; smf = alloc_smf(sc, size); CHECK_OBJ_NOTNULL(smf, SMF_MAGIC); + VSL_stats->sm_nobj++; + VSL_stats->sm_balloc += smf->size; + VSL_stats->sm_bfree -= smf->size; UNLOCK(&sc->mtx); XXXAN(smf); assert(smf->size == size); @@ -662,6 +668,8 @@ smf_trim(struct storage *s, size_t size) size &= ~(sc->pagesize - 1); if (smf->size > size) { LOCK(&sc->mtx); + VSL_stats->sm_balloc -= (smf->size - size); + VSL_stats->sm_bfree += (smf->size - size); trim_smf(smf, size); assert(smf->size == size); UNLOCK(&sc->mtx); @@ -681,6 +689,9 @@ smf_free(struct storage *s) CAST_OBJ_NOTNULL(smf, s->priv, SMF_MAGIC); sc = smf->sc; LOCK(&sc->mtx); + VSL_stats->sm_nobj--; + VSL_stats->sm_balloc -= smf->size; + VSL_stats->sm_bfree += smf->size; free_smf(smf); UNLOCK(&sc->mtx); } diff --git a/varnish-cache/bin/varnishd/storage_malloc.c b/varnish-cache/bin/varnishd/storage_malloc.c index 9ec2e0fc..40afd92d 100644 --- a/varnish-cache/bin/varnishd/storage_malloc.c +++ b/varnish-cache/bin/varnishd/storage_malloc.c @@ -35,6 +35,7 @@ #include +#include "shmlog.h" #include "cache.h" struct sma { @@ -46,6 +47,7 @@ sma_alloc(struct stevedore *st, size_t size) { struct sma *sma; + VSL_stats->sm_nreq++; sma = calloc(sizeof *sma, 1); XXXAN(sma); sma->s.priv = sma; @@ -56,6 +58,8 @@ sma_alloc(struct stevedore *st, size_t size) sma->s.fd = -1; sma->s.stevedore = st; sma->s.magic = STORAGE_MAGIC; + VSL_stats->sm_nobj++; + VSL_stats->sm_balloc += sma->s.space; return (&sma->s); } @@ -65,6 +69,8 @@ sma_free(struct storage *s) struct sma *sma; sma = s->priv; + VSL_stats->sm_nobj--; + VSL_stats->sm_balloc -= sma->s.space; free(sma->s.ptr); free(sma); }