lsquic_eng_hist.c revision 50aadb33
150aadb33SDmitri Tikhonov/* Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov#include <time.h>
350aadb33SDmitri Tikhonov
450aadb33SDmitri Tikhonov#include "lsquic_eng_hist.h"
550aadb33SDmitri Tikhonov
650aadb33SDmitri Tikhonov#if ENG_HIST_ENABLED
750aadb33SDmitri Tikhonov
850aadb33SDmitri Tikhonov#define LSQUIC_LOGGER_MODULE LSQLM_ENG_HIST
950aadb33SDmitri Tikhonov#include "lsquic_logger.h"
1050aadb33SDmitri Tikhonov
1150aadb33SDmitri Tikhonov
1250aadb33SDmitri Tikhonovstatic void
1350aadb33SDmitri Tikhonovlog_hist_slice (const struct hist_slice *slice, time_t t)
1450aadb33SDmitri Tikhonov{
1550aadb33SDmitri Tikhonov    size_t strftime(char *s, size_t max, const char *format,
1650aadb33SDmitri Tikhonov                                  const struct tm *tm);
1750aadb33SDmitri Tikhonov    if (slice->sl_packets_in == 0 &&
1850aadb33SDmitri Tikhonov        slice->sl_packets_out == 0 &&
1950aadb33SDmitri Tikhonov        slice->sl_del_mini_conns == 0 &&
2050aadb33SDmitri Tikhonov        slice->sl_del_full_conns == 0)
2150aadb33SDmitri Tikhonov        return;
2250aadb33SDmitri Tikhonov
2350aadb33SDmitri Tikhonov    struct tm tm;
2450aadb33SDmitri Tikhonov    char timestr[sizeof("12:00:00")];
2550aadb33SDmitri Tikhonov
2650aadb33SDmitri Tikhonov    localtime_r(&t, &tm);
2750aadb33SDmitri Tikhonov    strftime(timestr, sizeof(timestr), "%T", &tm);
2850aadb33SDmitri Tikhonov
2950aadb33SDmitri Tikhonov    LSQ_DEBUG("%s: pi: %u; po: %u; +mc: %u; -mc: %u; +fc: %u; -fc: %u",
3050aadb33SDmitri Tikhonov        timestr,
3150aadb33SDmitri Tikhonov        slice->sl_packets_in,
3250aadb33SDmitri Tikhonov        slice->sl_packets_out,
3350aadb33SDmitri Tikhonov        slice->sl_new_mini_conns,
3450aadb33SDmitri Tikhonov        slice->sl_del_mini_conns,
3550aadb33SDmitri Tikhonov        slice->sl_new_full_conns,
3650aadb33SDmitri Tikhonov        slice->sl_del_full_conns);
3750aadb33SDmitri Tikhonov}
3850aadb33SDmitri Tikhonov
3950aadb33SDmitri Tikhonov
4050aadb33SDmitri Tikhonovvoid
4150aadb33SDmitri Tikhonoveng_hist_log (const struct eng_hist *hist)
4250aadb33SDmitri Tikhonov{
4350aadb33SDmitri Tikhonov    unsigned i, idx;
4450aadb33SDmitri Tikhonov    time_t t0 = time(NULL) - ENG_HIST_NELEMS + 1;
4550aadb33SDmitri Tikhonov    for (i = 0; i < ENG_HIST_NELEMS; ++i)
4650aadb33SDmitri Tikhonov    {
4750aadb33SDmitri Tikhonov        idx = (hist->eh_prev_idx + i + 1) & (ENG_HIST_NELEMS - 1);
4850aadb33SDmitri Tikhonov        if (i >= ENG_HIST_NELEMS - ENG_HIST_N_TO_PRINT)
4950aadb33SDmitri Tikhonov            log_hist_slice(&hist->eh_slices[idx], t0 + i);
5050aadb33SDmitri Tikhonov    }
5150aadb33SDmitri Tikhonov}
5250aadb33SDmitri Tikhonov
5350aadb33SDmitri Tikhonov#endif
54