blob: 120521a2860e8859da917270b0e73fb3467757c5 [file] [log] [blame]
Willy Tarreau72c28532009-01-22 18:56:50 +01001/*
Willy Tarreaud8fc1102010-09-12 17:56:16 +02002 * haproxy log statistics reporter
Willy Tarreau72c28532009-01-22 18:56:50 +01003 *
Willy Tarreaud2201062010-05-27 18:17:30 +02004 * Copyright 2000-2010 Willy Tarreau <w@1wt.eu>
Willy Tarreau72c28532009-01-22 18:56:50 +01005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Willy Tarreau72c28532009-01-22 18:56:50 +010013#include <errno.h>
14#include <fcntl.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <syslog.h>
18#include <string.h>
19#include <unistd.h>
20#include <ctype.h>
21
Willy Tarreau45cb4fb2009-10-26 21:10:04 +010022#include <eb32tree.h>
Willy Tarreauabe45b62010-10-28 20:33:46 +020023#include <eb64tree.h>
24#include <ebistree.h>
Willy Tarreaud2201062010-05-27 18:17:30 +020025#include <ebsttree.h>
Willy Tarreau72c28532009-01-22 18:56:50 +010026
Willy Tarreaud2201062010-05-27 18:17:30 +020027#define SOURCE_FIELD 5
Willy Tarreau72c28532009-01-22 18:56:50 +010028#define ACCEPT_FIELD 6
Willy Tarreaud2201062010-05-27 18:17:30 +020029#define SERVER_FIELD 8
Willy Tarreau72c28532009-01-22 18:56:50 +010030#define TIME_FIELD 9
31#define STATUS_FIELD 10
Willy Tarreaud8fc1102010-09-12 17:56:16 +020032#define TERM_CODES_FIELD 14
Willy Tarreau72c28532009-01-22 18:56:50 +010033#define CONN_FIELD 15
Willy Tarreauabe45b62010-10-28 20:33:46 +020034#define METH_FIELD 17
35#define URL_FIELD 18
Willy Tarreau72c28532009-01-22 18:56:50 +010036#define MAXLINE 16384
37#define QBITS 4
38
Willy Tarreaudf6f0d12011-07-10 18:15:08 +020039#define SEP(c) ((unsigned char)(c) <= ' ')
40#define SKIP_CHAR(p,c) do { while (1) { int __c = (unsigned char)*p++; if (__c == c) break; if (__c <= ' ') { p--; break; } } } while (0)
Willy Tarreau72c28532009-01-22 18:56:50 +010041
42/* [0] = err/date, [1] = req, [2] = conn, [3] = resp, [4] = data */
43static struct eb_root timers[5] = {
44 EB_ROOT_UNIQUE, EB_ROOT_UNIQUE, EB_ROOT_UNIQUE,
45 EB_ROOT_UNIQUE, EB_ROOT_UNIQUE,
46};
47
48struct timer {
49 struct eb32_node node;
50 unsigned int count;
51};
52
Willy Tarreaud2201062010-05-27 18:17:30 +020053struct srv_st {
54 unsigned int st_cnt[6]; /* 0xx to 5xx */
55 unsigned int nb_ct, nb_rt, nb_ok;
56 unsigned long long cum_ct, cum_rt;
57 struct ebmb_node node;
58 /* don't put anything else here, the server name will be there */
59};
Willy Tarreau72c28532009-01-22 18:56:50 +010060
Willy Tarreauabe45b62010-10-28 20:33:46 +020061struct url_stat {
62 union {
63 struct ebpt_node url;
64 struct eb64_node val;
65 } node;
66 char *url;
67 unsigned long long total_time; /* sum(all reqs' times) */
68 unsigned long long total_time_ok; /* sum(all OK reqs' times) */
69 unsigned int nb_err, nb_req;
70};
71
Willy Tarreau72c28532009-01-22 18:56:50 +010072#define FILT_COUNT_ONLY 0x01
73#define FILT_INVERT 0x02
74#define FILT_QUIET 0x04
75#define FILT_ERRORS_ONLY 0x08
76#define FILT_ACC_DELAY 0x10
77#define FILT_ACC_COUNT 0x20
78#define FILT_GRAPH_TIMERS 0x40
Willy Tarreau214c2032009-02-20 11:02:32 +010079#define FILT_PERCENTILE 0x80
Willy Tarreau5bdfd962009-10-14 15:16:29 +020080#define FILT_TIME_RESP 0x100
81
82#define FILT_INVERT_ERRORS 0x200
83#define FILT_INVERT_TIME_RESP 0x400
Willy Tarreau72c28532009-01-22 18:56:50 +010084
Willy Tarreau0f423a72010-05-03 10:50:54 +020085#define FILT_COUNT_STATUS 0x800
Willy Tarreaud2201062010-05-27 18:17:30 +020086#define FILT_COUNT_SRV_STATUS 0x1000
Willy Tarreaud8fc1102010-09-12 17:56:16 +020087#define FILT_COUNT_TERM_CODES 0x2000
Willy Tarreau0f423a72010-05-03 10:50:54 +020088
Willy Tarreauabe45b62010-10-28 20:33:46 +020089#define FILT_COUNT_URL_ONLY 0x004000
90#define FILT_COUNT_URL_COUNT 0x008000
91#define FILT_COUNT_URL_ERR 0x010000
92#define FILT_COUNT_URL_TTOT 0x020000
93#define FILT_COUNT_URL_TAVG 0x040000
94#define FILT_COUNT_URL_TTOTO 0x080000
95#define FILT_COUNT_URL_TAVGO 0x100000
96#define FILT_COUNT_URL_ANY (FILT_COUNT_URL_ONLY|FILT_COUNT_URL_COUNT|FILT_COUNT_URL_ERR| \
97 FILT_COUNT_URL_TTOT|FILT_COUNT_URL_TAVG|FILT_COUNT_URL_TTOTO|FILT_COUNT_URL_TAVGO)
98
Willy Tarreau70c428f2011-07-10 17:27:40 +020099#define FILT_HTTP_ONLY 0x200000
100
Willy Tarreau72c28532009-01-22 18:56:50 +0100101unsigned int filter = 0;
102unsigned int filter_invert = 0;
Willy Tarreau214c2032009-02-20 11:02:32 +0100103const char *line;
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200104int linenum = 0;
105int parse_err = 0;
106int lines_out = 0;
Willy Tarreau72c28532009-01-22 18:56:50 +0100107
Willy Tarreau214c2032009-02-20 11:02:32 +0100108const char *fgets2(FILE *stream);
Willy Tarreau72c28532009-01-22 18:56:50 +0100109
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200110void filter_count_url(const char *accept_field, const char *time_field, struct timer **tptr);
111void filter_count_srv_status(const char *accept_field, const char *time_field, struct timer **tptr);
112void filter_count_term_codes(const char *accept_field, const char *time_field, struct timer **tptr);
113void filter_count_status(const char *accept_field, const char *time_field, struct timer **tptr);
114void filter_graphs(const char *accept_field, const char *time_field, struct timer **tptr);
115void filter_output_line(const char *accept_field, const char *time_field, struct timer **tptr);
116void filter_accept_holes(const char *accept_field, const char *time_field, struct timer **tptr);
117
Willy Tarreau72c28532009-01-22 18:56:50 +0100118void die(const char *msg)
119{
120 fprintf(stderr,
121 "%s"
Willy Tarreauabe45b62010-10-28 20:33:46 +0200122 "Usage: halog [-q] [-c] [-v] {-gt|-pct|-st|-tc|-srv|-u|-uc|-ue|-ua|-ut|-uao|-uto}\n"
Willy Tarreau70c428f2011-07-10 17:27:40 +0200123 " [-s <skip>] [-e|-E] [-H] [-rt|-RT <time>] [-ad <delay>] [-ac <count>] < log\n"
Willy Tarreau72c28532009-01-22 18:56:50 +0100124 "\n",
125 msg ? msg : ""
126 );
127 exit(1);
128}
129
130
131/* return pointer to first char not part of current field starting at <p>. */
132const char *field_stop(const char *p)
133{
134 unsigned char c;
135
136 while (1) {
137 c = *(p++);
138 if (c > ' ')
139 continue;
Willy Tarreau14389e72011-07-10 22:11:17 +0200140 if (c == ' ' || c == 0)
Willy Tarreau72c28532009-01-22 18:56:50 +0100141 break;
142 }
143 return p - 1;
144}
145
146/* return field <field> (starting from 1) in string <p>. Only consider
147 * contiguous spaces (or tabs) as one delimiter. May return pointer to
148 * last char if field is not found. Equivalent to awk '{print $field}'.
149 */
150const char *field_start(const char *p, int field)
151{
152 unsigned char c;
153 while (1) {
154 /* skip spaces */
155 while (1) {
156 c = *p;
157 if (c > ' ')
158 break;
Willy Tarreau14389e72011-07-10 22:11:17 +0200159 if (c == ' ')
Willy Tarreau72c28532009-01-22 18:56:50 +0100160 goto next;
161 if (!c) /* end of line */
162 return p;
163 /* other char => new field */
164 break;
165 next:
166 p++;
167 }
168
169 /* start of field */
170 field--;
171 if (!field)
172 return p;
173
174 /* skip this field */
175 while (1) {
176 c = *(p++);
177 if (c > ' ')
178 continue;
Willy Tarreau14389e72011-07-10 22:11:17 +0200179 if (c == ' ')
Willy Tarreau72c28532009-01-22 18:56:50 +0100180 break;
181 if (c == '\0')
182 return p;
183 }
184 }
185}
186
187/* keep only the <bits> higher bits of <i> */
188static inline unsigned int quantify_u32(unsigned int i, int bits)
189{
190 int high;
191
192 if (!bits)
193 return 0;
194
195 if (i)
196 high = fls_auto(i); // 1 to 32
197 else
198 high = 0;
199
200 if (high <= bits)
201 return i;
202
203 return i & ~((1 << (high - bits)) - 1);
204}
205
206/* keep only the <bits> higher bits of the absolute value of <i>, as well as
207 * its sign. */
208static inline int quantify(int i, int bits)
209{
210 if (i >= 0)
211 return quantify_u32(i, bits);
212 else
213 return -quantify_u32(-i, bits);
214}
215
216/* Insert timer value <v> into tree <r>. A pre-allocated node must be passed
217 * in <alloc>. It may be NULL, in which case the function will allocate it
218 * itself. It will be reset to NULL once consumed. The caller is responsible
219 * for freeing the node once not used anymore. The node where the value was
220 * inserted is returned.
221 */
222struct timer *insert_timer(struct eb_root *r, struct timer **alloc, int v)
223{
224 struct timer *t = *alloc;
225 struct eb32_node *n;
226
227 if (!t) {
228 t = calloc(sizeof(*t), 1);
229 if (unlikely(!t)) {
230 fprintf(stderr, "%s: not enough memory\n", __FUNCTION__);
231 exit(1);
232 }
233 }
234 t->node.key = quantify(v, QBITS); // keep only the higher QBITS bits
235
236 n = eb32i_insert(r, &t->node);
237 if (n == &t->node)
238 t = NULL; /* node inserted, will malloc next time */
239
240 *alloc = t;
241 return container_of(n, struct timer, node);
242}
243
244/* Insert value value <v> into tree <r>. A pre-allocated node must be passed
245 * in <alloc>. It may be NULL, in which case the function will allocate it
246 * itself. It will be reset to NULL once consumed. The caller is responsible
247 * for freeing the node once not used anymore. The node where the value was
248 * inserted is returned.
249 */
250struct timer *insert_value(struct eb_root *r, struct timer **alloc, int v)
251{
252 struct timer *t = *alloc;
253 struct eb32_node *n;
254
255 if (!t) {
256 t = calloc(sizeof(*t), 1);
257 if (unlikely(!t)) {
258 fprintf(stderr, "%s: not enough memory\n", __FUNCTION__);
259 exit(1);
260 }
261 }
262 t->node.key = v;
263
264 n = eb32i_insert(r, &t->node);
265 if (n == &t->node)
266 t = NULL; /* node inserted, will malloc next time */
267
268 *alloc = t;
269 return container_of(n, struct timer, node);
270}
271
272int str2ic(const char *s)
273{
274 int i = 0;
275 int j, k;
276
277 if (*s != '-') {
278 /* positive number */
279 while (1) {
280 j = (*s++) - '0';
281 k = i * 10;
282 if ((unsigned)j > 9)
283 break;
284 i = k + j;
285 }
286 } else {
287 /* negative number */
288 s++;
289 while (1) {
290 j = (*s++) - '0';
291 k = i * 10;
292 if ((unsigned)j > 9)
293 break;
294 i = k - j;
295 }
296 }
297
298 return i;
299}
300
301
302/* Equivalent to strtoul with a length. */
303static inline unsigned int __strl2ui(const char *s, int len)
304{
305 unsigned int i = 0;
306 while (len-- > 0) {
307 i = i * 10 - '0';
308 i += (unsigned char)*s++;
309 }
310 return i;
311}
312
313unsigned int strl2ui(const char *s, int len)
314{
315 return __strl2ui(s, len);
316}
317
318/* Convert "[04/Dec/2008:09:49:40.555]" to an integer equivalent to the time of
319 * the day in milliseconds. It returns -1 for all unparsable values. The parser
320 * looks ugly but gcc emits far better code that way.
321 */
322int convert_date(const char *field)
323{
324 unsigned int h, m, s, ms;
325 unsigned char c;
326 const char *b, *e;
327
328 h = m = s = ms = 0;
329 e = field;
330
331 /* skip the date */
332 while (1) {
333 c = *(e++);
334 if (c == ':')
335 break;
336 if (!c)
337 goto out_err;
338 }
339
340 /* hour + ':' */
341 b = e;
342 while (1) {
343 c = *(e++) - '0';
344 if (c > 9)
345 break;
346 h = h * 10 + c;
347 }
348 if (c == (unsigned char)(0 - '0'))
349 goto out_err;
350
351 /* minute + ':' */
352 b = e;
353 while (1) {
354 c = *(e++) - '0';
355 if (c > 9)
356 break;
357 m = m * 10 + c;
358 }
359 if (c == (unsigned char)(0 - '0'))
360 goto out_err;
361
362 /* second + '.' or ']' */
363 b = e;
364 while (1) {
365 c = *(e++) - '0';
366 if (c > 9)
367 break;
368 s = s * 10 + c;
369 }
370 if (c == (unsigned char)(0 - '0'))
371 goto out_err;
372
373 /* if there's a '.', we have milliseconds */
374 if (c == (unsigned char)('.' - '0')) {
375 /* millisecond second + ']' */
376 b = e;
377 while (1) {
378 c = *(e++) - '0';
379 if (c > 9)
380 break;
381 ms = ms * 10 + c;
382 }
383 if (c == (unsigned char)(0 - '0'))
384 goto out_err;
385 }
386 return (((h * 60) + m) * 60 + s) * 1000 + ms;
387 out_err:
388 return -1;
389}
390
391void truncated_line(int linenum, const char *line)
392{
393 if (!(filter & FILT_QUIET))
394 fprintf(stderr, "Truncated line %d: %s\n", linenum, line);
395}
396
397int main(int argc, char **argv)
398{
Willy Tarreau26deaf52011-07-10 19:47:48 +0200399 const char *b, *e, *p, *time_field, *accept_field;
Willy Tarreau72c28532009-01-22 18:56:50 +0100400 const char *output_file = NULL;
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200401 int f, last, err;
402 struct timer *t = NULL;
Willy Tarreau72c28532009-01-22 18:56:50 +0100403 struct eb32_node *n;
Willy Tarreauabe45b62010-10-28 20:33:46 +0200404 struct url_stat *ustat = NULL;
Willy Tarreau72c28532009-01-22 18:56:50 +0100405 int val, test;
Willy Tarreau72c28532009-01-22 18:56:50 +0100406 int filter_acc_delay = 0, filter_acc_count = 0;
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200407 int filter_time_resp = 0;
Willy Tarreau72c28532009-01-22 18:56:50 +0100408 int skip_fields = 1;
409
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200410 void (*line_filter)(const char *accept_field, const char *time_field, struct timer **tptr) = NULL;
411
Willy Tarreau72c28532009-01-22 18:56:50 +0100412 argc--; argv++;
413 while (argc > 0) {
414 if (*argv[0] != '-')
415 break;
416
417 if (strcmp(argv[0], "-ad") == 0) {
418 if (argc < 2) die("missing option for -ad");
419 argc--; argv++;
420 filter |= FILT_ACC_DELAY;
421 filter_acc_delay = atol(*argv);
422 }
423 else if (strcmp(argv[0], "-ac") == 0) {
424 if (argc < 2) die("missing option for -ac");
425 argc--; argv++;
426 filter |= FILT_ACC_COUNT;
427 filter_acc_count = atol(*argv);
428 }
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200429 else if (strcmp(argv[0], "-rt") == 0) {
430 if (argc < 2) die("missing option for -rt");
431 argc--; argv++;
432 filter |= FILT_TIME_RESP;
433 filter_time_resp = atol(*argv);
434 }
435 else if (strcmp(argv[0], "-RT") == 0) {
436 if (argc < 2) die("missing option for -RT");
437 argc--; argv++;
438 filter |= FILT_TIME_RESP | FILT_INVERT_TIME_RESP;
439 filter_time_resp = atol(*argv);
440 }
Willy Tarreau72c28532009-01-22 18:56:50 +0100441 else if (strcmp(argv[0], "-s") == 0) {
442 if (argc < 2) die("missing option for -s");
443 argc--; argv++;
444 skip_fields = atol(*argv);
445 }
446 else if (strcmp(argv[0], "-e") == 0)
447 filter |= FILT_ERRORS_ONLY;
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200448 else if (strcmp(argv[0], "-E") == 0)
449 filter |= FILT_ERRORS_ONLY | FILT_INVERT_ERRORS;
Willy Tarreau70c428f2011-07-10 17:27:40 +0200450 else if (strcmp(argv[0], "-H") == 0)
451 filter |= FILT_HTTP_ONLY;
Willy Tarreau72c28532009-01-22 18:56:50 +0100452 else if (strcmp(argv[0], "-c") == 0)
453 filter |= FILT_COUNT_ONLY;
454 else if (strcmp(argv[0], "-q") == 0)
455 filter |= FILT_QUIET;
456 else if (strcmp(argv[0], "-v") == 0)
457 filter_invert = !filter_invert;
458 else if (strcmp(argv[0], "-gt") == 0)
459 filter |= FILT_GRAPH_TIMERS;
Willy Tarreau214c2032009-02-20 11:02:32 +0100460 else if (strcmp(argv[0], "-pct") == 0)
461 filter |= FILT_PERCENTILE;
Willy Tarreau0f423a72010-05-03 10:50:54 +0200462 else if (strcmp(argv[0], "-st") == 0)
463 filter |= FILT_COUNT_STATUS;
Willy Tarreaud2201062010-05-27 18:17:30 +0200464 else if (strcmp(argv[0], "-srv") == 0)
465 filter |= FILT_COUNT_SRV_STATUS;
Willy Tarreaud8fc1102010-09-12 17:56:16 +0200466 else if (strcmp(argv[0], "-tc") == 0)
467 filter |= FILT_COUNT_TERM_CODES;
Willy Tarreauabe45b62010-10-28 20:33:46 +0200468 else if (strcmp(argv[0], "-u") == 0)
469 filter |= FILT_COUNT_URL_ONLY;
470 else if (strcmp(argv[0], "-uc") == 0)
471 filter |= FILT_COUNT_URL_COUNT;
472 else if (strcmp(argv[0], "-ue") == 0)
473 filter |= FILT_COUNT_URL_ERR;
474 else if (strcmp(argv[0], "-ua") == 0)
475 filter |= FILT_COUNT_URL_TAVG;
476 else if (strcmp(argv[0], "-ut") == 0)
477 filter |= FILT_COUNT_URL_TTOT;
478 else if (strcmp(argv[0], "-uao") == 0)
479 filter |= FILT_COUNT_URL_TAVGO;
480 else if (strcmp(argv[0], "-uto") == 0)
481 filter |= FILT_COUNT_URL_TTOTO;
Willy Tarreau72c28532009-01-22 18:56:50 +0100482 else if (strcmp(argv[0], "-o") == 0) {
483 if (output_file)
484 die("Fatal: output file name already specified.\n");
485 if (argc < 2)
486 die("Fatal: missing output file name.\n");
487 output_file = argv[1];
488 }
489 argc--;
490 argv++;
491 }
492
493 if (!filter)
494 die("No action specified.\n");
495
496 if (filter & FILT_ACC_COUNT && !filter_acc_count)
497 filter_acc_count=1;
498
499 if (filter & FILT_ACC_DELAY && !filter_acc_delay)
500 filter_acc_delay = 1;
501
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200502
503 /* by default, all lines are printed */
504 line_filter = filter_output_line;
505 if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY))
506 line_filter = filter_accept_holes;
507 else if (filter & (FILT_GRAPH_TIMERS|FILT_PERCENTILE))
508 line_filter = filter_graphs;
509 else if (filter & FILT_COUNT_STATUS)
510 line_filter = filter_count_status;
511 else if (filter & FILT_COUNT_TERM_CODES)
512 line_filter = filter_count_term_codes;
513 else if (filter & FILT_COUNT_SRV_STATUS)
514 line_filter = filter_count_srv_status;
515 else if (filter & FILT_COUNT_URL_ANY)
516 line_filter = filter_count_url;
517 else if (filter & FILT_COUNT_ONLY)
518 line_filter = NULL;
Willy Tarreau72c28532009-01-22 18:56:50 +0100519
Willy Tarreau214c2032009-02-20 11:02:32 +0100520 while ((line = fgets2(stdin)) != NULL) {
Willy Tarreau72c28532009-01-22 18:56:50 +0100521 linenum++;
Willy Tarreau26deaf52011-07-10 19:47:48 +0200522 time_field = NULL; accept_field = NULL;
Willy Tarreau72c28532009-01-22 18:56:50 +0100523
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200524 test = 1;
Willy Tarreau26deaf52011-07-10 19:47:48 +0200525
526 /* for any line we process, we first ensure that there is a field
527 * looking like the accept date field (beginning with a '[').
528 */
529 accept_field = field_start(line, ACCEPT_FIELD + skip_fields);
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200530 if (unlikely(*accept_field != '[')) {
Willy Tarreau26deaf52011-07-10 19:47:48 +0200531 parse_err++;
532 continue;
533 }
534
535 /* the day of month field is begin 01 and 31 */
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200536 if (accept_field[1] < '0' || accept_field[1] > '3') {
Willy Tarreau26deaf52011-07-10 19:47:48 +0200537 parse_err++;
538 continue;
539 }
540
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200541 if (filter & FILT_HTTP_ONLY) {
Willy Tarreau70c428f2011-07-10 17:27:40 +0200542 /* only report lines with at least 4 timers */
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200543 if (!time_field) {
Willy Tarreau26deaf52011-07-10 19:47:48 +0200544 time_field = field_start(accept_field, TIME_FIELD - ACCEPT_FIELD + 1);
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200545 if (unlikely(!*time_field)) {
Willy Tarreau26deaf52011-07-10 19:47:48 +0200546 truncated_line(linenum, line);
547 continue;
548 }
Willy Tarreau70c428f2011-07-10 17:27:40 +0200549 }
550
Willy Tarreau758a6ea2011-07-10 18:53:44 +0200551 e = field_stop(time_field + 1);
552 /* we have field TIME_FIELD in [time_field]..[e-1] */
553 p = time_field;
Willy Tarreau70c428f2011-07-10 17:27:40 +0200554 f = 0;
Willy Tarreaudf6f0d12011-07-10 18:15:08 +0200555 while (!SEP(*p)) {
Willy Tarreau70c428f2011-07-10 17:27:40 +0200556 if (++f == 4)
557 break;
558 SKIP_CHAR(p, '/');
559 }
560 test &= (f >= 4);
561 }
562
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200563 if (filter & FILT_TIME_RESP) {
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200564 int tps;
565
566 /* only report lines with response times larger than filter_time_resp */
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200567 if (!time_field) {
Willy Tarreau26deaf52011-07-10 19:47:48 +0200568 time_field = field_start(accept_field, TIME_FIELD - ACCEPT_FIELD + 1);
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200569 if (unlikely(!*time_field)) {
Willy Tarreau26deaf52011-07-10 19:47:48 +0200570 truncated_line(linenum, line);
571 continue;
572 }
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200573 }
574
Willy Tarreau758a6ea2011-07-10 18:53:44 +0200575 e = field_stop(time_field + 1);
576 /* we have field TIME_FIELD in [time_field]..[e-1], let's check only the response time */
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200577
Willy Tarreau758a6ea2011-07-10 18:53:44 +0200578 p = time_field;
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200579 err = 0;
Willy Tarreau24bcb4f2010-10-28 20:39:50 +0200580 f = 0;
Willy Tarreaudf6f0d12011-07-10 18:15:08 +0200581 while (!SEP(*p)) {
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200582 tps = str2ic(p);
583 if (tps < 0) {
584 tps = -1;
585 err = 1;
586 }
Willy Tarreau24bcb4f2010-10-28 20:39:50 +0200587 if (++f == 4)
588 break;
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200589 SKIP_CHAR(p, '/');
590 }
591
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200592 if (unlikely(f < 4)) {
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200593 parse_err++;
594 continue;
595 }
596
597 test &= (tps >= filter_time_resp) ^ !!(filter & FILT_INVERT_TIME_RESP);
598 }
599
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200600 if (filter & FILT_ERRORS_ONLY) {
Willy Tarreau72c28532009-01-22 18:56:50 +0100601 /* only report erroneous status codes */
Willy Tarreau26deaf52011-07-10 19:47:48 +0200602 if (time_field)
603 b = field_start(time_field, STATUS_FIELD - TIME_FIELD + 1);
604 else
605 b = field_start(accept_field, STATUS_FIELD - ACCEPT_FIELD + 1);
606
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200607 if (unlikely(!*b)) {
Willy Tarreau72c28532009-01-22 18:56:50 +0100608 truncated_line(linenum, line);
609 continue;
610 }
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200611
Willy Tarreau72c28532009-01-22 18:56:50 +0100612 if (*b == '-') {
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200613 test &= !!(filter & FILT_INVERT_ERRORS);
Willy Tarreau72c28532009-01-22 18:56:50 +0100614 } else {
615 val = strl2ui(b, 3);
Willy Tarreau5bdfd962009-10-14 15:16:29 +0200616 test &= (val >= 500 && val <= 599) ^ !!(filter & FILT_INVERT_ERRORS);
Willy Tarreau72c28532009-01-22 18:56:50 +0100617 }
Willy Tarreau72c28532009-01-22 18:56:50 +0100618 }
619
Willy Tarreau0f423a72010-05-03 10:50:54 +0200620 test ^= filter_invert;
621 if (!test)
622 continue;
623
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200624 /************** here we process inputs *******************/
Willy Tarreau72c28532009-01-22 18:56:50 +0100625
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200626 if (line_filter)
627 line_filter(accept_field, time_field, &t);
628 else
629 lines_out++; /* we're just counting lines */
630 }
Willy Tarreauabe45b62010-10-28 20:33:46 +0200631
Willy Tarreauabe45b62010-10-28 20:33:46 +0200632
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200633 /*****************************************************
634 * Here we've finished reading all input. Depending on the
635 * filters, we may still have some analysis to run on the
636 * collected data and to output data in a new format.
637 *************************************************** */
Willy Tarreau72c28532009-01-22 18:56:50 +0100638
639 if (t)
640 free(t);
641
642 if (filter & FILT_COUNT_ONLY) {
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200643 printf("%d\n", lines_out);
Willy Tarreau72c28532009-01-22 18:56:50 +0100644 exit(0);
645 }
646
Willy Tarreau72c28532009-01-22 18:56:50 +0100647 if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) {
648 /* sort and count all timers. Output will look like this :
649 * <accept_date> <delta_ms from previous one> <nb entries>
650 */
651 n = eb32_first(&timers[0]);
652
653 if (n)
654 last = n->key;
655 while (n) {
656 unsigned int d, h, m, s, ms;
657
658 t = container_of(n, struct timer, node);
659 h = n->key;
660 d = h - last;
661 last = h;
662
663 if (d >= filter_acc_delay && t->count >= filter_acc_count) {
664 ms = h % 1000; h = h / 1000;
665 s = h % 60; h = h / 60;
666 m = h % 60; h = h / 60;
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200667 lines_out++;
Willy Tarreau72c28532009-01-22 18:56:50 +0100668 printf("%02d:%02d:%02d.%03d %d %d %d\n", h, m, s, ms, last, d, t->count);
669 }
670 n = eb32_next(n);
671 }
672 }
673 else if (filter & FILT_GRAPH_TIMERS) {
674 /* sort all timers */
675 for (f = 0; f < 5; f++) {
676 struct eb32_node *n;
677 int val;
678
679 val = 0;
680 n = eb32_first(&timers[f]);
681 while (n) {
682 int i;
683 double d;
684
685 t = container_of(n, struct timer, node);
686 last = n->key;
687 val = t->count;
688
689 i = (last < 0) ? -last : last;
690 i = fls_auto(i) - QBITS;
691
692 if (i > 0)
693 d = val / (double)(1 << i);
694 else
695 d = val;
696
697 if (d > 0.0) {
698 printf("%d %d %f\n", f, last, d+1.0);
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200699 lines_out++;
Willy Tarreau72c28532009-01-22 18:56:50 +0100700 }
701
702 n = eb32_next(n);
703 }
Willy Tarreau214c2032009-02-20 11:02:32 +0100704 }
705 }
706 else if (filter & FILT_PERCENTILE) {
707 /* report timers by percentile :
708 * <percent> <total> <max_req_time> <max_conn_time> <max_resp_time> <max_data_time>
709 * We don't count errs.
710 */
711 struct eb32_node *n[5];
712 unsigned long cum[5];
713 double step;
714
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200715 if (!lines_out)
Willy Tarreau910ba4b2009-11-17 10:16:19 +0100716 goto empty;
717
Willy Tarreau214c2032009-02-20 11:02:32 +0100718 for (f = 1; f < 5; f++) {
719 n[f] = eb32_first(&timers[f]);
720 cum[f] = container_of(n[f], struct timer, node)->count;
721 }
722
723 for (step = 1; step <= 1000;) {
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200724 unsigned int thres = lines_out * (step / 1000.0);
Willy Tarreau214c2032009-02-20 11:02:32 +0100725
726 printf("%3.1f %d ", step/10.0, thres);
727 for (f = 1; f < 5; f++) {
728 struct eb32_node *next;
729 while (cum[f] < thres) {
730 /* need to find other keys */
731 next = eb32_next(n[f]);
732 if (!next)
733 break;
734 n[f] = next;
735 cum[f] += container_of(next, struct timer, node)->count;
736 }
737
738 /* value still within $step % of total */
739 printf("%d ", n[f]->key);
740 }
741 putchar('\n');
742 if (step >= 100 && step < 900)
743 step += 50; // jump 5% by 5% between those steps.
744 else if (step >= 20 && step < 980)
745 step += 10;
746 else
747 step += 1;
Willy Tarreau72c28532009-01-22 18:56:50 +0100748 }
749 }
Willy Tarreau0f423a72010-05-03 10:50:54 +0200750 else if (filter & FILT_COUNT_STATUS) {
751 /* output all statuses in the form of <status> <occurrences> */
752 n = eb32_first(&timers[0]);
753 while (n) {
754 t = container_of(n, struct timer, node);
755 printf("%d %d\n", n->key, t->count);
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200756 lines_out++;
Willy Tarreau0f423a72010-05-03 10:50:54 +0200757 n = eb32_next(n);
758 }
759 }
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200760 else if (filter & FILT_COUNT_SRV_STATUS) {
Willy Tarreaud2201062010-05-27 18:17:30 +0200761 struct ebmb_node *srv_node;
762 struct srv_st *srv;
763
764 printf("#srv_name 1xx 2xx 3xx 4xx 5xx other tot_req req_ok pct_ok avg_ct avg_rt\n");
765
766 srv_node = ebmb_first(&timers[0]);
767 while (srv_node) {
768 int tot_rq;
769
770 srv = container_of(srv_node, struct srv_st, node);
771
772 tot_rq = 0;
773 for (f = 0; f <= 5; f++)
774 tot_rq += srv->st_cnt[f];
775
776 printf("%s %d %d %d %d %d %d %d %d %.1f %d %d\n",
777 srv_node->key, srv->st_cnt[1], srv->st_cnt[2],
778 srv->st_cnt[3], srv->st_cnt[4], srv->st_cnt[5], srv->st_cnt[0],
779 tot_rq,
780 srv->nb_ok, (double)srv->nb_ok * 100.0 / (tot_rq?tot_rq:1),
781 (int)(srv->cum_ct / (srv->nb_ct?srv->nb_ct:1)), (int)(srv->cum_rt / (srv->nb_rt?srv->nb_rt:1)));
782 srv_node = ebmb_next(srv_node);
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200783 lines_out++;
Willy Tarreaud2201062010-05-27 18:17:30 +0200784 }
785 }
Willy Tarreaud8fc1102010-09-12 17:56:16 +0200786 else if (filter & FILT_COUNT_TERM_CODES) {
787 /* output all statuses in the form of <code> <occurrences> */
788 n = eb32_first(&timers[0]);
789 while (n) {
790 t = container_of(n, struct timer, node);
791 printf("%c%c %d\n", (n->key >> 8), (n->key) & 255, t->count);
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200792 lines_out++;
Willy Tarreaud8fc1102010-09-12 17:56:16 +0200793 n = eb32_next(n);
794 }
795 }
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200796 else if (filter & FILT_COUNT_URL_ANY) {
Willy Tarreauabe45b62010-10-28 20:33:46 +0200797 struct eb_node *node, *next;
798
799 if (!(filter & FILT_COUNT_URL_ONLY)) {
800 /* we have to sort on another criterion. We'll use timers[1] for the
801 * destination tree.
802 */
803
804 timers[1] = EB_ROOT; /* reconfigure to accept duplicates */
805 for (node = eb_first(&timers[0]); node; node = next) {
806 next = eb_next(node);
807 eb_delete(node);
808
809 ustat = container_of(node, struct url_stat, node.url.node);
810
811 if (filter & FILT_COUNT_URL_COUNT)
812 ustat->node.val.key = ustat->nb_req;
813 else if (filter & FILT_COUNT_URL_ERR)
814 ustat->node.val.key = ustat->nb_err;
815 else if (filter & FILT_COUNT_URL_TTOT)
816 ustat->node.val.key = ustat->total_time;
817 else if (filter & FILT_COUNT_URL_TAVG)
818 ustat->node.val.key = ustat->nb_req ? ustat->total_time / ustat->nb_req : 0;
819 else if (filter & FILT_COUNT_URL_TTOTO)
820 ustat->node.val.key = ustat->total_time_ok;
821 else if (filter & FILT_COUNT_URL_TAVGO)
822 ustat->node.val.key = (ustat->nb_req - ustat->nb_err) ? ustat->total_time_ok / (ustat->nb_req - ustat->nb_err) : 0;
823 else
824 ustat->node.val.key = 0;
825
826 eb64_insert(&timers[1], &ustat->node.val);
827 }
828 /* switch trees */
829 timers[0] = timers[1];
830 }
831
832 printf("#req err ttot tavg oktot okavg url\n");
833
834 /* scan the tree in its reverse sorting order */
835 node = eb_last(&timers[0]);
836 while (node) {
837 ustat = container_of(node, struct url_stat, node.url.node);
838 printf("%d %d %Ld %Ld %Ld %Ld %s\n",
839 ustat->nb_req,
840 ustat->nb_err,
841 ustat->total_time,
842 ustat->nb_req ? ustat->total_time / ustat->nb_req : 0,
843 ustat->total_time_ok,
844 (ustat->nb_req - ustat->nb_err) ? ustat->total_time_ok / (ustat->nb_req - ustat->nb_err) : 0,
845 ustat->url);
846
847 node = eb_prev(node);
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200848 lines_out++;
Willy Tarreauabe45b62010-10-28 20:33:46 +0200849 }
850 }
Willy Tarreaud2201062010-05-27 18:17:30 +0200851
Willy Tarreau910ba4b2009-11-17 10:16:19 +0100852 empty:
Willy Tarreau72c28532009-01-22 18:56:50 +0100853 if (!(filter & FILT_QUIET))
854 fprintf(stderr, "%d lines in, %d lines out, %d parsing errors\n",
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200855 linenum, lines_out, parse_err);
Willy Tarreau72c28532009-01-22 18:56:50 +0100856 exit(0);
857}
858
Willy Tarreaua2b39fb2011-07-10 21:39:35 +0200859void filter_output_line(const char *accept_field, const char *time_field, struct timer **tptr)
860{
861 puts(line);
862 lines_out++;
863}
864
865void filter_accept_holes(const char *accept_field, const char *time_field, struct timer **tptr)
866{
867 struct timer *t2;
868 int val;
869
870 val = convert_date(accept_field);
871 if (unlikely(val < 0)) {
872 truncated_line(linenum, line);
873 return;
874 }
875
876 t2 = insert_value(&timers[0], tptr, val);
877 t2->count++;
878 lines_out++;
879 return;
880}
881
882void filter_count_status(const char *accept_field, const char *time_field, struct timer **tptr)
883{
884 struct timer *t2;
885 const char *b;
886 int val;
887
888 if (time_field)
889 b = field_start(time_field, STATUS_FIELD - TIME_FIELD + 1);
890 else
891 b = field_start(accept_field, STATUS_FIELD - ACCEPT_FIELD + 1);
892
893 if (unlikely(!*b)) {
894 truncated_line(linenum, line);
895 return;
896 }
897
898 val = str2ic(b);
899
900 t2 = insert_value(&timers[0], tptr, val);
901 t2->count++;
902}
903
904void filter_count_term_codes(const char *accept_field, const char *time_field, struct timer **tptr)
905{
906 struct timer *t2;
907 const char *b;
908 int val;
909
910 if (time_field)
911 b = field_start(time_field, TERM_CODES_FIELD - TIME_FIELD + 1);
912 else
913 b = field_start(accept_field, TERM_CODES_FIELD - ACCEPT_FIELD + 1);
914
915 if (unlikely(!*b)) {
916 truncated_line(linenum, line);
917 return;
918 }
919
920 val = 256 * b[0] + b[1];
921
922 t2 = insert_value(&timers[0], tptr, val);
923 t2->count++;
924}
925
926void filter_count_srv_status(const char *accept_field, const char *time_field, struct timer **tptr)
927{
928 const char *b, *e, *p;
929 int f, err, array[5];
930 struct ebmb_node *srv_node;
931 struct srv_st *srv;
932 int val;
933
934 /* the server field is before the status field, so let's
935 * parse them in the proper order.
936 */
937 b = field_start(accept_field, SERVER_FIELD - ACCEPT_FIELD + 1);
938 if (unlikely(!*b)) {
939 truncated_line(linenum, line);
940 return;
941 }
942
943 e = field_stop(b + 1); /* we have the server name in [b]..[e-1] */
944
945 /* the chance that a server name already exists is extremely high,
946 * so let's perform a normal lookup first.
947 */
948 srv_node = ebst_lookup_len(&timers[0], b, e - b);
949 srv = container_of(srv_node, struct srv_st, node);
950
951 if (!srv_node) {
952 /* server not yet in the tree, let's create it */
953 srv = (void *)calloc(1, sizeof(struct srv_st) + e - b + 1);
954 srv_node = &srv->node;
955 memcpy(&srv_node->key, b, e - b);
956 srv_node->key[e - b] = '\0';
957 ebst_insert(&timers[0], srv_node);
958 }
959
960 /* let's collect the connect and response times */
961 if (!time_field) {
962 time_field = field_start(e, TIME_FIELD - SERVER_FIELD);
963 if (unlikely(!*time_field)) {
964 truncated_line(linenum, line);
965 return;
966 }
967 }
968
969 e = field_stop(time_field + 1);
970 /* we have field TIME_FIELD in [time_field]..[e-1] */
971
972 p = time_field;
973 err = 0;
974 f = 0;
975 while (!SEP(*p)) {
976 array[f] = str2ic(p);
977 if (array[f] < 0) {
978 array[f] = -1;
979 err = 1;
980 }
981 if (++f == 5)
982 break;
983 SKIP_CHAR(p, '/');
984 }
985
986 if (unlikely(f < 5)){
987 parse_err++;
988 return;
989 }
990
991 /* OK we have our timers in array[2,3] */
992 if (!err)
993 srv->nb_ok++;
994
995 if (array[2] >= 0) {
996 srv->cum_ct += array[2];
997 srv->nb_ct++;
998 }
999
1000 if (array[3] >= 0) {
1001 srv->cum_rt += array[3];
1002 srv->nb_rt++;
1003 }
1004
1005 /* we're interested in the 5 HTTP status classes (1xx ... 5xx), and
1006 * the invalid ones which will be reported as 0.
1007 */
1008 b = field_start(e, STATUS_FIELD - TIME_FIELD);
1009 if (unlikely(!*b)) {
1010 truncated_line(linenum, line);
1011 return;
1012 }
1013
1014 val = 0;
1015 if (*b >= '1' && *b <= '5')
1016 val = *b - '0';
1017
1018 srv->st_cnt[val]++;
1019}
1020
1021void filter_count_url(const char *accept_field, const char *time_field, struct timer **tptr)
1022{
1023 struct url_stat *ustat = NULL;
1024 struct ebpt_node *ebpt_old;
1025 const char *b, *e;
1026 int f, err, array[5];
1027
1028 /* let's collect the response time */
1029 if (!time_field) {
1030 time_field = field_start(accept_field, TIME_FIELD - ACCEPT_FIELD + 1); // avg 115 ns per line
1031 if (unlikely(!*time_field)) {
1032 truncated_line(linenum, line);
1033 return;
1034 }
1035 }
1036
1037 /* we have the field TIME_FIELD starting at <time_field>. We'll
1038 * parse the 5 timers to detect errors, it takes avg 55 ns per line.
1039 */
1040 e = time_field; err = 0; f = 0;
1041 while (!SEP(*e)) {
1042 array[f] = str2ic(e);
1043 if (array[f] < 0) {
1044 array[f] = -1;
1045 err = 1;
1046 }
1047 if (++f == 5)
1048 break;
1049 SKIP_CHAR(e, '/');
1050 }
1051 if (f < 5) {
1052 parse_err++;
1053 return;
1054 }
1055
1056 /* OK we have our timers in array[3], and err is >0 if at
1057 * least one -1 was seen. <e> points to the first char of
1058 * the last timer. Let's prepare a new node with that.
1059 */
1060 if (unlikely(!ustat))
1061 ustat = calloc(1, sizeof(*ustat));
1062
1063 ustat->nb_err = err;
1064 ustat->nb_req = 1;
1065
1066 /* use array[4] = total time in case of error */
1067 ustat->total_time = (array[3] >= 0) ? array[3] : array[4];
1068 ustat->total_time_ok = (array[3] >= 0) ? array[3] : 0;
1069
1070 /* the line may be truncated because of a bad request or anything like this,
1071 * without a method. Also, if it does not begin with an quote, let's skip to
1072 * the next field because it's a capture. Let's fall back to the "method" itself
1073 * if there's nothing else.
1074 */
1075 e = field_start(e, METH_FIELD - TIME_FIELD + 1); // avg 100 ns per line
1076 while (*e != '"' && *e)
1077 e = field_start(e, 2);
1078
1079 if (unlikely(!*e)) {
1080 truncated_line(linenum, line);
1081 return;
1082 }
1083
1084 b = field_start(e, URL_FIELD - METH_FIELD + 1); // avg 40 ns per line
1085 if (!*b)
1086 b = e;
1087
1088 /* stop at end of field or first ';' or '?', takes avg 64 ns per line */
1089 e = b;
1090 do {
Willy Tarreau14389e72011-07-10 22:11:17 +02001091 if (*e == ' ' || *e == '?' || *e == ';') {
Willy Tarreaua2b39fb2011-07-10 21:39:35 +02001092 *(char *)e = 0;
1093 break;
1094 }
1095 e++;
1096 } while (*e);
1097
1098 /* now instead of copying the URL for a simple lookup, we'll link
1099 * to it from the node we're trying to insert. If it returns a
1100 * different value, it was already there. Otherwise we just have
1101 * to dynamically realloc an entry using strdup().
1102 */
1103 ustat->node.url.key = (char *)b;
1104 ebpt_old = ebis_insert(&timers[0], &ustat->node.url);
1105
1106 if (ebpt_old != &ustat->node.url) {
1107 struct url_stat *ustat_old;
1108 /* node was already there, let's update previous one */
1109 ustat_old = container_of(ebpt_old, struct url_stat, node.url);
1110 ustat_old->nb_req ++;
1111 ustat_old->nb_err += ustat->nb_err;
1112 ustat_old->total_time += ustat->total_time;
1113 ustat_old->total_time_ok += ustat->total_time_ok;
1114 } else {
1115 ustat->url = ustat->node.url.key = strdup(ustat->node.url.key);
1116 ustat = NULL; /* node was used */
1117 }
1118}
1119
1120void filter_graphs(const char *accept_field, const char *time_field, struct timer **tptr)
1121{
1122 struct timer *t2;
1123 const char *e, *p;
1124 int f, err, array[5];
1125
1126 if (!time_field) {
1127 time_field = field_start(accept_field, TIME_FIELD - ACCEPT_FIELD + 1);
1128 if (unlikely(!*time_field)) {
1129 truncated_line(linenum, line);
1130 return;
1131 }
1132 }
1133
1134 e = field_stop(time_field + 1);
1135 /* we have field TIME_FIELD in [time_field]..[e-1] */
1136
1137 p = time_field;
1138 err = 0;
1139 f = 0;
1140 while (!SEP(*p)) {
1141 array[f] = str2ic(p);
1142 if (array[f] < 0) {
1143 array[f] = -1;
1144 err = 1;
1145 }
1146 if (++f == 5)
1147 break;
1148 SKIP_CHAR(p, '/');
1149 }
1150
1151 if (unlikely(f < 5)) {
1152 parse_err++;
1153 return;
1154 }
1155
1156 /* if we find at least one negative time, we count one error
1157 * with a time equal to the total session time. This will
1158 * emphasize quantum timing effects associated to known
1159 * timeouts. Note that on some buggy machines, it is possible
1160 * that the total time is negative, hence the reason to reset
1161 * it.
1162 */
1163
1164 if (filter & FILT_GRAPH_TIMERS) {
1165 if (err) {
1166 if (array[4] < 0)
1167 array[4] = -1;
1168 t2 = insert_timer(&timers[0], tptr, array[4]); // total time
1169 t2->count++;
1170 } else {
1171 int v;
1172
1173 t2 = insert_timer(&timers[1], tptr, array[0]); t2->count++; // req
1174 t2 = insert_timer(&timers[2], tptr, array[2]); t2->count++; // conn
1175 t2 = insert_timer(&timers[3], tptr, array[3]); t2->count++; // resp
1176
1177 v = array[4] - array[0] - array[1] - array[2] - array[3]; // data time
1178 if (v < 0 && !(filter & FILT_QUIET))
1179 fprintf(stderr, "ERR: %s (%d %d %d %d %d => %d)\n",
1180 line, array[0], array[1], array[2], array[3], array[4], v);
1181 t2 = insert_timer(&timers[4], tptr, v); t2->count++;
1182 lines_out++;
1183 }
1184 } else { /* percentile */
1185 if (err) {
1186 if (array[4] < 0)
1187 array[4] = -1;
1188 t2 = insert_value(&timers[0], tptr, array[4]); // total time
1189 t2->count++;
1190 } else {
1191 int v;
1192
1193 t2 = insert_value(&timers[1], tptr, array[0]); t2->count++; // req
1194 t2 = insert_value(&timers[2], tptr, array[2]); t2->count++; // conn
1195 t2 = insert_value(&timers[3], tptr, array[3]); t2->count++; // resp
1196
1197 v = array[4] - array[0] - array[1] - array[2] - array[3]; // data time
1198 if (v < 0 && !(filter & FILT_QUIET))
1199 fprintf(stderr, "ERR: %s (%d %d %d %d %d => %d)\n",
1200 line, array[0], array[1], array[2], array[3], array[4], v);
1201 t2 = insert_value(&timers[4], tptr, v); t2->count++;
1202 lines_out++;
1203 }
1204 }
1205}
1206
1207
Willy Tarreau72c28532009-01-22 18:56:50 +01001208/*
1209 * Local variables:
1210 * c-indent-level: 8
1211 * c-basic-offset: 8
1212 * End:
1213 */