Commit 9372a68a authored by Geoff Simmons's avatar Geoff Simmons

implement and test formatters for %{Varnish:time_firstbyte}x

parent 5353d764
......@@ -277,7 +277,7 @@ format_h_##dir(tx_t *tx, char *name, enum VSL_tag_e tag, char **s, \
FORMAT_h(client, ReqStart, 0)
FORMAT_h(backend, Backend, 2)
static void
static inline void
format_IO_client(tx_t *tx, int req_fld, int pipe_fld, char **s, size_t *len)
{
int field;
......@@ -547,41 +547,39 @@ format_Xt(tx_t *tx, char *name, enum VSL_tag_e tag, char **s, size_t *len)
format_tim(tx, (const char *) name, s, len);
}
#if 0
static inline void
format_Xttfb(tx_t *tx, const char *tname, char **s, size_t *len)
{
char *ts;
static void
format_Xttfb_client(logline_t *ll, char *name, enum VSL_tag_e tag,
char **s, size_t *len)
ts = get_hdr(tx, SLT_Timestamp, tname);
if (ts == NULL)
return;
*s = get_fld(ts, 1);
*len = strlen(*s);
}
void
format_Xttfb_client(tx_t *tx, char *name, enum VSL_tag_e tag,
char **s, size_t *len)
{
(void) name;
(void) tag;
if (TAG(ll,SLT_ReqEnd).len)
RETURN_FLD(TAG(ll,SLT_ReqEnd), 5, s, len);
format_Xttfb(tx, "Process", s, len);
}
#ifdef BESTATS
static void
format_Xttfb_backend(logline_t *ll, char *name, enum VSL_tag_e tag,
char **s, size_t *len)
void
format_Xttfb_backend(tx_t *tx, char *name, enum VSL_tag_e tag,
char **s, size_t *len)
{
(void) name;
(void) tag;
if (TAG(ll,SLT_BackendReq).len && TAG(ll,SLT_Fetch_Hdr).len) {
double req_end, fetch_start;
errno = 0;
req_end = strtod(get_fld(&TAG(ll,SLT_BackendReq), 2), NULL);
AZ(errno);
fetch_start = strtod(get_fld(&TAG(ll,SLT_Fetch_Hdr), 2), NULL);
AZ(errno);
sprintf(scratch, "%.9f", fetch_start - req_end);
*s = scratch;
*len = strlen(scratch);
}
format_Xttfb(tx, "Beresp", s, len);
}
#endif
#if 0
static void
format_VCL_disp(logline_t *ll, char *name, enum VSL_tag_e tag,
......
......@@ -91,3 +91,6 @@ formatter_f format_Xo_client;
formatter_f format_Xo_backend;
formatter_f format_Xt;
formatter_f format_Xttfb_client;
formatter_f format_Xttfb_backend;
......@@ -1030,6 +1030,35 @@ static const char
return NULL;
}
static const char
*test_format_Xttfb(void)
{
tx_t tx;
logline_t rec;
chunk_t chunk;
char *str;
size_t len;
printf("... testing format_Xttfb_*()\n");
init_tx_rec_chunk(&tx, &rec, &chunk);
MAN(chunk.data);
#define TS_PROCESS_PAYLOAD "Process: 1427979230.712416 0.000166 0.000166"
set_record_data(&rec, &chunk, TS_PROCESS_PAYLOAD, SLT_Timestamp);
format_Xttfb_client(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "0.000166") == 0);
MASSERT(len == 8);
#define TS_BERESP_HDR_PAYLOAD "Beresp: 1427979243.588828 0.002837 0.002743"
set_record_data(&rec, &chunk, TS_BERESP_HDR_PAYLOAD, SLT_Timestamp);
format_Xttfb_backend(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "0.002837") == 0);
MASSERT(len == 8);
return NULL;
}
static const char
*all_tests(void)
{
......@@ -1057,6 +1086,7 @@ static const char
mu_run_test(test_format_Xi);
mu_run_test(test_format_Xo);
mu_run_test(test_format_Xt);
mu_run_test(test_format_Xttfb);
return NULL;
}
......
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