From 5d5fe073c39a303ba43b6c1bb029943ee34f8a4a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 9 Dec 2014 17:30:36 +0100 Subject: httpress: add per-second stats on request counts We have absolute time, total time, relative time, total reqs, relative reqs, reqs per second. --- httpress.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/httpress.c b/httpress.c index 2b7e3ed..5d9bd68 100644 --- a/httpress.c +++ b/httpress.c @@ -92,6 +92,9 @@ struct config { }; static struct config config; +static struct timeval last_tv; +static struct timeval init_tv; +static int last_rc; enum nxweb_chunked_decoder_state_code {CDS_CR1=-2, CDS_LF1=-1, CDS_SIZE=0, CDS_LF2, CDS_DATA}; @@ -724,12 +727,37 @@ static void shutdown_thread(thread_config* tdata) { static int more_requests_to_run() { int rc=__sync_add_and_fetch(&config.request_counter, 1); + struct timeval curr_tv; + volatile static int printers; + if (rc>config.num_requests) { return 0; } - if (!config.quiet && config.progress_step>=10 && (rc%config.progress_step==0 || rc==config.num_requests)) { - printf("%d requests launched\n", rc); + + if (!__sync_bool_compare_and_swap(&printers, 0, 1)) + return 0; + + gettimeofday(&curr_tv, NULL); + if (!init_tv.tv_sec) { + init_tv = curr_tv; + last_tv = curr_tv; + printf("#time_a time_t time_r req_t req_r req_s\n"); + } + + if (!config.quiet && + ((curr_tv.tv_sec > last_tv.tv_sec + 1 || curr_tv.tv_sec == last_tv.tv_sec + 1 && curr_tv.tv_usec >= last_tv.tv_usec) || + rc==config.num_requests)) { + unsigned int ms_last = (curr_tv.tv_sec - last_tv.tv_sec) * 1000L + (signed long)(curr_tv.tv_usec - last_tv.tv_usec) / 1000L; + unsigned int ms_init = (curr_tv.tv_sec - init_tv.tv_sec) * 1000L + (signed long)(curr_tv.tv_usec - init_tv.tv_usec) / 1000L; + + printf("%10u %7u %4u %9u %6u %6u\n", + (unsigned int)curr_tv.tv_sec, ms_init, ms_last, + rc, rc - last_rc, (rc - last_rc) * 1000 / ms_last); + last_rc = rc; + last_tv = curr_tv; } + asm volatile("": : :"memory"); + printers = 0; return 1; } -- 1.7.12.1