Commit 75b40a64 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Start segmenting stats, so that we can have per-whatever stats, starting

with -smalloc stats:

Split SMA relevant fields into their own MAC_STAT_SMA macros, and make it
possible to include stat_field.h without all MAC_STAT* macrods defined.

Move SMA relevant fields from struct varnish_stats to their own 
varnish_stats_sma.

Teach varnishstat to enumerate fields from a varnish_stats_sma.  (This
code looks like it should/could be much more general, and probably
libvarnisapi candidate).  For now only curses mode updated.

In storage_malloc.c, allocate a shm_alloc for a struct varnish_stats_sma
for each instance (in ->ready(), because we have no shm during arg
processing in ->init(), update the counters therein.




git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4855 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 7a3459ac
......@@ -301,7 +301,8 @@ mgt_SHM_Init(const char *fn, const char *l_arg)
bprintf(loghead->head.class, "%s", "Free");
MEMORY_BARRIER();
VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, VSL_CLASS_STAT, "", "");
VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats,
VSL_CLASS_STAT, VSL_TYPE_STAT, "");
AN(VSL_stats);
pp = mgt_SHM_Alloc(sizeof *pp, "Params", "", "");
......
......@@ -48,6 +48,7 @@ struct sma_sc {
#define SMA_SC_MAGIC 0x1ac8a345
struct lock sma_mtx;
size_t sma_max;
struct varnish_stats_sma *stats;
};
struct sma {
......@@ -67,13 +68,13 @@ sma_alloc(struct stevedore *st, size_t size, struct objcore *oc)
CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
(void)oc;
Lck_Lock(&sma_sc->sma_mtx);
VSL_stats->sma_nreq++;
if (VSL_stats->sma_nbytes + size > sma_sc->sma_max)
sma_sc->stats->sma_nreq++;
if (sma_sc->stats->sma_nbytes + size > sma_sc->sma_max)
size = 0;
else {
VSL_stats->sma_nobj++;
VSL_stats->sma_nbytes += size;
VSL_stats->sma_balloc += size;
sma_sc->stats->sma_nobj++;
sma_sc->stats->sma_nbytes += size;
sma_sc->stats->sma_balloc += size;
}
Lck_Unlock(&sma_sc->sma_mtx);
......@@ -117,9 +118,9 @@ sma_free(struct storage *s)
sma_sc = sma->sc;
assert(sma->sz == sma->s.space);
Lck_Lock(&sma_sc->sma_mtx);
VSL_stats->sma_nobj--;
VSL_stats->sma_nbytes -= sma->sz;
VSL_stats->sma_bfree += sma->sz;
sma_sc->stats->sma_nobj--;
sma_sc->stats->sma_nbytes -= sma->sz;
sma_sc->stats->sma_bfree += sma->sz;
Lck_Unlock(&sma_sc->sma_mtx);
free(sma->s.ptr);
free(sma);
......@@ -140,8 +141,8 @@ sma_trim(struct storage *s, size_t size)
assert(size < sma->sz);
if ((p = realloc(sma->s.ptr, size)) != NULL) {
Lck_Lock(&sma_sc->sma_mtx);
VSL_stats->sma_nbytes -= (sma->sz - size);
VSL_stats->sma_bfree += sma->sz - size;
sma_sc->stats->sma_nbytes -= (sma->sz - size);
sma_sc->stats->sma_bfree += sma->sz - size;
sma->sz = size;
Lck_Unlock(&sma_sc->sma_mtx);
sma->s.ptr = p;
......@@ -156,6 +157,7 @@ sma_init(struct stevedore *parent, int ac, char * const *av)
uintmax_t u;
struct sma_sc *sc;
ASSERT_MGT();
ALLOC_OBJ(sc, SMA_SC_MAGIC);
AN(sc);
sc->sma_max = SIZE_MAX;
......@@ -180,6 +182,17 @@ sma_init(struct stevedore *parent, int ac, char * const *av)
}
static void
sma_ready(struct stevedore *st)
{
struct sma_sc *sma_sc;
CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
sma_sc->stats = mgt_SHM_Alloc(sizeof *sma_sc->stats,
VSL_CLASS_STAT, VSL_TYPE_STAT_SMA, st->ident);
memset(sma_sc->stats, 0, sizeof *sma_sc->stats);
}
static void
sma_open(const struct stevedore *st)
{
......@@ -193,6 +206,7 @@ const struct stevedore sma_stevedore = {
.magic = STEVEDORE_MAGIC,
.name = "malloc",
.init = sma_init,
.ready = sma_ready,
.open = sma_open,
.alloc = sma_alloc,
.free = sma_free,
......
......@@ -110,7 +110,6 @@ main_stat(void *ptr, const char *fields)
#undef MAC_STAT
}
#if 0
static void
sma_stat(struct shmalloc *sha, const char *fields)
{
......@@ -122,7 +121,6 @@ sma_stat(struct shmalloc *sha, const char *fields)
#include "stat_field.h"
#undef MAC_STAT_SMA
}
#endif
static void
prep_pts(struct VSL_data *vd, const char *fields)
......@@ -133,12 +131,10 @@ prep_pts(struct VSL_data *vd, const char *fields)
CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
if (strcmp(sha->class, VSL_CLASS_STAT))
continue;
if (!strcmp(sha->type, ""))
if (!strcmp(sha->type, VSL_TYPE_STAT))
main_stat(SHA_PTR(sha), fields);
#if 0
else if (!strcmp(sha->type, VSL_TYPE_STAT_SMA))
sma_stat(sha, fields);
#endif
else
fprintf(stderr, "Unknwon Statistics");
}
......
......@@ -32,6 +32,12 @@
* stats structure.
*/
#ifndef MAC_STAT
#define MAC_STAT(a, b, c, d, e)
#define __MAC_STAT
#endif
MAC_STAT(client_conn, uint64_t, 0, 'a', "Client connections accepted")
MAC_STAT(client_drop, uint64_t, 0, 'a', "Connection dropped, no sess/wrk")
MAC_STAT(client_req, uint64_t, 1, 'a', "Client requests received")
......@@ -118,12 +124,6 @@ MAC_STAT(sm_nobj, uint64_t, 0, 'i', "outstanding allocations")
MAC_STAT(sm_balloc, uint64_t, 0, 'i', "bytes allocated")
MAC_STAT(sm_bfree, uint64_t, 0, 'i', "bytes free")
MAC_STAT(sma_nreq, uint64_t, 0, 'a', "SMA allocator requests")
MAC_STAT(sma_nobj, uint64_t, 0, 'i', "SMA outstanding allocations")
MAC_STAT(sma_nbytes, uint64_t, 0, 'i', "SMA outstanding bytes")
MAC_STAT(sma_balloc, uint64_t, 0, 'i', "SMA bytes allocated")
MAC_STAT(sma_bfree, uint64_t, 0, 'i', "SMA bytes free")
MAC_STAT(sms_nreq, uint64_t, 0, 'a', "SMS allocator requests")
MAC_STAT(sms_nobj, uint64_t, 0, 'i', "SMS outstanding allocations")
MAC_STAT(sms_nbytes, uint64_t, 0, 'i', "SMS outstanding bytes")
......@@ -152,3 +152,24 @@ MAC_STAT(esi_errors, uint64_t, 0, 'a', "ESI parse errors (unlock)")
MAC_STAT(accept_fail, uint64_t, 0, 'a', "Accept failures")
MAC_STAT(client_drop_late, uint64_t, 0, 'a', "Connection dropped late")
MAC_STAT(uptime, uint64_t, 0, 'a', "Client uptime")
#ifdef __MAC_STAT
#undef MAC_STAT
#undef __MAC_STAT
#endif
#ifndef MAC_STAT_SMA
#define MAC_STAT_SMA(a, b, c, d, e)
#define __MAC_STAT_SMA
#endif
MAC_STAT_SMA(sma_nreq, uint64_t, 0, 'a', "Allocator requests")
MAC_STAT_SMA(sma_nobj, uint64_t, 0, 'i', "Outstanding allocations")
MAC_STAT_SMA(sma_nbytes, uint64_t, 0, 'i', "Outstanding bytes")
MAC_STAT_SMA(sma_balloc, uint64_t, 0, 'i', "Bytes allocated")
MAC_STAT_SMA(sma_bfree, uint64_t, 0, 'i', "Bytes free")
#ifdef __MAC_STAT_SMA
#undef MAC_STAT_SMA
#undef __MAC_STAT_SMA
#endif
......@@ -31,10 +31,18 @@
#include <stdint.h>
#define VSL_TYPE_STAT "Stats"
#define VSL_TYPE_STAT ""
struct varnish_stats {
#define MAC_STAT(n, t, l, f, e) t n;
#include "stat_field.h"
#undef MAC_STAT
};
#define VSL_TYPE_STAT_SMA "SMA"
struct varnish_stats_sma {
#define MAC_STAT_SMA(n, t, l, f, e) t n;
#include "stat_field.h"
#undef MAC_STAT_SMA
};
......@@ -261,7 +261,7 @@ VSL_OpenLog(struct VSL_data *vd)
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (VSL_Open(vd))
return (-1);
sha = vsl_find_alloc(vd, VSL_CLASS_LOG, "", "");
sha = vsl_find_alloc(vd, VSL_CLASS_LOG, VSL_TYPE_STAT_SMA, "");
assert(sha != NULL);
vd->log_start = SHA_PTR(sha);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment