r4895 - trunk/varnish-cache/bin/varnishstat
phk at varnish-cache.org
phk at varnish-cache.org
Sat Jun 5 12:16:01 CEST 2010
Author: phk
Date: 2010-06-05 12:16:01 +0200 (Sat, 05 Jun 2010)
New Revision: 4895
Modified:
trunk/varnish-cache/bin/varnishstat/varnishstat.c
trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
Log:
Rewrite curses support to use VSL_IterStat()
Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 10:04:39 UTC (rev 4894)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 10:16:01 UTC (rev 4895)
@@ -121,7 +121,7 @@
}
static void
-do_xml(struct VSL_data *vd, const char* fields)
+do_xml(const struct VSL_data *vd, const char* fields)
{
char time_stamp[20];
time_t now;
@@ -182,7 +182,7 @@
}
static void
-do_once(struct VSL_data *vd, const struct varnish_stats *VSL_stats, const char* fields)
+do_once(const struct VSL_data *vd, const struct varnish_stats *VSL_stats, const char* fields)
{
struct once_priv op;
Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 10:04:39 UTC (rev 4894)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 10:16:01 UTC (rev 4895)
@@ -51,7 +51,6 @@
#include "vqueue.h"
#include "varnishapi.h"
#include "varnishstat.h"
-#include "miniobj.h"
#define AC(x) assert((x) != ERR)
@@ -59,88 +58,75 @@
VTAILQ_ENTRY(pt) next;
const volatile uint64_t *ptr;
uint64_t ref;
- char type;
+ int type;
char seen;
const char *name;
};
static VTAILQ_HEAD(, pt) pthead = VTAILQ_HEAD_INITIALIZER(pthead);
-static struct pt *
-add_pt(const uint64_t *ptr, int type, const char *c, const char *t, const char *i)
+
+struct curses_priv {
+ const char *fields;
+};
+
+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 */
{
+ struct curses_priv *cp;
struct pt *pt;
char buf[128];
+ cp = priv;
+ if (cp->fields != NULL && !show_field(nm, cp->fields))
+ return (0);
+ assert(!strcmp(fmt, "uint64_t"));
+
pt = calloc(sizeof *pt, 1);
AN(pt);
VTAILQ_INSERT_TAIL(&pthead, pt, next);
pt->ptr = ptr;
- pt->ref = *ptr;
- pt->type = type;
+ pt->ref = *pt->ptr;
+ pt->type = flag;
*buf = '\0';
- if (c != NULL) {
- strcat(buf, c);
+ if (strcmp(type, "")) {
+ strcat(buf, type);
strcat(buf, ".");
}
- if (t != NULL) {
- strcat(buf, t);
+ if (strcmp(ident, "")) {
+ strcat(buf, ident);
strcat(buf, ".");
}
- if (i != NULL) {
- strcat(buf, i);
- strcat(buf, ".");
- }
+ strcat(buf, nm);
+ strcat(buf, " - ");
+ strcat(buf, desc);
pt->name = strdup(buf);
AN(pt->name);
- return (pt);
+ return (0);
}
static void
-main_stat(void *ptr, const char *fields)
+prep_pts(struct VSL_data *vd, const char *fields)
{
- struct varnish_stats *st = ptr;
+ struct curses_priv cp;
-#define MAC_STAT(nn, tt, ll, ff, dd) \
- if (fields == NULL || show_field( #nn, fields )) \
- (void)add_pt(&st->nn, ff, NULL, NULL, dd);
-#include "stat_field.h"
-#undef MAC_STAT
-}
+ cp.fields = fields;
-static void
-sma_stat(struct shmalloc *sha, const char *fields)
-{
- struct varnish_stats_sma *st = SHA_PTR(sha);
+ (void)VSL_IterStat(vd, do_curses_cb, &cp);
-#define MAC_STAT_SMA(nn, tt, ll, ff, dd) \
- if (fields == NULL || show_field( #nn, fields )) \
- (void)add_pt(&st->nn, ff, "SMA", sha->ident, dd);
-#include "stat_field.h"
-#undef MAC_STAT_SMA
}
static void
-prep_pts(struct VSL_data *vd, const char *fields)
-{
- struct shmalloc *sha;
-
- 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))
- main_stat(SHA_PTR(sha), fields);
- else if (!strcmp(sha->type, VSL_TYPE_STAT_SMA))
- sma_stat(sha, fields);
- else
- fprintf(stderr, "Unknwon Statistics");
- }
-}
-
-static void
myexp(double *acc, double val, unsigned *n, unsigned nmax)
{
More information about the varnish-commit
mailing list