Commit 7b43a197 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Redo the dynamic stats CPP magic to require less replicated coding when

new structs are added.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5214 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 7b3607a4
......@@ -195,11 +195,13 @@ struct acct {
#define L0(n)
#define L1(n) int n;
#define VSC_F_MAIN(n, t, l, f, e) L##l(n)
#define VSC_F(n, t, l, f, e) L##l(n)
#define VSC_DO_MAIN
struct dstat {
#include "vsc_fields.h"
};
#undef VSC_F_MAIN
#undef VSC_F
#undef VSC_DO_MAIN
#undef L0
#undef L1
......
......@@ -96,9 +96,11 @@ wrk_sumstat(struct worker *w)
Lck_AssertHeld(&wstat_mtx);
#define L0(n)
#define L1(n) (VSC_main->n += w->stats.n)
#define VSC_F_MAIN(n, t, l, f, d) L##l(n);
#define VSC_DO_MAIN
#define VSC_F(n, t, l, f, d) L##l(n);
#include "vsc_fields.h"
#undef VSC_F_MAIN
#undef VSC_F
#undef VSC_DO_MAIN
#undef L0
#undef L1
memset(&w->stats, 0, sizeof w->stats);
......
......@@ -81,11 +81,13 @@ mcf_stats(struct cli *cli, const char * const *av, void *priv)
(void)priv;
AN(VSC_main);
#define VSC_F_MAIN(n, t, l, f, d) \
#define VSC_DO_MAIN
#define VSC_F(n, t, l, f, d) \
if (VSC_main->n != 0) \
cli_out(cli, "%12ju %s\n", (VSC_main->n), d);
#include "vsc_fields.h"
#undef VSC_F_MAIN
#undef VSC_F
#undef VSC_DO_MAIN
}
/*--------------------------------------------------------------------*/
......
......@@ -34,33 +34,17 @@
#define VSC_CLASS "Stat"
#define VSC_TYPE_MAIN ""
struct vsc_main {
#define VSC_F_MAIN(n, t, l, f, e) t n;
#include "vsc_fields.h"
#undef VSC_F_MAIN
};
#define VSC_TYPE_SMA "SMA"
struct vsc_sma {
#define VSC_F_SMA(n, t, l, f, e) t n;
#include "vsc_fields.h"
#undef VSC_F_SMA
};
#define VSC_TYPE_VBE "VBE"
#define VSC_TYPE_LCK "LCK"
struct vsc_vbe {
#define VSC_F_VBE(n, t, l, f, e) t n;
#include "vsc_fields.h"
#undef VSC_F_VBE
};
#define VSC_F(n, t, l, f, e) t n;
#define VSC_TYPE_LCK "LCK"
#define VSC_DO(u,l,t) struct vsc_##l {
#define VSC_DONE(u,l,t) };
#include "vsc_all.h"
struct vsc_lck {
#define VSC_F_LCK(n, t, l, f, e) t n;
#include "vsc_fields.h"
#undef VSC_F_LCK
};
#undef VSC_DO
#undef VSC_F
#undef VSC_DONE
/*-
* Copyright (c) 2010 Linpro AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
VSC_DO(MAIN, main, VSC_TYPE_MAIN)
#define VSC_DO_MAIN
#include "vsc_fields.h"
#undef VSC_DO_MAIN
VSC_DONE(MAIN, main, VSC_TYPE_MAIN)
VSC_DO(SMA, sma, VSC_TYPE_SMA)
#define VSC_DO_SMA
#include "vsc_fields.h"
#undef VSC_DO_SMA
VSC_DONE(SMA, sma, VSC_TYPE_SMA)
VSC_DO(VBE, vbe, VSC_TYPE_VBE)
#define VSC_DO_VBE
#include "vsc_fields.h"
#undef VSC_DO_VBE
VSC_DONE(VBE, vbe, VSC_TYPE_VBE)
VSC_DO(LCK, lck, VSC_TYPE_LCK)
#define VSC_DO_LCK
#include "vsc_fields.h"
#undef VSC_DO_LCK
VSC_DONE(LCK, lck, VSC_TYPE_LCK)
This diff is collapsed.
......@@ -283,117 +283,39 @@ iter_call(const struct vsc *vsc, vsc_iter_f *func, void *priv,
return (func(priv, sp));
}
static int
iter_main(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func,
void *priv)
{
struct vsc_main *st;
struct vsc_point sp;
int i;
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
st = VSM_PTR(sha);
sp.class = "";
sp.ident = "";
#define VSC_F_MAIN(nn, tt, ll, ff, dd) \
sp.name = #nn; \
sp.fmt = #tt; \
sp.flag = ff; \
sp.desc = dd; \
sp.ptr = &st->nn; \
i = iter_call(vsc, func, priv, &sp); \
if (i) \
return(i);
#include "vsc_fields.h"
#undef VSC_F_MAIN
return (0);
}
static int
iter_sma(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func,
void *priv)
{
struct vsc_sma *st;
struct vsc_point sp;
int i;
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
st = VSM_PTR(sha);
sp.class = VSC_TYPE_SMA;
sp.ident = sha->ident;
#define VSC_F_SMA(nn, tt, ll, ff, dd) \
sp.name = #nn; \
sp.fmt = #tt; \
sp.flag = ff; \
sp.desc = dd; \
sp.ptr = &st->nn; \
i = iter_call(vsc, func, priv, &sp); \
if (i) \
return(i);
#include "vsc_fields.h"
#undef VSC_F_SMA
return (0);
}
static int
iter_vbe(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func,
void *priv)
{
struct vsc_vbe *st;
struct vsc_point sp;
int i;
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
st = VSM_PTR(sha);
sp.class = VSC_TYPE_VBE;
sp.ident = sha->ident;
#define VSC_F_VBE(nn, tt, ll, ff, dd) \
sp.name = #nn; \
sp.fmt = #tt; \
sp.flag = ff; \
sp.desc = dd; \
sp.ptr = &st->nn; \
i = iter_call(vsc, func, priv, &sp); \
if (i) \
return(i);
#include "vsc_fields.h"
#undef VSC_F_VBE
return (0);
}
static int
iter_lck(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func,
void *priv)
{
struct vsc_lck *st;
struct vsc_point sp;
int i;
#define VSC_DO(U,l,t) \
static int \
iter_##l(const struct vsc *vsc, struct vsm_chunk *sha, \
vsc_iter_f *func, void *priv) \
{ \
struct vsc_##l *st; \
struct vsc_point sp; \
int i; \
\
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); \
CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); \
st = VSM_PTR(sha); \
sp.class = t; \
sp.ident = sha->ident;
#define VSC_F(nn,tt,ll,ff,dd) \
sp.name = #nn; \
sp.fmt = #tt; \
sp.flag = ff; \
sp.desc = dd; \
sp.ptr = &st->nn; \
i = iter_call(vsc, func, priv, &sp); \
if (i) \
return(i);
#define VSC_DONE(U,l,t) \
return (0); \
}
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
st = VSM_PTR(sha);
sp.class = VSC_TYPE_LCK;
sp.ident = sha->ident;
#define VSC_F_LCK(nn, tt, ll, ff, dd) \
sp.name = #nn; \
sp.fmt = #tt; \
sp.flag = ff; \
sp.desc = dd; \
sp.ptr = &st->nn; \
i = iter_call(vsc, func, priv, &sp); \
if (i) \
return(i);
#include "vsc_fields.h"
#undef VSC_F_LCK
return (0);
}
#include "vsc_all.h"
#undef VSC_DO
#undef VSC_F
#undef VSC_DONE
int
VSC_Iter(struct VSM_data *vd, vsc_iter_f *func, void *priv)
......@@ -411,18 +333,20 @@ VSC_Iter(struct VSM_data *vd, vsc_iter_f *func, void *priv)
CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
if (strcmp(sha->class, VSC_CLASS))
continue;
if (!strcmp(sha->type, VSC_TYPE_MAIN))
i = iter_main(vsc, sha, func, priv);
else if (!strcmp(sha->type, VSC_TYPE_SMA))
i = iter_sma(vsc, sha, func, priv);
else if (!strcmp(sha->type, VSC_TYPE_VBE))
i = iter_vbe(vsc, sha, func, priv);
else if (!strcmp(sha->type, VSC_TYPE_LCK))
i = iter_lck(vsc, sha, func, priv);
else
i = -1;
if (i != 0)
break;
#define VSC_F(a,b,c,d,e)
#define VSC_DONE(a,b,c)
#define VSC_DO(U,l,t) \
if (!strcmp(sha->type, t)) { \
i = iter_##l(vsc, sha, func, priv); \
if (!i) \
continue; \
}
#include "vsc_all.h"
#undef VSC_F
#undef VSC_DO
#undef VSC_DONE
break;
}
return (i);
}
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