adapted counters to use util-time.[ch]

remotes/origin/master-1.0.x
Anoop Saldanha 16 years ago committed by Victor Julien
parent c8b423578a
commit 30a7ea2141

@ -8,8 +8,9 @@
#include "threadvars.h"
#include "tm-modules.h"
#include "tm-threads.h"
#include "util-unittest.h"
#include "conf.h"
#include "util-time.h"
#include "util-unittest.h"
#include "util-debug.h"
/** \todo Get the default log directory from some global resource. */
@ -322,7 +323,7 @@ static int SCPerfParseTBCounterInterval(SCPerfCounter *pc, char *interval)
pc->type_q->total_secs = ((pc->type_q->hours * 60 * 60) +
(pc->type_q->minutes * 60) + pc->type_q->seconds);
pc->type_q->ts = time(NULL);
TimeGet(&pc->type_q->ts);
return 0;
@ -601,7 +602,7 @@ static void SCPerfCopyCounterValue(SCPCAElem *pcae, int reset_lc)
*/
static void SCPerfOutputCalculateCounterValue(SCPerfCounter *pc, void *cvalue_op)
{
time_t curr_ts;
struct timeval curr_ts;
int elapsed_secs = 0;
double divisor = 0;
@ -621,8 +622,9 @@ static void SCPerfOutputCalculateCounterValue(SCPerfCounter *pc, void *cvalue_op
return;
/* we have a timebased counter. Awesome. Time for some more processing */
curr_ts = time(NULL);
elapsed_secs = curr_ts - pc->type_q->ts;
TimeGet(&curr_ts);
elapsed_secs = ((curr_ts.tv_sec + curr_ts.tv_usec / 1000000.0) -
(pc->type_q->ts.tv_sec + pc->type_q->ts.tv_usec / 1000000.0));
if (elapsed_secs < pc->type_q->total_secs)
return;
@ -642,8 +644,9 @@ static void SCPerfOutputCalculateCounterValue(SCPerfCounter *pc, void *cvalue_op
break;
}
pc->type_q->ts = time(NULL);
/* reset the timestamp to the current time */
TimeGet(&pc->type_q->ts);
/* reset the local counter back to 0 */
memset(pc->value->cvalue, 0, pc->value->size);
return;

@ -76,7 +76,7 @@ typedef struct SCPerfCounterTypeQ_ {
int total_secs;
/* timestamp to indicate the time, when the counter was last reset */
time_t ts;
struct timeval ts;
} SCPerfCounterTypeQ;
/**

@ -5,21 +5,24 @@
#include "threads.h"
#include "util-debug.h"
static struct timeval current_time = { 0,0 };
static struct timeval current_time = { 0, 0 };
static pthread_mutex_t current_time_mutex = PTHREAD_MUTEX_INITIALIZER;
static char live = TRUE;
void TimeModeSetLive(void) {
void TimeModeSetLive(void)
{
live = TRUE;
SCLogDebug("live time mode enabled");
}
void TimeModeSetOffline (void) {
void TimeModeSetOffline (void)
{
live = FALSE;
SCLogDebug("offline time mode enabled");
}
void TimeSet(struct timeval *tv) {
void TimeSet(struct timeval *tv)
{
if (live == TRUE)
return;
@ -31,12 +34,13 @@ void TimeSet(struct timeval *tv) {
current_time.tv_usec = tv->tv_usec;
SCLogDebug("time set to %" PRIuMAX " sec, %" PRIuMAX " usec",
(uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec);
(uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec);
mutex_unlock(&current_time_mutex);
}
void TimeGet(struct timeval *tv) {
void TimeGet(struct timeval *tv)
{
if (tv == NULL)
return;
@ -50,6 +54,5 @@ void TimeGet(struct timeval *tv) {
}
SCLogDebug("time we got is %" PRIuMAX " sec, %" PRIuMAX " usec",
(uintmax_t)tv->tv_sec, (uintmax_t)tv->tv_usec);
(uintmax_t)tv->tv_sec, (uintmax_t)tv->tv_usec);
}

Loading…
Cancel
Save