diff --git a/src/detect-engine.c b/src/detect-engine.c index 63de6d6a58..f2247b5d6b 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -1356,12 +1356,14 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data) * rules haven't been loaded yet. */ uint16_t counter_alerts = SCPerfTVRegisterCounter("detect.alert", tv, SC_PERF_TYPE_UINT64, "NULL"); +#ifdef PROFILING uint16_t counter_mpm_list = SCPerfTVRegisterAvgCounter("detect.mpm_list", tv, SC_PERF_TYPE_UINT64, "NULL"); uint16_t counter_nonmpm_list = SCPerfTVRegisterAvgCounter("detect.nonmpm_list", tv, SC_PERF_TYPE_UINT64, "NULL"); uint16_t counter_match_list = SCPerfTVRegisterAvgCounter("detect.match_list", tv, SC_PERF_TYPE_UINT64, "NULL"); +#endif if (de_ctx->delayed_detect == 1 && de_ctx->delayed_detect_initialized == 0) { *data = NULL; return TM_ECODE_OK; @@ -1380,9 +1382,11 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data) /** alert counter setup */ det_ctx->counter_alerts = counter_alerts; +#ifdef PROFILING det_ctx->counter_mpm_list = counter_mpm_list; det_ctx->counter_nonmpm_list = counter_nonmpm_list; det_ctx->counter_match_list = counter_match_list; +#endif /* pass thread data back to caller */ *data = (void *)det_ctx; diff --git a/src/detect.c b/src/detect.c index 46a66f31f6..9977908314 100644 --- a/src/detect.c +++ b/src/detect.c @@ -1334,8 +1334,14 @@ int SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineTh PACKET_PROFILING_DETECT_START(p, PROF_DETECT_MPM); DetectMpmPrefilter(de_ctx, det_ctx, smsg, p, flags, alproto, has_state, &sms_runflags); PACKET_PROFILING_DETECT_END(p, PROF_DETECT_MPM); - SCPerfCounterAddUI64(det_ctx->counter_mpm_list, th_v->sc_perf_pca, (uint64_t)det_ctx->pmq.rule_id_array_cnt); - SCPerfCounterAddUI64(det_ctx->counter_nonmpm_list, th_v->sc_perf_pca, (uint64_t)det_ctx->sgh->non_mpm_id_cnt); +#ifdef PROFILING + if (th_v) { + SCPerfCounterAddUI64(det_ctx->counter_mpm_list, th_v->sc_perf_pca, + (uint64_t)det_ctx->pmq.rule_id_array_cnt); + SCPerfCounterAddUI64(det_ctx->counter_nonmpm_list, th_v->sc_perf_pca, + (uint64_t)det_ctx->sgh->non_mpm_id_cnt); + } +#endif PACKET_PROFILING_DETECT_START(p, PROF_DETECT_PREFILTER); DetectPrefilterMergeSort(de_ctx, det_ctx, det_ctx->sgh); @@ -1345,7 +1351,12 @@ int SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineTh /* inspect the sigs against the packet */ /* Prefetch the next signature. */ SigIntId match_cnt = det_ctx->match_array_cnt; - SCPerfCounterAddUI64(det_ctx->counter_match_list, th_v->sc_perf_pca, (uint64_t)match_cnt); +#ifdef PROFILING + if (th_v) { + SCPerfCounterAddUI64(det_ctx->counter_match_list, th_v->sc_perf_pca, + (uint64_t)match_cnt); + } +#endif Signature **match_array = det_ctx->match_array; uint32_t sflags, next_sflags = 0; diff --git a/src/detect.h b/src/detect.h index c3485a9f70..2ed8b5a3c0 100644 --- a/src/detect.h +++ b/src/detect.h @@ -791,9 +791,11 @@ typedef struct DetectionEngineThreadCtx_ { /** id for alert counter */ uint16_t counter_alerts; +#ifdef COLLECT_SIGMATCH_LIST_STATS uint16_t counter_mpm_list; uint16_t counter_nonmpm_list; uint16_t counter_match_list; +#endif /* used to discontinue any more matching */ uint16_t discontinue_matching;