Commit f25134aa authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a new function for walking over all stats counters, including

dynamically allocated such.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4892 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 38f03e75
......@@ -71,4 +71,16 @@ void vsl_itern(const struct VSL_data *vd, struct shmalloc **pp);
#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
......@@ -34,6 +34,7 @@ SVNID("$Id$")
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include "vas.h"
#include "shmlog.h"
......@@ -57,3 +58,62 @@ VSL_OpenStats(struct VSL_data *vd)
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);
}
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