Commit 1f3fbd8e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make VSC/varnishstat sorta-work again.

parent 6cc6f23f
...@@ -52,7 +52,9 @@ do_xml_cb(void *priv, const struct VSC_point * const pt) ...@@ -52,7 +52,9 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
uint64_t val; uint64_t val;
(void)priv; (void)priv;
assert(!strcmp(pt->fmt, "uint64_t")); if (pt == NULL)
return (0);
assert(!strcmp(pt->desc->fmt, "uint64_t"));
val = *(const volatile uint64_t*)pt->ptr; val = *(const volatile uint64_t*)pt->ptr;
printf("\t<stat>\n"); printf("\t<stat>\n");
...@@ -60,10 +62,10 @@ do_xml_cb(void *priv, const struct VSC_point * const pt) ...@@ -60,10 +62,10 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
printf("\t\t<type>%s</type>\n", pt->class); printf("\t\t<type>%s</type>\n", pt->class);
if (strcmp(pt->ident, "")) if (strcmp(pt->ident, ""))
printf("\t\t<ident>%s</ident>\n", pt->ident); printf("\t\t<ident>%s</ident>\n", pt->ident);
printf("\t\t<name>%s</name>\n", pt->name); printf("\t\t<name>%s</name>\n", pt->desc->name);
printf("\t\t<value>%ju</value>\n", val); printf("\t\t<value>%ju</value>\n", val);
printf("\t\t<flag>%c</flag>\n", pt->flag); printf("\t\t<flag>%c</flag>\n", pt->desc->flag);
printf("\t\t<description>%s</description>\n", pt->desc); printf("\t\t<description>%s</description>\n", pt->desc->sdesc);
printf("\t</stat>\n"); printf("\t</stat>\n");
return (0); return (0);
} }
...@@ -91,9 +93,11 @@ do_json_cb(void *priv, const struct VSC_point * const pt) ...@@ -91,9 +93,11 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
uint64_t val; uint64_t val;
int *jp; int *jp;
jp = priv; if (pt == NULL)
return (0);
assert(!strcmp(pt->fmt, "uint64_t")); jp = priv;
assert(!strcmp(pt->desc->fmt, "uint64_t"));
val = *(const volatile uint64_t*)pt->ptr; val = *(const volatile uint64_t*)pt->ptr;
if (*jp) *jp = 0; else printf(",\n"); if (*jp) *jp = 0; else printf(",\n");
...@@ -104,15 +108,15 @@ do_json_cb(void *priv, const struct VSC_point * const pt) ...@@ -104,15 +108,15 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
printf("%s.", pt->class); printf("%s.", pt->class);
if (pt->ident[0]) if (pt->ident[0])
printf("%s.", pt->ident); printf("%s.", pt->ident);
printf("%s\": {", pt->name); printf("%s\": {", pt->desc->name);
if (strcmp(pt->class, "")) printf("\"type\": \"%s\", ", pt->class); if (strcmp(pt->class, "")) printf("\"type\": \"%s\", ", pt->class);
if (strcmp(pt->ident, "")) printf("\"ident\": \"%s\", ", pt->ident); if (strcmp(pt->ident, "")) printf("\"ident\": \"%s\", ", pt->ident);
printf("\"value\": %ju, ", val); printf("\"value\": %ju, ", val);
printf("\"flag\": \"%c\", ", pt->flag); printf("\"flag\": \"%c\", ", pt->desc->flag);
printf("\"description\": \"%s\"", pt->desc); printf("\"description\": \"%s\"", pt->desc->sdesc);
printf("}"); printf("}");
if (*jp) printf("\n"); if (*jp) printf("\n");
...@@ -153,22 +157,24 @@ do_once_cb(void *priv, const struct VSC_point * const pt) ...@@ -153,22 +157,24 @@ do_once_cb(void *priv, const struct VSC_point * const pt)
uint64_t val; uint64_t val;
int i; int i;
if (pt == NULL)
return (0);
op = priv; op = priv;
assert(!strcmp(pt->fmt, "uint64_t")); assert(!strcmp(pt->desc->fmt, "uint64_t"));
val = *(const volatile uint64_t*)pt->ptr; val = *(const volatile uint64_t*)pt->ptr;
i = 0; i = 0;
if (strcmp(pt->class, "")) if (strcmp(pt->class, ""))
i += printf("%s.", pt->class); i += printf("%s.", pt->class);
if (strcmp(pt->ident, "")) if (strcmp(pt->ident, ""))
i += printf("%s.", pt->ident); i += printf("%s.", pt->ident);
i += printf("%s", pt->name); i += printf("%s", pt->desc->name);
if (i > op->pad) if (i > op->pad)
op->pad = i + 1; op->pad = i + 1;
printf("%*.*s", op->pad - i, op->pad - i, ""); printf("%*.*s", op->pad - i, op->pad - i, "");
if (pt->flag == 'a' || pt->flag == 'c') if (pt->desc->flag == 'a' || pt->desc->flag == 'c')
printf("%12ju %12.2f %s\n", val, val / op->up, pt->desc); printf("%12ju %12.2f %s\n", val, val / op->up, pt->desc->sdesc);
else else
printf("%12ju %12s %s\n", val, ". ", pt->desc); printf("%12ju %12s %s\n", val, ". ", pt->desc->sdesc);
return (0); return (0);
} }
...@@ -197,10 +203,10 @@ do_list_cb(void *priv, const struct VSC_point * const pt) ...@@ -197,10 +203,10 @@ do_list_cb(void *priv, const struct VSC_point * const pt)
i += fprintf(stderr, "%s.", pt->class); i += fprintf(stderr, "%s.", pt->class);
if (strcmp(pt->ident, "")) if (strcmp(pt->ident, ""))
i += fprintf(stderr, "%s.", pt->ident); i += fprintf(stderr, "%s.", pt->ident);
i += fprintf(stderr, "%s", pt->name); i += fprintf(stderr, "%s", pt->desc->name);
if (i < 30) if (i < 30)
fprintf(stderr, "%*s", i - 30, ""); fprintf(stderr, "%*s", i - 30, "");
fprintf(stderr, " %s\n", pt->desc); fprintf(stderr, " %s\n", pt->desc->sdesc);
return (0); return (0);
} }
...@@ -253,7 +259,6 @@ main(int argc, char * const *argv) ...@@ -253,7 +259,6 @@ main(int argc, char * const *argv)
int delay = 1, once = 0, xml = 0, json = 0, do_repeat = 0; int delay = 1, once = 0, xml = 0, json = 0, do_repeat = 0;
vd = VSM_New(); vd = VSM_New();
VSC_Setup(vd);
while ((c = getopt(argc, argv, VSC_ARGS "1f:lVw:xjt:")) != -1) { while ((c = getopt(argc, argv, VSC_ARGS "1f:lVw:xjt:")) != -1) {
switch (c) { switch (c) {
...@@ -261,8 +266,6 @@ main(int argc, char * const *argv) ...@@ -261,8 +266,6 @@ main(int argc, char * const *argv)
once = 1; once = 1;
break; break;
case 'l': case 'l':
if (VSC_Open(vd, 1))
exit(1);
list_fields(vd); list_fields(vd);
exit(0); exit(0);
case 'V': case 'V':
...@@ -285,9 +288,6 @@ main(int argc, char * const *argv) ...@@ -285,9 +288,6 @@ main(int argc, char * const *argv)
} }
} }
if (VSC_Open(vd, 1))
exit(1);
VSC_C_main = VSC_Main(vd); VSC_C_main = VSC_Main(vd);
AN(VSC_C_main); AN(VSC_C_main);
......
...@@ -81,7 +81,9 @@ do_curses_cb(void *priv, const struct VSC_point * const sp) ...@@ -81,7 +81,9 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
char buf[128]; char buf[128];
(void)priv; (void)priv;
assert(!strcmp(sp->fmt, "uint64_t")); if (sp == NULL)
return (0);
assert(!strcmp(sp->desc->fmt, "uint64_t"));
pt = calloc(sizeof *pt, 1); pt = calloc(sizeof *pt, 1);
AN(pt); AN(pt);
...@@ -89,7 +91,7 @@ do_curses_cb(void *priv, const struct VSC_point * const sp) ...@@ -89,7 +91,7 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
pt->ptr = sp->ptr; pt->ptr = sp->ptr;
pt->ref = *pt->ptr; pt->ref = *pt->ptr;
pt->flag = sp->flag; pt->flag = sp->desc->flag;
*buf = '\0'; *buf = '\0';
if (strcmp(sp->class, "")) { if (strcmp(sp->class, "")) {
...@@ -100,9 +102,9 @@ do_curses_cb(void *priv, const struct VSC_point * const sp) ...@@ -100,9 +102,9 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
strcat(buf, sp->ident); strcat(buf, sp->ident);
strcat(buf, "."); strcat(buf, ".");
} }
strcat(buf, sp->name); strcat(buf, sp->desc->name);
strcat(buf, " - "); strcat(buf, " - ");
strcat(buf, sp->desc); strcat(buf, sp->desc->sdesc);
pt->name = strdup(buf); pt->name = strdup(buf);
AN(pt->name); AN(pt->name);
return (0); return (0);
...@@ -144,7 +146,6 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main, ...@@ -144,7 +146,6 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
int ch, line; int ch, line;
struct pt *pt; struct pt *pt;
double act, lact; double act, lact;
unsigned seq;
(void)initscr(); (void)initscr();
AC(raw()); AC(raw());
...@@ -157,7 +158,6 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main, ...@@ -157,7 +158,6 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
/* /*
* Initialization goes in outher loop * Initialization goes in outher loop
*/ */
seq = VSM_Seq(vd);
prep_pts(vd); prep_pts(vd);
AC(erase()); AC(erase());
AC(refresh()); AC(refresh());
...@@ -170,15 +170,11 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main, ...@@ -170,15 +170,11 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
lact = 0; lact = 0;
while (1) { while (1) {
if (seq != VSM_Seq(vd))
break;
/* /*
* Break to outher loop if we need to re-read file. * Break to outher loop if we need to re-read file.
* Only check if it looks like nothing is happening. * Only check if it looks like nothing is happening.
*/ */
act = VSC_C_main->cache_hit + VSC_C_main->cache_miss + 1; act = VSC_C_main->cache_hit + VSC_C_main->cache_miss + 1;
if (act == lact && VSM_ReOpen(vd, 1))
break;
lact = act; lact = act;
AZ(gettimeofday(&tv, NULL)); AZ(gettimeofday(&tv, NULL));
......
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* This is the public API for the VSC access.
*
* VSC is a "subclass" of VSM.
*
*/ */
#ifndef VAPI_VSC_H_INCLUDED #ifndef VAPI_VSC_H_INCLUDED
...@@ -34,17 +38,12 @@ ...@@ -34,17 +38,12 @@
#include "vapi/vsc_int.h" #include "vapi/vsc_int.h"
struct VSM_data; struct VSM_data;
struct VSM_fantom;
/*--------------------------------------------------------------------- /*---------------------------------------------------------------------
* VSC level access functions * VSC level access functions
*/ */
void VSC_Setup(struct VSM_data *vd);
/*
* Setup vd for use with VSC functions.
* Must be called once before any other VSC function is called
*/
#define VSC_ARGS "f:n:" #define VSC_ARGS "f:n:"
#define VSC_n_USAGE VSM_n_USAGE #define VSC_n_USAGE VSM_n_USAGE
#define VSC_f_USAGE "[-f field_name,...]" #define VSC_f_USAGE "[-f field_name,...]"
...@@ -55,39 +54,58 @@ int VSC_Arg(struct VSM_data *vd, int arg, const char *opt); ...@@ -55,39 +54,58 @@ int VSC_Arg(struct VSM_data *vd, int arg, const char *opt);
/* /*
* Handle standard stat-presenter arguments * Handle standard stat-presenter arguments
* Return: * Return:
* -1 error * -1 error, VSM_Error() returns diagnostic string
* 0 not handled * 0 not handled
* 1 Handled. * 1 Handled.
*/ */
int VSC_Open(struct VSM_data *vd, int diag); struct VSC_C_main *VSC_Main(struct VSM_data *vd);
/*
* Open shared memory for VSC processing.
* args and returns as VSM_Open()
*/
struct VSC_C_main *VSC_Main(const struct VSM_data *vd);
/* /*
* return Main stats structure * return Main stats structure
* returns NULL until child has been started. * returns NULL until child has been started.
*/ */
struct VSC_desc {
const char *name; /* field name */
const char *fmt; /* field format ("uint64_t") */
int flag; /* 'c' = counter, 'g' = gauge */
const char *sdesc; /* short description */
const char *ldesc; /* long description */
};
struct VSC_point { struct VSC_point {
const char *class; /* stat struct type */ const char *class; /* stat struct type */
const char *ident; /* stat struct ident */ const char *ident; /* stat struct ident */
const char *name; /* field name */ const struct VSC_desc *desc; /* point description */
const char *fmt; /* field format ("uint64_t") */
int flag; /* 'a' = counter, 'i' = gauge */
const char *desc; /* description */
const volatile void *ptr; /* field value */ const volatile void *ptr; /* field value */
struct VSM_fantom *vf;
}; };
typedef int VSC_iter_f(void *priv, const struct VSC_point *const pt); typedef int VSC_iter_f(void *priv, const struct VSC_point *const pt);
int VSC_Iter(const struct VSM_data *vd, VSC_iter_f *func, void *priv); int VSC_Iter(struct VSM_data *vd, VSC_iter_f *func, void *priv);
/* /*
* Iterate over all statistics counters, calling "func" for * Iterate over all statistics counters, calling "func" for
* each counter not suppressed by any "-f" arguments. * each counter not suppressed by any "-f" arguments.
*
* Func is called with pt == NULL, whenever VSM allocations
* change (child restart, allocations/deallocations)
*
* Returns:
* !=0: func returned non-zero
* -1: No VSC's available
* 0: Done
*/ */
/**********************************************************************
* Precompiled VSC_desc's for all know VSCs.
*/
#define VSC_F(n,t,l,f,d,e)
#define VSC_DO(U,l,t) extern const struct VSC_desc VSC_desc_##l[];
#define VSC_DONE(U,l,t)
#include "tbl/vsc_all.h"
#undef VSC_F
#undef VSC_DO
#undef VSC_DONE
#endif /* VAPI_VSC_H_INCLUDED */ #endif /* VAPI_VSC_H_INCLUDED */
This diff is collapsed.
...@@ -113,7 +113,7 @@ VSM_n_Arg(struct VSM_data *vd, const char *opt) ...@@ -113,7 +113,7 @@ VSM_n_Arg(struct VSM_data *vd, const char *opt)
{ {
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
AN(vd->n_opt); AN(opt);
REPLACE(vd->n_opt, opt); REPLACE(vd->n_opt, opt);
if (VIN_N_Arg(vd->n_opt, NULL, NULL, &vd->fname)) if (VIN_N_Arg(vd->n_opt, NULL, NULL, &vd->fname))
......
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