stats: more accurate interval handling

In the stats loop sleep for a time period more closely matching
the stats.interval setting. Fix an off by one that would make
the loop wake up ~1 second early.

Bug #2716
pull/3577/head
Victor Julien 8 years ago
parent c1238af3e0
commit 31f81429c2

@ -340,7 +340,6 @@ static void *StatsMgmtThread(void *arg)
{
ThreadVars *tv_local = (ThreadVars *)arg;
uint8_t run = 1;
struct timespec cond_time;
/* Set the thread name */
if (SCSetThreadName(tv_local->name) < 0) {
@ -381,8 +380,11 @@ static void *StatsMgmtThread(void *arg)
TmThreadsUnsetFlag(tv_local, THV_PAUSED);
}
cond_time.tv_sec = time(NULL) + stats_tts;
cond_time.tv_nsec = 0;
struct timeval cur_timev;
gettimeofday(&cur_timev, NULL);
struct timespec cond_time = FROM_TIMEVAL(cur_timev);
cond_time.tv_sec += (stats_tts);
/* wait for the set time, or until we are woken up by
* the shutdown procedure */

@ -40,6 +40,9 @@ void TimeDeinit(void);
void TimeSetByThread(const int thread_id, const struct timeval *tv);
void TimeGet(struct timeval *);
/** \brief intialize a 'struct timespec' from a 'struct timeval'. */
#define FROM_TIMEVAL(timev) { .tv_sec = (timev).tv_sec, .tv_nsec = (timev).tv_usec * 1000 }
#ifdef UNITTESTS
void TimeSet(struct timeval *);
void TimeSetToCurrentTime(void);

Loading…
Cancel
Save