r4898 - in trunk/varnish-cache: bin/varnishstat include lib/libvarnishapi
phk at varnish-cache.org
phk at varnish-cache.org
Sat Jun 5 14:40:56 CEST 2010
Author: phk
Date: 2010-06-05 14:40:56 +0200 (Sat, 05 Jun 2010)
New Revision: 4898
Modified:
trunk/varnish-cache/bin/varnishstat/varnishstat.c
trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
trunk/varnish-cache/include/varnishapi.h
trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
Log:
Wrap all the details in a struct for the VSL_IterStat() callback, it
is faster, more handy and easier to extend in the future.
Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 11:05:04 UTC (rev 4897)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 12:40:56 UTC (rev 4898)
@@ -88,34 +88,26 @@
};
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 @@
};
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);
}
Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 11:05:04 UTC (rev 4897)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 12:40:56 UTC (rev 4898)
@@ -71,45 +71,37 @@
};
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);
Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h 2010-06-05 11:05:04 UTC (rev 4897)
+++ trunk/varnish-cache/include/varnishapi.h 2010-06-05 12:40:56 UTC (rev 4898)
@@ -73,16 +73,18 @@
#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);
#endif
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 11:05:04 UTC (rev 4897)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 12:40:56 UTC (rev 4898)
@@ -67,11 +67,18 @@
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 @@
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"
More information about the varnish-commit
mailing list