r4892 - in trunk/varnish-cache: include lib/libvarnishapi
phk at varnish-cache.org
phk at varnish-cache.org
Sat Jun 5 11:58:51 CEST 2010
Author: phk
Date: 2010-06-05 11:58:51 +0200 (Sat, 05 Jun 2010)
New Revision: 4892
Modified:
trunk/varnish-cache/include/varnishapi.h
trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
Log:
Add a new function for walking over all stats counters, including
dynamically allocated such.
Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h 2010-06-05 08:57:14 UTC (rev 4891)
+++ trunk/varnish-cache/include/varnishapi.h 2010-06-05 09:58:51 UTC (rev 4892)
@@ -71,4 +71,16 @@
#define VSL_FOREACH(var, vd) \
for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var)))
+typedef int vsl_stat_f(
+ void *priv, /* private context */
+ const char *type, /* stat struct type */
+ const char *ident, /* stat struct ident */
+ const char *nm, /* field name */
+ const char *fmt, /* field format ("uint64_t") */
+ int flag, /* 'a' = counter, 'i' = gauge */
+ const char *desc, /* description */
+ volatile void *ptr); /* field value */
+
+int VSL_IterStat(struct VSL_data *vd, vsl_stat_f *func, void *priv);
+
#endif
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 08:57:14 UTC (rev 4891)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 09:58:51 UTC (rev 4892)
@@ -34,6 +34,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <string.h>
#include "vas.h"
#include "shmlog.h"
@@ -57,3 +58,62 @@
assert(sha != NULL);
return (SHA_PTR(sha));
}
+
+/*--------------------------------------------------------------------
+ * -1 -> unknown stats encountered.
+ */
+
+static int
+iter_main(struct shmalloc *sha, vsl_stat_f *func, void *priv)
+{
+ struct varnish_stats *st = SHA_PTR(sha);
+ int i;
+
+#define MAC_STAT(nn, tt, ll, ff, dd) \
+ i = func(priv, "", "", \
+ #nn, #tt, ff, dd, &st->nn); \
+ if (i) \
+ return(i);
+#include "stat_field.h"
+#undef MAC_STAT
+ return (0);
+}
+
+static int
+iter_sma(struct shmalloc *sha, vsl_stat_f *func, void *priv)
+{
+ struct varnish_stats_sma *st = SHA_PTR(sha);
+ int i;
+
+#define MAC_STAT_SMA(nn, tt, ll, ff, dd) \
+ i = func(priv, VSL_TYPE_STAT_SMA, sha->ident, \
+ #nn, #tt, ff, dd, &st->nn); \
+ if (i) \
+ return(i);
+#include "stat_field.h"
+#undef MAC_STAT_SMA
+ return (0);
+}
+
+int
+VSL_IterStat(struct VSL_data *vd, vsl_stat_f *func, void *priv)
+{
+ struct shmalloc *sha;
+ int i;
+
+ i = 0;
+ VSL_FOREACH(sha, vd) {
+ CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
+ if (strcmp(sha->class, VSL_CLASS_STAT))
+ continue;
+ if (!strcmp(sha->type, VSL_TYPE_STAT))
+ i = iter_main(sha, func, priv);
+ else if (!strcmp(sha->type, VSL_TYPE_STAT_SMA))
+ i = iter_sma(sha, func, priv);
+ else
+ i = -1;
+ if (i != 0)
+ break;
+ }
+ return (i);
+}
More information about the varnish-commit
mailing list