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