r4893 - in trunk/varnish-cache: bin/varnishstat include lib/libvarnishapi
phk at varnish-cache.org
phk at varnish-cache.org
Sat Jun 5 12:03:27 CEST 2010
Author: phk
Date: 2010-06-05 12:03:27 +0200 (Sat, 05 Jun 2010)
New Revision: 4893
Modified:
trunk/varnish-cache/bin/varnishstat/varnishstat.c
trunk/varnish-cache/include/varnishapi.h
trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
Log:
Tighten prototype consting.
Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 09:58:51 UTC (rev 4892)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 10:03:27 UTC (rev 4893)
@@ -81,57 +81,121 @@
return (!match_value);
}
+/*--------------------------------------------------------------------*/
+
+struct xml_priv {
+ const char *fields;
+};
+
+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 */
+{
+ uint64_t val;
+ struct xml_priv *xp;
+
+ xp = priv;
+ if (xp->fields != NULL && !show_field(nm, xp->fields))
+ return (0);
+ assert(!strcmp(fmt, "uint64_t"));
+ val = *(const volatile uint64_t*)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);
+ 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</stat>\n");
+ return (0);
+}
+
static void
-do_xml(const struct varnish_stats *VSL_stats, const char* fields)
+do_xml(struct VSL_data *vd, const char* fields)
{
char time_stamp[20];
time_t now;
+ struct xml_priv xp;
+ xp.fields = fields;
+
printf("<?xml version=\"1.0\"?>\n");
now = time(NULL);
(void)strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now));
printf("<varnishstat timestamp=\"%s\">\n", time_stamp);
-#define MAC_STAT(n, t, l, f, d) \
- do { \
- if (fields != NULL && ! show_field( #n, fields )) \
- break; \
- intmax_t ju = VSL_stats->n; \
- printf("\t<stat>\n"); \
- printf("\t\t<name>%s</name>\n", #n); \
- printf("\t\t<value>%ju</value>\n", ju); \
- printf("\t\t<description>%s</description>\n", d); \
- printf("\t</stat>\n"); \
- } while (0);
-#include "stat_field.h"
-#undef MAC_STAT
+ (void)VSL_IterStat(vd, do_xml_cb, &xp);
printf("</varnishstat>\n");
}
+/*--------------------------------------------------------------------*/
+
+struct once_priv {
+ double up;
+ const char *fields;
+ int pad;
+};
+
+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 */
+{
+ struct once_priv *op;
+ uint64_t val;
+ int i;
+
+ op = priv;
+ if (op->fields != NULL && !show_field(nm, op->fields))
+ return (0);
+ assert(!strcmp(fmt, "uint64_t"));
+ val = *(const volatile uint64_t*)ptr;
+ i = 0;
+ if (strcmp(type, ""))
+ i += printf("%s.", type);
+ if (strcmp(ident, ""))
+ i += printf("%s.", ident);
+ i += printf("%s", 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);
+ else
+ printf("%12ju %12s %s\n", val, ". ", desc);
+ return (0);
+}
+
static void
-do_once(const struct varnish_stats *VSL_stats, const char* fields)
+do_once(struct VSL_data *vd, const struct varnish_stats *VSL_stats, const char* fields)
{
- struct timeval tv;
- double up;
+ struct once_priv op;
- AZ(gettimeofday(&tv, NULL));
- up = VSL_stats->uptime;
+ memset(&op, 0, sizeof op);
+ op.up = VSL_stats->uptime;
+ op.fields = fields;
+ op.pad = 18;
-#define MAC_STAT(n, t, l, ff, d) \
- do { \
- if (fields != NULL && ! show_field( #n, fields )) \
- break; \
- intmax_t ju = VSL_stats->n; \
- if (ff == 'a') \
- printf("%-16s %12ju %12.2f %s\n", \
- #n, ju, ju / up, d); \
- else \
- printf("%-16s %12ju %12s %s\n", \
- #n, ju, ". ", d); \
- } while (0);
-#include "stat_field.h"
-#undef MAC_STAT
+ (void)VSL_IterStat(vd, do_once_cb, &op);
}
+/*--------------------------------------------------------------------*/
+
static void
usage(void)
{
@@ -266,9 +330,9 @@
}
if (xml)
- do_xml(VSL_stats, fields);
+ do_xml(vd, fields);
else if (once)
- do_once(VSL_stats, fields);
+ do_once(vd, VSL_stats, fields);
else
do_curses(vd, VSL_stats, delay, fields);
Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h 2010-06-05 09:58:51 UTC (rev 4892)
+++ trunk/varnish-cache/include/varnishapi.h 2010-06-05 10:03:27 UTC (rev 4893)
@@ -79,8 +79,8 @@
const char *fmt, /* field format ("uint64_t") */
int flag, /* 'a' = counter, 'i' = gauge */
const char *desc, /* description */
- volatile void *ptr); /* field value */
+ const volatile void * const ptr); /* field value */
-int VSL_IterStat(struct VSL_data *vd, vsl_stat_f *func, void *priv);
+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 09:58:51 UTC (rev 4892)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 10:03:27 UTC (rev 4893)
@@ -96,7 +96,7 @@
}
int
-VSL_IterStat(struct VSL_data *vd, vsl_stat_f *func, void *priv)
+VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv)
{
struct shmalloc *sha;
int i;
More information about the varnish-commit
mailing list