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

Wrap all the details in a struct for the VSL_IterStat() callback, it

is faster, more handy and easier to extend in the future.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4898 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent f77d9668
......@@ -88,34 +88,26 @@ struct xml_priv {
};
static int
do_xml_cb(
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 */
const volatile void *const ptr) /* field value */
do_xml_cb(void *priv, const struct vsl_statpt * const pt)
{
uint64_t val;
struct xml_priv *xp;
xp = priv;
if (xp->fields != NULL && !show_field(nm, xp->fields))
if (xp->fields != NULL && !show_field(pt->nm, xp->fields))
return (0);
assert(!strcmp(fmt, "uint64_t"));
val = *(const volatile uint64_t*)ptr;
assert(!strcmp(pt->fmt, "uint64_t"));
val = *(const volatile uint64_t*)pt->ptr;
printf("\t<stat>\n");
if (strcmp(type, ""))
printf("\t\t<type>%s</type>\n", type);
if (strcmp(ident, ""))
printf("\t\t<ident>%s</ident>\n", ident);
printf("\t\t<name>%s</name>\n", nm);
if (strcmp(pt->type, ""))
printf("\t\t<type>%s</type>\n", pt->type);
if (strcmp(pt->ident, ""))
printf("\t\t<ident>%s</ident>\n", pt->ident);
printf("\t\t<name>%s</name>\n", pt->nm);
printf("\t\t<value>%ju</value>\n", val);
printf("\t\t<flag>%c</flag>\n", flag);
printf("\t\t<description>%s</description>\n", desc);
printf("\t\t<flag>%c</flag>\n", pt->flag);
printf("\t\t<description>%s</description>\n", pt->desc);
printf("\t</stat>\n");
return (0);
}
......@@ -146,38 +138,30 @@ struct once_priv {
};
static int
do_once_cb(
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 */
const volatile void * const ptr) /* field value */
do_once_cb(void *priv, const struct vsl_statpt * const pt)
{
struct once_priv *op;
uint64_t val;
int i;
op = priv;
if (op->fields != NULL && !show_field(nm, op->fields))
if (op->fields != NULL && !show_field(pt->nm, op->fields))
return (0);
assert(!strcmp(fmt, "uint64_t"));
val = *(const volatile uint64_t*)ptr;
assert(!strcmp(pt->fmt, "uint64_t"));
val = *(const volatile uint64_t*)pt->ptr;
i = 0;
if (strcmp(type, ""))
i += printf("%s.", type);
if (strcmp(ident, ""))
i += printf("%s.", ident);
i += printf("%s", nm);
if (strcmp(pt->type, ""))
i += printf("%s.", pt->type);
if (strcmp(pt->ident, ""))
i += printf("%s.", pt->ident);
i += printf("%s", pt->nm);
if (i > op->pad)
op->pad = i + 1;
printf("%*.*s", op->pad - i, op->pad - i, "");
if (flag == 'a')
printf("%12ju %12.2f %s\n", val, val / op->up, desc);
if (pt->flag == 'a')
printf("%12ju %12.2f %s\n", val, val / op->up, pt->desc);
else
printf("%12ju %12s %s\n", val, ". ", desc);
printf("%12ju %12s %s\n", val, ". ", pt->desc);
return (0);
}
......
......@@ -71,45 +71,37 @@ struct curses_priv {
};
static int
do_curses_cb(
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 */
const volatile void *const ptr) /* field value */
do_curses_cb(void *priv, const struct vsl_statpt * const sp)
{
struct curses_priv *cp;
struct pt *pt;
char buf[128];
cp = priv;
if (cp->fields != NULL && !show_field(nm, cp->fields))
if (cp->fields != NULL && !show_field(sp->nm, cp->fields))
return (0);
assert(!strcmp(fmt, "uint64_t"));
assert(!strcmp(sp->fmt, "uint64_t"));
pt = calloc(sizeof *pt, 1);
AN(pt);
VTAILQ_INSERT_TAIL(&pthead, pt, next);
pt->ptr = ptr;
pt->ptr = sp->ptr;
pt->ref = *pt->ptr;
pt->type = flag;
pt->type = sp->flag;
*buf = '\0';
if (strcmp(type, "")) {
strcat(buf, type);
if (strcmp(sp->type, "")) {
strcat(buf, sp->type);
strcat(buf, ".");
}
if (strcmp(ident, "")) {
strcat(buf, ident);
if (strcmp(sp->ident, "")) {
strcat(buf, sp->ident);
strcat(buf, ".");
}
strcat(buf, nm);
strcat(buf, sp->nm);
strcat(buf, " - ");
strcat(buf, desc);
strcat(buf, sp->desc);
pt->name = strdup(buf);
AN(pt->name);
return (0);
......
......@@ -73,15 +73,17 @@ 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 */
const volatile void * const ptr); /* field value */
struct vsl_statpt {
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 */
const volatile void *ptr; /* field value */
};
typedef int vsl_stat_f(void *priv, const struct vsl_statpt *const pt);
int VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv);
......
......@@ -67,11 +67,18 @@ static int
iter_main(struct shmalloc *sha, vsl_stat_f *func, void *priv)
{
struct varnish_stats *st = SHA_PTR(sha);
struct vsl_statpt sp;
int i;
sp.type = "";
sp.ident = "";
#define MAC_STAT(nn, tt, ll, ff, dd) \
i = func(priv, "", "", \
#nn, #tt, ff, dd, &st->nn); \
sp.nm = #nn; \
sp.fmt = #tt; \
sp.flag = ff; \
sp.desc = dd; \
sp.ptr = &st->nn; \
i = func(priv, &sp); \
if (i) \
return(i);
#include "stat_field.h"
......@@ -83,11 +90,18 @@ static int
iter_sma(struct shmalloc *sha, vsl_stat_f *func, void *priv)
{
struct varnish_stats_sma *st = SHA_PTR(sha);
struct vsl_statpt sp;
int i;
sp.type = VSL_TYPE_STAT_SMA;
sp.ident = sha->ident;
#define MAC_STAT_SMA(nn, tt, ll, ff, dd) \
i = func(priv, VSL_TYPE_STAT_SMA, sha->ident, \
#nn, #tt, ff, dd, &st->nn); \
sp.nm = #nn; \
sp.fmt = #tt; \
sp.flag = ff; \
sp.desc = dd; \
sp.ptr = &st->nn; \
i = func(priv, &sp); \
if (i) \
return(i);
#include "stat_field.h"
......
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