Codebase list httping / aa9ac8c
add tcp rtt measurement / graph range improvements folkert 11 years ago
7 changed file(s) with 86 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
77 {
88 memset(data, 0x00, sizeof(stats_t));
99
10 data -> min = 999999999999.0;
10 data -> min = MY_DOUBLE_INF;
1111 data -> max = -data -> min;
1212 }
1313
1515 #define SSL_CTX void
1616 #define BIO void
1717 #endif
18
19 #define MY_DOUBLE_INF 999999999999999.9
1820
1921 #ifdef TCP_TFO
2022 #ifndef MSG_FASTOPEN
171171 Show the version and exit.
172172
173173 .SH GRAPH
174 The graph in the ncurses uses colors to encode a meaning. Green: value is less than 1 block. Red: the value did not fit in the graph. Blue: the value was limitted by --graph-limit.
174 The graph in the ncurses uses colors to encode a meaning. Green: value is less than 1 block. Red: the value did not fit in the graph. Blue: the value was limitted by --graph-limit. Cyan: no measurement for that point in time.
175175
176176 .SH KEYS
177177 Press <CTRL> + <c> to exit the program. It will display a summary of what was measured.
3737 #ifdef NC
3838 #include "nc.h"
3939 #endif
40
41 #define MI_MA 999999999.9
4240
4341 static volatile int stop = 0;
4442
583581 memset(&(*aggregates)[*n_aggregates - 1], 0x00, sizeof(aggregate_t));
584582
585583 (*aggregates)[*n_aggregates - 1].interval = atoi(dummy);
586 (*aggregates)[*n_aggregates - 1].max = -MI_MA;
587 (*aggregates)[*n_aggregates - 1].min = MI_MA;
584 (*aggregates)[*n_aggregates - 1].max = -MY_DOUBLE_INF;
585 (*aggregates)[*n_aggregates - 1].min = MY_DOUBLE_INF;
588586
589587 dummy = strchr(dummy, ',');
590588 if (dummy)
650648
651649 aggregates[index].value =
652650 aggregates[index].sd = 0.0;
653 aggregates[index].min = MI_MA;
654 aggregates[index].max = -MI_MA;
651 aggregates[index].min = MY_DOUBLE_INF;
652 aggregates[index].max = -MY_DOUBLE_INF;
655653 aggregates[index].n_values = 0;
656654 aggregates[index].last_ts = cur_ts;
657655 }
941939 int n_aggregates = 0;
942940 aggregate_t *aggregates = NULL;
943941 char *au_dummy = NULL, *ap_dummy = NULL;
944 stats_t t_connect, t_request, t_total, t_resolve, t_ssl, stats_to;
942 stats_t t_connect, t_request, t_total, t_resolve, t_ssl, stats_to, tcp_rtt_stats;
945943 double total_took = 0;
946944 char first_resolve = 1;
947 double graph_limit = 9999999.9;
945 double graph_limit = MY_DOUBLE_INF;
948946 char nc_graph = 1;
949947 char adaptive_interval = 0;
950 double show_slow_log = 9999999.0;
948 double show_slow_log = MY_DOUBLE_INF;
951949
952950 init_statst(&t_resolve);
953951 init_statst(&t_connect);
956954 init_statst(&t_ssl);
957955
958956 init_statst(&stats_to);
957 #if defined(linux) || defined(__FreeBSD__)
958 init_statst(&tcp_rtt_stats);
959 #endif
959960
960961 static struct option long_options[] =
961962 {
15371538 double their_est_ts = -1.0, toff_diff_ts = -1.0;
15381539 char tfo_success = 0;
15391540 double ssl_handshake = 0.0;
1540 #ifdef TCP_TFO
1541 #if defined(linux) || defined(__FreeBSD__)
15411542 struct tcp_info info;
15421543 socklen_t info_len = sizeof(struct tcp_info);
15431544 #endif
18751876 }
18761877 #endif
18771878
1878 #ifdef TCP_TFO
1879 #if defined(linux) || defined(__FreeBSD__)
18791880 if (getsockopt(fd, IPPROTO_TCP, TCP_INFO, &info, &info_len) == 0 && (info.tcpi_options & TCPI_OPT_SYN_DATA))
18801881 tfo_success = 1;
18811882 /* printf("%d %d %d %d %d %d\n", info.tcpi_retransmits, info.tcpi_unacked, info.tcpi_sacked, info.tcpi_lost, info.tcpi_retrans, info.tcpi_fackets); */
1883
1884 update_statst(&tcp_rtt_stats, (double)info.tcpi_rtt / 1000.0);
18821885 #endif
18831886
18841887 if (!persistent_connections)
18931896 dummy_ms = (dend - dstart) * 1000.0;
18941897 update_statst(&t_total, dummy_ms);
18951898
1896 /* estimate of when other end started replying */
1897 their_est_ts = (dend + dafter_connect) / 2.0;
1899 their_est_ts = (dend + dafter_connect) / 2.0; /* estimate of when other end started replying */
18981900 toff_diff_ts = ((double)their_ts - their_est_ts) * 1000.0;
18991901 update_statst(&stats_to, toff_diff_ts);
19001902
20762078 emit_statuslines(get_ts() - started_at);
20772079 #ifdef NC
20782080 if (ncurses_mode)
2079 update_stats(&t_resolve, &t_connect, &t_request, &t_total, &t_ssl, curncount, err, sc, fp, use_tfo, nc_graph, use_ssl, &stats_to);
2081 update_stats(&t_resolve, &t_connect, &t_request, &t_total, &t_ssl, curncount, err, sc, fp, use_tfo, nc_graph, use_ssl, &stats_to, &tcp_rtt_stats);
20802082 #endif
20812083
20822084 free(sc);
+64
-26
nc.c less more
2626 char **slow_history = NULL, **fast_history = NULL;
2727 int window_history_n = 0;
2828
29 double graph_limit = 99999999.9;
29 double graph_limit = MY_DOUBLE_INF;
3030 double hz = 1.0;
31
32 double graph_avg = 0.0, graph_sd = 0.0, graph_min = 999999999999.0, graph_max = -99999999999999999.0;
33 int graph_n = 0;
3431
3532 double *history = NULL, *history_temp = NULL, *history_fft = NULL;
3633 char *history_set = NULL;
463460
464461 void draw_graph(double val)
465462 {
466 int index = 0, n = min(max_x, history_n);
463 int index = 0, loop_n = min(max_x, history_n), n = 0, n2 = 0;
467464 double avg = 0, sd = 0;
468 double mi = 0.0, ma = 0.0, diff = 0.0;
469
470 graph_min = min(val, graph_min);
471 graph_max = max(val, graph_max);
472
473 graph_avg += val;
474 graph_sd += val * val;
475 graph_n++;
476
477 avg = graph_avg / (double)graph_n;
478 sd = sqrt((graph_sd / (double)graph_n) - pow(avg, 2.0));
479
480 mi = max(graph_min, max(0.0, avg - sd));
481 ma = min(graph_max, avg + sd);
465 double avg2 = 0, sd2 = 0;
466 double mi = MY_DOUBLE_INF, ma = -MY_DOUBLE_INF, diff = 0.0;
467
468 for(index=0; index<loop_n; index++)
469 {
470 double val = history[index];
471
472 if (!history_set[index])
473 continue;
474
475 mi = min(val, mi);
476 ma = max(val, ma);
477
478 avg += val;
479 sd += val * val;
480 n++;
481 }
482
483 avg /= (double)n;
484 sd = sqrt((sd / (double)n) - pow(avg, 2.0));
485
486 mi = max(mi, avg - sd);
487 ma = min(ma, avg + sd);
488
489 for(index=0; index<loop_n; index++)
490 {
491 double val = history[index];
492
493 if (!history_set[index])
494 continue;
495
496 if (val < mi || val > ma)
497 continue;
498
499 avg2 += val;
500 sd2 += val * val;
501 n2++;
502 }
503
504 avg2 /= (double)n2;
505 sd2 = sqrt((sd2 / (double)n2) - pow(avg2, 2.0));
506
507 mi = max(mi, avg2 - sd2);
508 ma = min(ma, avg2 + sd2);
482509 diff = ma - mi;
483510
484511 if (diff == 0.0)
491518
492519 /* fprintf(stderr, "%d| %f %f %f %f\n", h_stats.n, mi, avg, ma, sd); */
493520
494 for(index=0; index<n; index++)
521 for(index=0; index<loop_n; index++)
495522 {
496523 char overflow = 0, limitter = 0;
497524 double val = 0, height = 0;
498 int i_h = 0;
525 int i_h = 0, x = max_x - (1 + index);
526
527 if (!history_set[index])
528 {
529 mvwchgat(w_stats, stats_h - 1, x, 1, A_REVERSE, C_CYAN, NULL);
530 continue;
531 }
499532
500533 if (history[index] < graph_limit)
501534 val = history[index];
516549 i_h = (int)(height * stats_h);
517550 /* fprintf(stderr, "%d %f %f %d %d\n", index, history[index], height, i_h, overflow); */
518551
519 draw_column(w_stats, max_x - (1 + index), i_h, overflow, limitter);
520 }
521 }
522
523 void update_stats(stats_t *resolve, stats_t *connect, stats_t *request, stats_t *total, stats_t *ssl_setup, int n_ok, int n_fail, const char *last_connect_str, const char *fp, char use_tfo, char dg, char use_ssl, stats_t *st_to)
552 draw_column(w_stats, x, i_h, overflow, limitter);
553 }
554 }
555
556 void update_stats(stats_t *resolve, stats_t *connect, stats_t *request, stats_t *total, stats_t *ssl_setup, int n_ok, int n_fail, const char *last_connect_str, const char *fp, char use_tfo, char dg, char use_ssl, stats_t *st_to, stats_t *tcp_rtt_stats)
524557 {
525558 double k = 0.0;
526559 char force_redraw = 0;
561594 mvwprintw(w_stats, 0, 45, " %6s %6s %6s %6s %6s", "cur", "min", "avg", "max", "sd");
562595 mvwprintw(w_stats, 1, 45, "t offst: %6.2f %6.2f %6.2f %6.2f %6.2f",
563596 st_to -> cur, st_to -> min, st_to -> avg / (double)st_to -> n, st_to -> max, calc_sd(st_to));
597
598 #if defined(linux) || defined(__FreeBSD__)
599 mvwprintw(w_stats, 2, 45, "tcp rtt: %6.2f %6.2f %6.2f %6.2f %6.2f",
600 tcp_rtt_stats -> cur, tcp_rtt_stats -> min, tcp_rtt_stats -> avg / (double)tcp_rtt_stats -> n, tcp_rtt_stats -> max, calc_sd(tcp_rtt_stats));
601 #endif
564602 }
565603
566604 buflen = snprintf(buffer, sizeof buffer, "http result code: %s, SSL fingerprint: %s", last_connect_str, fp ? fp : "n/a");
99 void my_beep(void);
1010 void update_terminal(void);
1111 void status_line(char *fmt, ...);
12 void update_stats(stats_t *resolve, stats_t *connect, stats_t *request, stats_t *total, stats_t *ssl_setup, int n_ok, int n_fail, const char *last_connect_str, const char *fp, char use_tfo, char dg, char use_ssl, stats_t *st_to);
12 void update_stats(stats_t *resolve, stats_t *connect, stats_t *request, stats_t *total, stats_t *ssl_setup, int n_ok, int n_fail, const char *last_connect_str, const char *fp, char use_tfo, char dg, char use_ssl, stats_t *st_to, stats_t *tcp_rtt_stats);
3232 If this script fails with the following error:
3333 ValueError: Expecting object: [...]
3434 then make sure the json-file ends with a ']' (without the quotes).
35 In sm cases this character is missing.
35 In some cases this character is missing.
3636
3737
3838 Thanks to Thanatos for cookie and authentication support.