r4855 - in trunk/varnish-cache: bin/varnishd bin/varnishstat include lib/libvarnishapi
phk at varnish-cache.org
phk at varnish-cache.org
Fri May 21 14:01:16 CEST 2010
Author: phk
Date: 2010-05-21 14:01:16 +0200 (Fri, 21 May 2010)
New Revision: 4855
Modified:
trunk/varnish-cache/bin/varnishd/mgt_shmem.c
trunk/varnish-cache/bin/varnishd/storage_malloc.c
trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
trunk/varnish-cache/include/stat_field.h
trunk/varnish-cache/include/stats.h
trunk/varnish-cache/lib/libvarnishapi/vsl.c
Log:
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.
Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-05-21 11:48:16 UTC (rev 4854)
+++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-05-21 12:01:16 UTC (rev 4855)
@@ -301,7 +301,8 @@
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", "", "");
Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-05-21 11:48:16 UTC (rev 4854)
+++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-05-21 12:01:16 UTC (rev 4855)
@@ -48,6 +48,7 @@
#define SMA_SC_MAGIC 0x1ac8a345
struct lock sma_mtx;
size_t sma_max;
+ struct varnish_stats_sma *stats;
};
struct sma {
@@ -67,13 +68,13 @@
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_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 @@
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 @@
uintmax_t u;
struct sma_sc *sc;
+ ASSERT_MGT();
ALLOC_OBJ(sc, SMA_SC_MAGIC);
AN(sc);
sc->sma_max = SIZE_MAX;
@@ -181,6 +183,17 @@
}
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)
{
struct sma_sc *sma_sc;
@@ -193,6 +206,7 @@
.magic = STEVEDORE_MAGIC,
.name = "malloc",
.init = sma_init,
+ .ready = sma_ready,
.open = sma_open,
.alloc = sma_alloc,
.free = sma_free,
Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-05-21 11:48:16 UTC (rev 4854)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-05-21 12:01:16 UTC (rev 4855)
@@ -110,7 +110,6 @@
#undef MAC_STAT
}
-#if 0
static void
sma_stat(struct shmalloc *sha, const char *fields)
{
@@ -122,7 +121,6 @@
#include "stat_field.h"
#undef MAC_STAT_SMA
}
-#endif
static void
prep_pts(struct VSL_data *vd, const char *fields)
@@ -133,12 +131,10 @@
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");
}
Modified: trunk/varnish-cache/include/stat_field.h
===================================================================
--- trunk/varnish-cache/include/stat_field.h 2010-05-21 11:48:16 UTC (rev 4854)
+++ trunk/varnish-cache/include/stat_field.h 2010-05-21 12:01:16 UTC (rev 4855)
@@ -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_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(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
Modified: trunk/varnish-cache/include/stats.h
===================================================================
--- trunk/varnish-cache/include/stats.h 2010-05-21 11:48:16 UTC (rev 4854)
+++ trunk/varnish-cache/include/stats.h 2010-05-21 12:01:16 UTC (rev 4855)
@@ -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
+};
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-05-21 11:48:16 UTC (rev 4854)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-05-21 12:01:16 UTC (rev 4855)
@@ -261,7 +261,7 @@
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);
More information about the varnish-commit
mailing list