lsquic_eng_hist.c revision 5392f7a3
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov#include <time.h>
3461e84d8SAmol Deshpande#ifdef WIN32
4461e84d8SAmol Deshpande#include <vc_compat.h>
5461e84d8SAmol Deshpande#define localtime_r(a,b) localtime_s(b,a)
6461e84d8SAmol Deshpande#endif
750aadb33SDmitri Tikhonov
850aadb33SDmitri Tikhonov#include "lsquic_eng_hist.h"
950aadb33SDmitri Tikhonov
1050aadb33SDmitri Tikhonov#if ENG_HIST_ENABLED
1150aadb33SDmitri Tikhonov
1250aadb33SDmitri Tikhonov#define LSQUIC_LOGGER_MODULE LSQLM_ENG_HIST
135392f7a3SLiteSpeed Tech#include "lsquic_types.h"
1450aadb33SDmitri Tikhonov#include "lsquic_logger.h"
1550aadb33SDmitri Tikhonov
1650aadb33SDmitri Tikhonov
1750aadb33SDmitri Tikhonovstatic void
1850aadb33SDmitri Tikhonovlog_hist_slice (const struct hist_slice *slice, time_t t)
1950aadb33SDmitri Tikhonov{
2050aadb33SDmitri Tikhonov    size_t strftime(char *s, size_t max, const char *format,
2150aadb33SDmitri Tikhonov                                  const struct tm *tm);
2250aadb33SDmitri Tikhonov    if (slice->sl_packets_in == 0 &&
2350aadb33SDmitri Tikhonov        slice->sl_packets_out == 0 &&
2450aadb33SDmitri Tikhonov        slice->sl_del_mini_conns == 0 &&
2550aadb33SDmitri Tikhonov        slice->sl_del_full_conns == 0)
2650aadb33SDmitri Tikhonov        return;
2750aadb33SDmitri Tikhonov
2850aadb33SDmitri Tikhonov    struct tm tm;
2950aadb33SDmitri Tikhonov    char timestr[sizeof("12:00:00")];
3050aadb33SDmitri Tikhonov
3150aadb33SDmitri Tikhonov    localtime_r(&t, &tm);
3250aadb33SDmitri Tikhonov    strftime(timestr, sizeof(timestr), "%T", &tm);
3350aadb33SDmitri Tikhonov
3450aadb33SDmitri Tikhonov    LSQ_DEBUG("%s: pi: %u; po: %u; +mc: %u; -mc: %u; +fc: %u; -fc: %u",
3550aadb33SDmitri Tikhonov        timestr,
3650aadb33SDmitri Tikhonov        slice->sl_packets_in,
3750aadb33SDmitri Tikhonov        slice->sl_packets_out,
3850aadb33SDmitri Tikhonov        slice->sl_new_mini_conns,
3950aadb33SDmitri Tikhonov        slice->sl_del_mini_conns,
4050aadb33SDmitri Tikhonov        slice->sl_new_full_conns,
4150aadb33SDmitri Tikhonov        slice->sl_del_full_conns);
4250aadb33SDmitri Tikhonov}
4350aadb33SDmitri Tikhonov
4450aadb33SDmitri Tikhonov
4550aadb33SDmitri Tikhonovvoid
4650aadb33SDmitri Tikhonoveng_hist_log (const struct eng_hist *hist)
4750aadb33SDmitri Tikhonov{
4850aadb33SDmitri Tikhonov    unsigned i, idx;
4950aadb33SDmitri Tikhonov    time_t t0 = time(NULL) - ENG_HIST_NELEMS + 1;
5050aadb33SDmitri Tikhonov    for (i = 0; i < ENG_HIST_NELEMS; ++i)
5150aadb33SDmitri Tikhonov    {
5250aadb33SDmitri Tikhonov        idx = (hist->eh_prev_idx + i + 1) & (ENG_HIST_NELEMS - 1);
5350aadb33SDmitri Tikhonov        if (i >= ENG_HIST_NELEMS - ENG_HIST_N_TO_PRINT)
5450aadb33SDmitri Tikhonov            log_hist_slice(&hist->eh_slices[idx], t0 + i);
5550aadb33SDmitri Tikhonov    }
5650aadb33SDmitri Tikhonov}
5750aadb33SDmitri Tikhonov
5850aadb33SDmitri Tikhonov#endif
59