lsquic_eng_hist.c revision 50aadb33
1/* Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE. */ 2#include <time.h> 3 4#include "lsquic_eng_hist.h" 5 6#if ENG_HIST_ENABLED 7 8#define LSQUIC_LOGGER_MODULE LSQLM_ENG_HIST 9#include "lsquic_logger.h" 10 11 12static void 13log_hist_slice (const struct hist_slice *slice, time_t t) 14{ 15 size_t strftime(char *s, size_t max, const char *format, 16 const struct tm *tm); 17 if (slice->sl_packets_in == 0 && 18 slice->sl_packets_out == 0 && 19 slice->sl_del_mini_conns == 0 && 20 slice->sl_del_full_conns == 0) 21 return; 22 23 struct tm tm; 24 char timestr[sizeof("12:00:00")]; 25 26 localtime_r(&t, &tm); 27 strftime(timestr, sizeof(timestr), "%T", &tm); 28 29 LSQ_DEBUG("%s: pi: %u; po: %u; +mc: %u; -mc: %u; +fc: %u; -fc: %u", 30 timestr, 31 slice->sl_packets_in, 32 slice->sl_packets_out, 33 slice->sl_new_mini_conns, 34 slice->sl_del_mini_conns, 35 slice->sl_new_full_conns, 36 slice->sl_del_full_conns); 37} 38 39 40void 41eng_hist_log (const struct eng_hist *hist) 42{ 43 unsigned i, idx; 44 time_t t0 = time(NULL) - ENG_HIST_NELEMS + 1; 45 for (i = 0; i < ENG_HIST_NELEMS; ++i) 46 { 47 idx = (hist->eh_prev_idx + i + 1) & (ENG_HIST_NELEMS - 1); 48 if (i >= ENG_HIST_NELEMS - ENG_HIST_N_TO_PRINT) 49 log_hist_slice(&hist->eh_slices[idx], t0 + i); 50 } 51} 52 53#endif 54