counters: add StatsDecr

pull/7533/head
Victor Julien 3 years ago
parent 88edc8630c
commit aa31d2193f

@ -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,

@ -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 *);

@ -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.

@ -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_ {

Loading…
Cancel
Save