From: phk Date: Wed, 5 Jul 2006 13:13:56 +0000 (+0000) Subject: Add more stats X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=64847721c6727fb74c311f61e92b25f654a03c7a;p=varnish Add more stats git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@328 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index c0750ed8..22d7c49b 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -154,6 +154,7 @@ accept_f(int fd, short event, void *arg) * XXX: this is probably one we should handle * XXX: accept, emit error NNN and close */ + VSL_stats->n_sess++; sp = &sm->s; sp->rd_e = &sm->e; @@ -242,6 +243,7 @@ vca_return_session(struct sess *sp) } else { if (sp->http != NULL) http_Delete(sp->http); + VSL_stats->n_sess--; free(sp->mem); } } diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index b7868c0b..ed57620e 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -90,10 +90,13 @@ connect_to_backend(struct vbe_conn *vc, struct backend *bp) memset(&hint, 0, sizeof hint); hint.ai_family = PF_UNSPEC; hint.ai_socktype = SOCK_STREAM; + res = NULL; error = getaddrinfo(bp->hostname, bp->portname == NULL ? "http" : bp->portname, &hint, &res); if (error) { + if (res != NULL) + freeaddrinfo(res); fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error)); return; @@ -138,6 +141,7 @@ vbe_rdp(int fd, short event __unused, void *arg __unused) if (vc->fd < 0) { vc->vbe->nconn--; free(vc); + VSL_stats->n_vbe_conn--; } else { vc->inuse = 0; event_add(&vc->ev, NULL); @@ -172,6 +176,7 @@ vbe_rdf(int fd, short event __unused, void *arg) event_del(&vc->ev); close(vc->fd); free(vc); + VSL_stats->n_vbe_conn--; } /* Backend monitoring thread -----------------------------------------*/ @@ -220,6 +225,7 @@ VBE_GetFd(struct backend *bp, void **ptr, unsigned xid) if (vp == NULL) { vp = calloc(sizeof *vp, 1); assert(vp != NULL); + VSL_stats->n_vbe++; TAILQ_INIT(&vp->fconn); TAILQ_INIT(&vp->bconn); vp->ip = bp->ip; @@ -235,6 +241,7 @@ VBE_GetFd(struct backend *bp, void **ptr, unsigned xid) AZ(pthread_mutex_unlock(&vbemtx)); } else { vc = calloc(sizeof *vc, 1); + VSL_stats->n_vbe_conn++; assert(vc != NULL); vc->vbe = vp; vc->fd = -1; diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 6c9f5e19..685b7483 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -287,6 +287,7 @@ FetchSession(struct worker *w, struct sess *sp) cls = 0; sbuf_finish(w->sb); sp->obj->header = strdup(sbuf_data(w->sb)); + VSL_stats->n_header++; vca_write_obj(w, sp); diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index e2785cfb..df193be4 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -33,6 +33,7 @@ HSH_Lookup(struct worker *w, struct http *h) assert(w->nobjhead != NULL); TAILQ_INIT(&w->nobjhead->objects); AZ(pthread_mutex_init(&w->nobjhead->mtx, NULL)); + VSL_stats->n_objecthead++; } if (w->nobj == NULL) { w->nobj = calloc(sizeof *w->nobj, 1); @@ -40,6 +41,7 @@ HSH_Lookup(struct worker *w, struct http *h) w->nobj->busy = 1; TAILQ_INIT(&w->nobj->store); AZ(pthread_cond_init(&w->nobj->cv, NULL)); + VSL_stats->n_object++; } assert(http_GetURL(h, &b)); @@ -110,7 +112,10 @@ HSH_Deref(struct object *o) if (o == NULL) return; - free(o->header); + if (o->header != NULL) { + free(o->header); + VSL_stats->n_header--; + } AZ(pthread_cond_destroy(&o->cv)); TAILQ_FOREACH_SAFE(st, &o->store, list, stn) { @@ -118,12 +123,14 @@ HSH_Deref(struct object *o) st->stevedore->free(st); } free(o); + VSL_stats->n_object--; /* Drop our ref on the objhead */ if (hash->deref(oh)) return; assert(TAILQ_EMPTY(&oh->objects)); AZ(pthread_mutex_destroy(&oh->mtx)); + VSL_stats->n_objecthead--; free(oh); } diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 914fa472..7ff5a8c3 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -53,6 +53,7 @@ http_New(void) hp = calloc(sizeof *hp, 1); assert(hp != NULL); + VSL_stats->n_http++; hp->s = malloc(http_bufsize); assert(hp->s != NULL); @@ -74,6 +75,7 @@ http_Delete(struct http *hp) free(hp->hdr); free(hp->s); free(hp); + VSL_stats->n_http--; } /*--------------------------------------------------------------------*/ @@ -369,10 +371,12 @@ http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *f unsigned l; assert(hp != NULL); + VSL(SLT_Debug, fd, "Recv t %u v %u", hp->t - hp->s, hp->v - hp->s); if (hp->t > hp->s && hp->t < hp->v) { l = hp->v - hp->t; memmove(hp->s, hp->t, l); hp->v = hp->s + l; + hp->t = hp->s; if (http_header_complete(hp)) { func(arg, 1); return; diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index 90c276e7..6bd9ba9a 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -22,6 +22,7 @@ #include #include "libvarnish.h" +#include "shmlog.h" #include "cache.h" #define MINPAGES 128 @@ -284,6 +285,7 @@ alloc_smf(struct smf_sc *sc, size_t bytes) /* Split from front */ sp2 = malloc(sizeof *sp2); assert(sp2 != NULL); + VSL_stats->n_smf++; *sp2 = *sp; sp->offset += bytes; @@ -320,6 +322,7 @@ free_smf(struct smf *sp) TAILQ_REMOVE(&sc->order, sp2, order); TAILQ_REMOVE(&sc->free, sp2, status); free(sp2); + VSL_stats->n_smf--; } sp2 = TAILQ_PREV(sp, smfhead, order); @@ -331,6 +334,7 @@ free_smf(struct smf *sp) sp2->age = sp->age; TAILQ_REMOVE(&sc->order, sp, order); free(sp); + VSL_stats->n_smf--; TAILQ_REMOVE(&sc->free, sp2, status); sp = sp2; } @@ -359,6 +363,7 @@ trim_smf(struct smf *sp, size_t bytes) assert(bytes > 0); sp2 = malloc(sizeof *sp2); assert(sp2 != NULL); + VSL_stats->n_smf++; *sp2 = *sp; sp2->size -= bytes; @@ -381,6 +386,7 @@ new_smf(struct smf_sc *sc, unsigned char *ptr, off_t off, size_t len) sp = calloc(sizeof *sp, 1); assert(sp != NULL); + VSL_stats->n_smf++; sp->sc = sc; diff --git a/varnish-cache/include/stat_field.h b/varnish-cache/include/stat_field.h index 74948271..87f39b8d 100644 --- a/varnish-cache/include/stat_field.h +++ b/varnish-cache/include/stat_field.h @@ -9,3 +9,13 @@ MAC_STAT(cache_miss, uint64_t, "u", "Cache misses") MAC_STAT(backend_conn, uint64_t, "u", "Backend connections initiated") MAC_STAT(backend_recycle, uint64_t, "u", "Backend connections recyles") +MAC_STAT(n_sess, uint64_t, "u", "N struct sess"); +MAC_STAT(n_object, uint64_t, "u", "N struct object"); +MAC_STAT(n_objecthead, uint64_t, "u", "N struct objecthead"); +MAC_STAT(n_header, uint64_t, "u", "N struct header"); +MAC_STAT(n_smf, uint64_t, "u", "N struct smf"); +MAC_STAT(n_http, uint64_t, "u", "N struct http"); +MAC_STAT(n_vbe, uint64_t, "u", "N struct vbe"); +MAC_STAT(n_vbe_conn, uint64_t, "u", "N struct vbe_conn"); + +