Commit 2b26d783 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Rewrite curses support to use VSL_IterStat()



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4895 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 0768a431
......@@ -121,7 +121,7 @@ do_xml_cb(
}
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 @@ do_once_cb(
}
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;
......
......@@ -51,7 +51,6 @@ SVNID("$Id$")
#include "vqueue.h"
#include "varnishapi.h"
#include "varnishstat.h"
#include "miniobj.h"
#define AC(x) assert((x) != ERR)
......@@ -59,85 +58,72 @@ struct pt {
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);
strcat(buf, ".");
}
if (i != NULL) {
strcat(buf, i);
if (strcmp(ident, "")) {
strcat(buf, ident);
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)
{
struct varnish_stats *st = ptr;
#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
}
static void
sma_stat(struct shmalloc *sha, const char *fields)
prep_pts(struct VSL_data *vd, const char *fields)
{
struct varnish_stats_sma *st = SHA_PTR(sha);
struct curses_priv 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
}
cp.fields = fields;
static void
prep_pts(struct VSL_data *vd, const char *fields)
{
struct shmalloc *sha;
(void)VSL_IterStat(vd, do_curses_cb, &cp);
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
......
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