counters: use a dedicated type for avg counters

pull/14398/head
Victor Julien 9 months ago
parent e13b4ecbce
commit a8095d8ef5

@ -247,6 +247,21 @@ void StatsCounterMaxUpdateI64(ThreadVars *tv, StatsCounterMaxId id, int64_t x)
}
}
void StatsCounterAvgAddI64(ThreadVars *tv, StatsCounterAvgId id, int64_t x)
{
StatsPrivateThreadContext *pca = &tv->perf_private_ctx;
#if defined(UNITTESTS) || defined(FUZZ)
if (pca->initialized == 0)
return;
#endif
#ifdef DEBUG
BUG_ON((id.id < 1) || (id.id > pca->size));
#endif
pca->head[id.id].value += x;
pca->head[id.id].updates++;
}
static SCConfNode *GetConfig(void)
{
SCConfNode *stats = SCConfGetNode("stats");
@ -1008,13 +1023,14 @@ uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
* \retval id Counter id for the newly registered counter, or the already
* present counter
*/
uint16_t StatsRegisterAvgCounter(const char *name, struct ThreadVars_ *tv)
StatsCounterAvgId StatsRegisterAvgCounter(const char *name, struct ThreadVars_ *tv)
{
uint16_t id = StatsRegisterQualifiedCounter(name,
(tv->thread_group_name != NULL) ? tv->thread_group_name : tv->printable_name,
&tv->perf_public_ctx,
STATS_TYPE_AVERAGE, NULL);
return id;
StatsCounterAvgId s = { .id = id };
return s;
}
/**

@ -30,6 +30,10 @@
/* forward declaration of the ThreadVars structure */
struct ThreadVars_;
typedef struct StatsCounterAvgId {
uint16_t id;
} StatsCounterAvgId;
typedef struct StatsCounterMaxId {
uint16_t id;
} StatsCounterMaxId;
@ -123,7 +127,7 @@ void StatsReleaseResources(void);
/* counter registration functions */
uint16_t StatsRegisterCounter(const char *, struct ThreadVars_ *);
uint16_t StatsRegisterAvgCounter(const char *, struct ThreadVars_ *);
StatsCounterAvgId StatsRegisterAvgCounter(const char *, struct ThreadVars_ *);
StatsCounterMaxId StatsRegisterMaxCounter(const char *, struct ThreadVars_ *);
uint16_t StatsRegisterGlobalCounter(const char *cname, uint64_t (*Func)(void));
@ -134,6 +138,7 @@ void StatsIncr(struct ThreadVars_ *, uint16_t);
void StatsDecr(struct ThreadVars_ *, uint16_t);
void StatsCounterMaxUpdateI64(struct ThreadVars_ *tv, StatsCounterMaxId id, int64_t x);
void StatsCounterAvgAddI64(struct ThreadVars_ *tv, StatsCounterAvgId id, int64_t x);
/* utility functions */
int StatsUpdateCounterArray(StatsPrivateThreadContext *, StatsPublicThreadContext *);

@ -778,7 +778,7 @@ void DecodeUpdatePacketCounters(ThreadVars *tv,
StatsIncr(tv, dtv->counter_pkts);
//StatsIncr(tv, dtv->counter_pkts_per_sec);
StatsAddUI64(tv, dtv->counter_bytes, GET_PKT_LEN(p));
StatsAddUI64(tv, dtv->counter_avg_pkt_size, GET_PKT_LEN(p));
StatsCounterAvgAddI64(tv, dtv->counter_avg_pkt_size, GET_PKT_LEN(p));
StatsCounterMaxUpdateI64(tv, dtv->counter_max_pkt_size, GET_PKT_LEN(p));
}

@ -967,7 +967,7 @@ typedef struct DecodeThreadVars_
/** stats/counters */
uint16_t counter_pkts;
uint16_t counter_bytes;
uint16_t counter_avg_pkt_size;
StatsCounterAvgId counter_avg_pkt_size;
StatsCounterMaxId counter_max_pkt_size;
StatsCounterMaxId counter_max_mac_addrs_src;
StatsCounterMaxId counter_max_mac_addrs_dst;
@ -1048,7 +1048,7 @@ typedef struct DecodeThreadVars_
uint16_t counter_flow_spare_sync;
uint16_t counter_flow_spare_sync_empty;
uint16_t counter_flow_spare_sync_incomplete;
uint16_t counter_flow_spare_sync_avg;
StatsCounterAvgId counter_flow_spare_sync_avg;
uint16_t counter_engine_events[DECODE_EVENT_MAX];

@ -600,7 +600,8 @@ static inline void DetectRunPrefilterPkt(ThreadVars *tv, const DetectEngineCtx *
if (det_ctx->pmq.rule_id_array_cnt) {
#ifdef PROFILING
if (tv) {
StatsAddUI64(tv, det_ctx->counter_mpm_list, (uint64_t)det_ctx->pmq.rule_id_array_cnt);
StatsCounterAvgAddI64(
tv, det_ctx->counter_mpm_list, (int64_t)det_ctx->pmq.rule_id_array_cnt);
}
#endif
PACKET_PROFILING_DETECT_START(p, PROF_DETECT_PF_SORT2);
@ -664,8 +665,7 @@ static inline uint8_t DetectRulePacketRules(ThreadVars *const tv,
SigIntId match_cnt = det_ctx->match_array_cnt;
#ifdef PROFILING
if (tv) {
StatsAddUI64(tv, det_ctx->counter_match_list,
(uint64_t)match_cnt);
StatsCounterAvgAddI64(tv, det_ctx->counter_match_list, (int64_t)match_cnt);
}
#endif
Signature **match_array = det_ctx->match_array;

@ -1293,8 +1293,8 @@ typedef struct DetectEngineThreadCtx_ {
/** id for suppressed alerts counter */
uint16_t counter_alerts_suppressed;
#ifdef PROFILING
uint16_t counter_mpm_list;
uint16_t counter_match_list;
StatsCounterAvgId counter_mpm_list;
StatsCounterAvgId counter_match_list;
#endif
struct {

@ -639,7 +639,8 @@ static inline Flow *FlowSpareSync(ThreadVars *tv, FlowLookupStruct *fls,
#endif
if (spare_sync) {
if (f != NULL) {
StatsAddUI64(tv, fls->dtv->counter_flow_spare_sync_avg, fls->spare_queue.len+1);
StatsCounterAvgAddI64(
tv, fls->dtv->counter_flow_spare_sync_avg, fls->spare_queue.len + 1);
if (fls->spare_queue.len < 99) {
/* When a new flow pool is fetched it has 100 flows in sync,
* so there should be 99 left if we're in full sync.

@ -1032,7 +1032,7 @@ typedef struct FlowRecyclerThreadData_ {
void *output_thread_data;
uint16_t counter_flows;
uint16_t counter_queue_avg;
StatsCounterAvgId counter_queue_avg;
StatsCounterMaxId counter_queue_max;
uint16_t counter_flow_active;
@ -1112,7 +1112,7 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
SC_ATOMIC_ADD(flowrec_busy,1);
FlowQueuePrivate list = FlowQueueExtractPrivate(&flow_recycle_q);
StatsAddUI64(th_v, ftd->counter_queue_avg, list.len);
StatsCounterAvgAddI64(th_v, ftd->counter_queue_avg, (int64_t)list.len);
StatsCounterMaxUpdateI64(th_v, ftd->counter_queue_max, (int64_t)list.len);
const int bail = (TmThreadsCheckFlag(th_v, THV_KILL));

@ -289,7 +289,7 @@ typedef struct AFPThreadVars_
uint16_t capture_kernel_packets;
uint16_t capture_kernel_drops;
uint16_t capture_errors;
uint16_t afpacket_spin;
StatsCounterAvgId afpacket_spin;
uint16_t capture_afp_poll;
uint16_t capture_afp_poll_signal;
uint16_t capture_afp_poll_timeout;
@ -823,7 +823,7 @@ static inline int AFPReadFromRingWaitForPacket(AFPThreadVars *ptv)
union thdr h;
struct timeval start_time;
gettimeofday(&start_time, NULL);
uint64_t busy_loop_iter = 0;
int64_t busy_loop_iter = 0;
/* busy wait loop until we have packets available */
while (1) {
@ -851,7 +851,7 @@ static inline int AFPReadFromRingWaitForPacket(AFPThreadVars *ptv)
break;
}
if (busy_loop_iter) {
StatsAddUI64(ptv->tv, ptv->afpacket_spin, busy_loop_iter);
StatsCounterAvgAddI64(ptv->tv, ptv->afpacket_spin, busy_loop_iter);
}
return AFP_READ_OK;
}

Loading…
Cancel
Save