Commit 8bcefb3f authored by Martin Blix Grydeland's avatar Martin Blix Grydeland Committed by Lasse Karstensen

varnishlog -k argument

Implement -k argument in vut for use with varnishlog. This takes as an
argument the number of log transactions to be processed before
exiting. Useful to stop varnishlog after a given set of log data has
been produced.

Drop -s from the 'not implemented yet' list as this option has very
limited usefullness.
parent 90f63914
......@@ -59,6 +59,7 @@ VUT_OPT_D
VUT_OPT_g
VUT_OPT_h
VSL_OPT_i
VUT_OPT_k
VSL_OPT_I
VSL_OPT_L
VUT_OPT_n
......
......@@ -21,20 +21,6 @@ The following options are available:
.. include:: ../include/varnishlog_options.rst
-k num
Only show the first num log transactions (or log records
in -g raw mode)
XXX: Not yet implemented
-s num
Skip the first num log transactions (or log records if
in -g raw mode)
XXX: Not yet implemented
SIGNALS
=======
......
......@@ -41,6 +41,7 @@ struct VUT {
int d_opt;
int D_opt;
int g_arg;
int k_arg;
char *P_arg;
char *q_arg;
char *r_arg;
......
......@@ -51,6 +51,12 @@
"Print program usage and exit" \
)
#define VUT_OPT_k \
VOPT("k:", "[-k num]", "Limit transactions", \
"Process this number of matching log transactions before" \
" exiting." \
)
#define VUT_OPT_n \
VOPT("n:", "[-n name]", "Varnish instance name", \
"Specify the name of the varnishd instance to get logs" \
......
......@@ -83,6 +83,24 @@ vut_sigusr1(int sig)
VUT.sigusr1 = 1;
}
static int __match_proto__(VSLQ_dispatch_f)
vut_dispatch(struct VSL_data *vsl, struct VSL_transaction * const trans[],
void *priv)
{
int i;
(void)priv;
if (VUT.k_arg == 0)
return (-1); /* End of file */
AN(VUT.dispatch_f);
i = VUT.dispatch_f(vsl, trans, VUT.dispatch_priv);
if (VUT.k_arg > 0)
VUT.k_arg--;
if (i >= 0 && VUT.k_arg == 0)
return (-1); /* End of file */
return (i);
}
void
VUT_Error(int status, const char *fmt, ...)
{
......@@ -114,6 +132,7 @@ int
VUT_Arg(int opt, const char *arg)
{
int i;
char *p;
switch (opt) {
case 'd':
......@@ -127,6 +146,12 @@ VUT_Arg(int opt, const char *arg)
case 'g':
/* Grouping */
return (VUT_g_Arg(arg));
case 'k':
/* Log transaction limit */
VUT.k_arg = (int)strtol(arg, &p, 10);
if (*p != '\0' || VUT.k_arg <= 0)
VUT_Error(1, "-k: Invalid number '%s'", arg);
return (1);
case 'n':
/* Varnish instance */
if (VUT.vsm == NULL)
......@@ -178,6 +203,7 @@ VUT_Init(const char *progname)
AZ(VUT.vsl);
VUT.vsl = VSL_New();
AN(VUT.vsl);
VUT.k_arg = -1;
}
void
......@@ -281,8 +307,7 @@ VUT_Main(void)
/* Flush and report any incomplete records */
VUT.sigusr1 = 0;
if (VUT.vslq != NULL)
VSLQ_Flush(VUT.vslq, VUT.dispatch_f,
VUT.dispatch_priv);
VSLQ_Flush(VUT.vslq, vut_dispatch, NULL);
}
if (VUT.vslq == NULL) {
......@@ -307,7 +332,7 @@ VUT_Main(void)
VUT_Error(0, "Log reacquired");
}
i = VSLQ_Dispatch(VUT.vslq, VUT.dispatch_f, VUT.dispatch_priv);
i = VSLQ_Dispatch(VUT.vslq, vut_dispatch, NULL);
if (i == 1)
/* Call again */
continue;
......@@ -330,7 +355,7 @@ VUT_Main(void)
/* XXX: Make continuation optional */
VSLQ_Flush(VUT.vslq, VUT.dispatch_f, VUT.dispatch_priv);
VSLQ_Flush(VUT.vslq, vut_dispatch, NULL);
VSLQ_Delete(&VUT.vslq);
AZ(VUT.vslq);
......
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