Commit 60d93181 authored by Federico G. Schwindt's avatar Federico G. Schwindt

Whitespace and format OCD

Also spring some VUT_Error() love.
parent d3984025
...@@ -56,8 +56,8 @@ ...@@ -56,8 +56,8 @@
#include "vut.h" #include "vut.h"
#include "vtim.h" #include "vtim.h"
#define HIST_N 2000 /* how far back we remember */ #define HIST_N 2000 /* how far back we remember */
#define HIST_RES 100 /* bucket resolution */ #define HIST_RES 100 /* bucket resolution */
static const char progname[] = "varnishhist"; static const char progname[] = "varnishhist";
...@@ -134,6 +134,7 @@ static struct profile *active_profile; ...@@ -134,6 +134,7 @@ static struct profile *active_profile;
static void static void
update(void) update(void)
{ {
char t[VTIM_FORMAT_SIZE];
unsigned w = COLS / hist_range; unsigned w = COLS / hist_range;
unsigned n = w * hist_range; unsigned n = w * hist_range;
unsigned bm[n], bh[n]; unsigned bm[n], bh[n];
...@@ -174,16 +175,15 @@ update(void) ...@@ -174,16 +175,15 @@ update(void)
scale = scales[i]; scale = scales[i];
if (vsl_t0 > 0) { if (vsl_t0 > 0) {
char t[VTIM_FORMAT_SIZE];
VTIM_format(vsl_ts, t); VTIM_format(vsl_ts, t);
mvprintw(0, 0, "1:%d, n = %d, d = %g @ %s x %g", mvprintw(0, 0, "1:%d, n = %d, d = %g @ %s x %g",
scale, nhist, delay, t, timebend); scale, nhist, delay, t, timebend);
} else { } else
mvprintw(0, 0, "1:%d, n = %d, d = %g", scale, nhist, delay); mvprintw(0, 0, "1:%d, n = %d, d = %g",
} scale, nhist, delay);
for (j = 2; j < LINES - 3; j+=5) for (j = 2; j < LINES - 3; j += 5)
mvprintw(j, 0, "%d_", (LINES - 3 - j) * scale); mvprintw(j, 0, "%d_", (LINES - 3 - j) * scale);
/* show them */ /* show them */
...@@ -218,7 +218,7 @@ upd_vsl_ts(const char *p) ...@@ -218,7 +218,7 @@ upd_vsl_ts(const char *p)
static int /*__match_proto__ (VSLQ_dispatch_f)*/ static int /*__match_proto__ (VSLQ_dispatch_f)*/
accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
void *priv) void *priv)
{ {
int i, tag, skip, match, hit; int i, tag, skip, match, hit;
unsigned u; unsigned u;
...@@ -242,7 +242,7 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], ...@@ -242,7 +242,7 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
while (skip == 0) { while (skip == 0) {
i = VSL_Next(tr->c); i = VSL_Next(tr->c);
if (i == -3) { if (i == -3) {
// overrun - need to skip forward /* overrun - need to skip forward */
pthread_mutex_lock(&mtx); pthread_mutex_lock(&mtx);
vsl_to = vsl_t0 = vsl_ts = 0; vsl_to = vsl_t0 = vsl_ts = 0;
t0 = VTIM_mono(); t0 = VTIM_mono();
...@@ -252,7 +252,7 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], ...@@ -252,7 +252,7 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
if (i != 1) if (i != 1)
break; break;
/* get the value we want, and register if it's a hit*/ /* get the value we want and register if it's a hit */
tag = VSL_TAG(tr->c->rec.ptr); tag = VSL_TAG(tr->c->rec.ptr);
switch (tag) { switch (tag) {
...@@ -261,9 +261,9 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], ...@@ -261,9 +261,9 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
break; break;
case SLT_VCL_return: case SLT_VCL_return:
if (!strcasecmp(VSL_CDATA(tr->c->rec.ptr), if (!strcasecmp(VSL_CDATA(tr->c->rec.ptr),
"restart") || "restart") ||
!strcasecmp(VSL_CDATA(tr->c->rec.ptr), !strcasecmp(VSL_CDATA(tr->c->rec.ptr),
"retry")) "retry"))
skip = 1; skip = 1;
break; break;
case SLT_Timestamp: case SLT_Timestamp:
...@@ -274,12 +274,12 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], ...@@ -274,12 +274,12 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
if (active_profile->prefix && if (active_profile->prefix &&
strncmp(VSL_CDATA(tr->c->rec.ptr), strncmp(VSL_CDATA(tr->c->rec.ptr),
active_profile->prefix, active_profile->prefix,
strlen(active_profile->prefix)) != 0) strlen(active_profile->prefix)) != 0)
break; break;
i = sscanf(VSL_CDATA(tr->c->rec.ptr), format, i = sscanf(VSL_CDATA(tr->c->rec.ptr),
&value); format, &value);
if (i != 1) if (i != 1)
break; break;
match = 1; match = 1;
...@@ -291,8 +291,8 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], ...@@ -291,8 +291,8 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
continue; continue;
/* /*
* only parse the last tsp seen in this transaction - it should * only parse the last tsp seen in this transaction -
* be the latest * it should be the latest.
*/ */
upd_vsl_ts(tsp); upd_vsl_ts(tsp);
...@@ -356,7 +356,7 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], ...@@ -356,7 +356,7 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
// Lck_CondWait // Lck_CondWait
ts.tv_nsec = (long)(modf(when, &t) * 1e9); ts.tv_nsec = (long)(modf(when, &t) * 1e9);
ts.tv_sec = (long)t; ts.tv_sec = (long)t;
(void) pthread_cond_timedwait(&timebend_cv, &mtx, &ts); (void)pthread_cond_timedwait(&timebend_cv, &mtx, &ts);
} }
pthread_mutex_unlock(&mtx); pthread_mutex_unlock(&mtx);
...@@ -396,17 +396,17 @@ do_curses(void *arg) ...@@ -396,17 +396,17 @@ do_curses(void *arg)
erase(); erase();
break; break;
#endif #endif
case '\014': /* Ctrl-L */ case '\014': /* Ctrl-L */
case '\024': /* Ctrl-T */ case '\024': /* Ctrl-T */
redrawwin(stdscr); redrawwin(stdscr);
refresh(); refresh();
break; break;
case '\032': /* Ctrl-Z */ case '\032': /* Ctrl-Z */
endwin(); endwin();
raise(SIGTSTP); raise(SIGTSTP);
break; break;
case '\003': /* Ctrl-C */ case '\003': /* Ctrl-C */
case '\021': /* Ctrl-Q */ case '\021': /* Ctrl-Q */
case 'Q': case 'Q':
case 'q': case 'q':
raise(SIGINT); raise(SIGINT);
...@@ -434,7 +434,7 @@ do_curses(void *arg) ...@@ -434,7 +434,7 @@ do_curses(void *arg)
break; break;
case '>': case '>':
case '<': case '<':
// see below /* see below */
break; break;
default: default:
beep(); beep();
...@@ -467,7 +467,7 @@ usage(int status) ...@@ -467,7 +467,7 @@ usage(int status)
fprintf(stderr, "Usage: %s <options>\n\n", progname); fprintf(stderr, "Usage: %s <options>\n\n", progname);
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
for (opt = vopt_spec.vopt_usage; *opt != NULL; opt +=2) for (opt = vopt_spec.vopt_usage; *opt != NULL; opt += 2)
fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1)); fprintf(stderr, " %-25s %s\n", *opt, *(opt + 1));
exit(status); exit(status);
} }
...@@ -476,7 +476,7 @@ static void ...@@ -476,7 +476,7 @@ static void
profile_error(const char *s) profile_error(const char *s)
{ {
fprintf(stderr, "-P: '%s' is not a valid" fprintf(stderr, "-P: '%s' is not a valid"
" profile name or definition\n", s); " profile name or definition\n", s);
exit(1); exit(1);
} }
...@@ -501,14 +501,12 @@ main(int argc, char **argv) ...@@ -501,14 +501,12 @@ main(int argc, char **argv)
usage(0); usage(0);
case 'p': case 'p':
delay = strtod(optarg, NULL); delay = strtod(optarg, NULL);
if (delay <= 0) { if (delay <= 0)
fprintf(stderr, "-p: invalid '%s'\n", optarg); VUT_Error(1, "-p: invalid '%s'", optarg);
exit(1);
}
break; break;
case 'P': case 'P':
colon = strchr(optarg, ':'); colon = strchr(optarg, ':');
/* no colon, take the profile as a name*/ /* no colon, take the profile as a name */
if (colon == NULL) { if (colon == NULL) {
profile = optarg; profile = optarg;
break; break;
...@@ -527,18 +525,15 @@ main(int argc, char **argv) ...@@ -527,18 +525,15 @@ main(int argc, char **argv)
} }
assert(colon); assert(colon);
if (sscanf(colon+1, "%d:%d:%d", &cli_p.field, if (sscanf(colon + 1, "%d:%d:%d", &cli_p.field,
&cli_p.hist_low, &cli_p.hist_high) != 3) { &cli_p.hist_low, &cli_p.hist_high) != 3)
profile_error(optarg); profile_error(optarg);
}
match_tag = VSL_Name2Tag(ptag, colon - ptag); match_tag = VSL_Name2Tag(ptag, colon - ptag);
if (match_tag < 0) { if (match_tag < 0)
fprintf(stderr, VUT_Error(1,
"-P: '%s' is not a valid tag name\n", "-P: '%s' is not a valid tag name",
optarg); optarg);
exit(1);
}
cli_p.name = "custom"; cli_p.name = "custom";
cli_p.tag = match_tag; cli_p.tag = match_tag;
profile = NULL; profile = NULL;
...@@ -547,20 +542,16 @@ main(int argc, char **argv) ...@@ -547,20 +542,16 @@ main(int argc, char **argv)
break; break;
case 'B': case 'B':
timebend = strtod(optarg, NULL); timebend = strtod(optarg, NULL);
if (timebend == 0) { if (timebend == 0)
fprintf(stderr, VUT_Error(1,
"-B: being able to bend time does not" "-B: being able to bend time does not"
" mean we can stop it" " mean we can stop it"
" (invalid factor '%s')\n", optarg); " (invalid factor '%s')", optarg);
exit(1); if (timebend < 0)
} VUT_Error(1,
if (timebend < 0) {
fprintf(stderr,
"-B: being able to bend time does not" "-B: being able to bend time does not"
" mean we can make it go backwards" " mean we can make it go backwards"
" (invalid factor '%s')\n", optarg); " (invalid factor '%s')", optarg);
exit(1);
}
break; break;
default: default:
if (!VUT_Arg(i, optarg)) if (!VUT_Arg(i, optarg))
...@@ -580,16 +571,13 @@ main(int argc, char **argv) ...@@ -580,16 +571,13 @@ main(int argc, char **argv)
if (profile) { if (profile) {
for (active_profile = profiles; active_profile->name; for (active_profile = profiles; active_profile->name;
active_profile++) { active_profile++) {
if (strcmp(active_profile->name, profile) == 0) { if (strcmp(active_profile->name, profile) == 0)
break; break;
}
} }
} }
if (! active_profile->name) { if (!active_profile->name)
fprintf(stderr, "-P: No such profile '%s'\n", profile); VUT_Error(1, "-P: No such profile '%s'", profile);
exit(1);
}
assert(VUT_Arg(active_profile->VSL_arg, NULL)); assert(VUT_Arg(active_profile->VSL_arg, NULL));
match_tag = active_profile->tag; match_tag = active_profile->tag;
...@@ -606,19 +594,15 @@ main(int argc, char **argv) ...@@ -606,19 +594,15 @@ main(int argc, char **argv)
t0 = VTIM_mono(); t0 = VTIM_mono();
format = malloc(4 * fnum); format = malloc(4 * fnum);
for (i = 0; i < fnum-1; i++) { for (i = 0; i < fnum - 1; i++)
strcpy(format + 4*i, "%*s "); strcpy(format + 4 * i, "%*s ");
} strcpy(format + 4 * (fnum - 1), "%lf");
strcpy(format + 4*(fnum-1), "%lf");
log_ten = log(10.0); log_ten = log(10.0);
VUT_Setup(); VUT_Setup();
if (pthread_create(&thr, NULL, do_curses, NULL) != 0) { if (pthread_create(&thr, NULL, do_curses, NULL) != 0)
fprintf(stderr, "pthread_create(): %s\n", VUT_Error(1, "pthread_create(): %s", strerror(errno));
strerror(errno));
exit(1);
}
VUT.dispatch_f = &accumulate; VUT.dispatch_f = &accumulate;
VUT.dispatch_priv = NULL; VUT.dispatch_priv = NULL;
VUT.sighup_f = sighup; VUT.sighup_f = sighup;
......
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