Mailing List Archive

r1565 - trunk/varnish-cache/bin/varnishd
Author: des
Date: 2007-06-25 16:24:09 +0200 (Mon, 25 Jun 2007)
New Revision: 1565

Modified:
trunk/varnish-cache/bin/varnishd/storage_file.c
trunk/varnish-cache/bin/varnishd/storage_malloc.c
Log:
Maintain statistics about the number of allocations made and the amount of
allocated and free space.


Modified: trunk/varnish-cache/bin/varnishd/storage_file.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-25 14:15:52 UTC (rev 1564)
+++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-06-25 14:24:09 UTC (rev 1565)
@@ -442,7 +442,7 @@
}

/*--------------------------------------------------------------------
- * 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 @@
if (sum < MINPAGES * (uintmax_t)getpagesize())
exit (2);
MTX_INIT(&sc->mtx);
+
+ VSL_stats->sm_bfree += sc->filesize;
}

/*--------------------------------------------------------------------*/
@@ -627,8 +629,12 @@
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 @@
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 @@
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);
}

Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-06-25 14:15:52 UTC (rev 1564)
+++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-06-25 14:24:09 UTC (rev 1565)
@@ -35,6 +35,7 @@

#include <stdlib.h>

+#include "shmlog.h"
#include "cache.h"

struct sma {
@@ -46,6 +47,7 @@
{
struct sma *sma;

+ VSL_stats->sm_nreq++;
sma = calloc(sizeof *sma, 1);
XXXAN(sma);
sma->s.priv = sma;
@@ -56,6 +58,8 @@
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 @@
struct sma *sma;

sma = s->priv;
+ VSL_stats->sm_nobj--;
+ VSL_stats->sm_balloc -= sma->s.space;
free(sma->s.ptr);
free(sma);
}