diff --git a/src/counters.c b/src/counters.c index 46fc79caa2..6960fe06e9 100644 --- a/src/counters.c +++ b/src/counters.c @@ -181,6 +181,27 @@ void StatsIncr(ThreadVars *tv, uint16_t id) return; } +/** + * \brief Decrements the local counter + * + * \param id Index of the counter in the counter array + * \param pca Counter array that holds the local counters for this TM + */ +void StatsDecr(ThreadVars *tv, uint16_t id) +{ + StatsPrivateThreadContext *pca = &tv->perf_private_ctx; +#if defined(UNITTESTS) || defined(FUZZ) + if (pca->initialized == 0) + return; +#endif +#ifdef DEBUG + BUG_ON((id < 1) || (id > pca->size)); +#endif + pca->head[id].value--; + pca->head[id].updates++; + return; +} + /** * \brief Sets a value of type double to the local counter * @@ -199,8 +220,7 @@ void StatsSetUI64(ThreadVars *tv, uint16_t id, uint64_t x) BUG_ON ((id < 1) || (id > pca->size)); #endif - if ((pca->head[id].pc->type == STATS_TYPE_MAXIMUM) && - (x > pca->head[id].value)) { + if ((pca->head[id].pc->type == STATS_TYPE_MAXIMUM) && ((int64_t)x > pca->head[id].value)) { pca->head[id].value = x; } else if (pca->head[id].pc->type == STATS_TYPE_NORMAL) { pca->head[id].value = x; @@ -666,7 +686,7 @@ static int StatsOutput(ThreadVars *tv) * especially needed for the average counters */ struct CountersMergeTable { int type; - uint64_t value; + int64_t value; uint64_t updates; } merge_table[max_id]; memset(&merge_table, 0x00, diff --git a/src/counters.h b/src/counters.h index d59cdbc581..f6b6bc07a7 100644 --- a/src/counters.h +++ b/src/counters.h @@ -41,7 +41,7 @@ typedef struct StatsCounter_ { uint16_t gid; /* counter value(s): copies from the 'private' counter */ - uint64_t value; /**< sum of updates/increments, or 'set' value */ + int64_t value; /**< sum of updates/increments, or 'set' value */ uint64_t updates; /**< number of updates (for avg) */ /* when using type STATS_TYPE_Q_FUNC this function is called once @@ -84,7 +84,7 @@ typedef struct StatsLocalCounter_ { uint16_t id; /* total value of the adds/increments, or exact value in case of 'set' */ - uint64_t value; + int64_t value; /* no of times the local counter has been updated */ uint64_t updates; @@ -124,6 +124,7 @@ uint16_t StatsRegisterGlobalCounter(const char *cname, uint64_t (*Func)(void)); void StatsAddUI64(struct ThreadVars_ *, uint16_t, uint64_t); void StatsSetUI64(struct ThreadVars_ *, uint16_t, uint64_t); void StatsIncr(struct ThreadVars_ *, uint16_t); +void StatsDecr(struct ThreadVars_ *, uint16_t); /* utility functions */ int StatsUpdateCounterArray(StatsPrivateThreadContext *, StatsPublicThreadContext *); diff --git a/src/log-stats.c b/src/log-stats.c index cb257a6f19..ac8ea13a5a 100644 --- a/src/log-stats.c +++ b/src/log-stats.c @@ -142,7 +142,7 @@ static int LogStatsLogger(ThreadVars *tv, void *thread_data, const StatsTable *s continue; char line[256]; - size_t len = snprintf(line, sizeof(line), "%-45s | %-25s | %-" PRIu64 "\n", + size_t len = snprintf(line, sizeof(line), "%-45s | %-25s | %-" PRIi64 "\n", st->tstats[u].name, st->tstats[u].tm_name, st->tstats[u].value); /* since we can have many threads, the buffer might not be big enough. diff --git a/src/output-stats.h b/src/output-stats.h index eba72f36e4..e5cd429b40 100644 --- a/src/output-stats.h +++ b/src/output-stats.h @@ -29,8 +29,8 @@ typedef struct StatsRecord_ { const char *name; const char *tm_name; - uint64_t value; /**< total value */ - uint64_t pvalue; /**< prev value (may be higher for memuse counters) */ + int64_t value; /**< total value */ + int64_t pvalue; /**< prev value (may be higher for memuse counters) */ } StatsRecord; typedef struct StatsTable_ {