diff --git a/src/util-profiling.c b/src/util-profiling.c index a4f5bbef0ae7..e8a2dfa6330a 100644 --- a/src/util-profiling.c +++ b/src/util-profiling.c @@ -1208,15 +1208,16 @@ int SCProfileRuleStart(Packet *p) p->flags |= PKT_PROFILE; return 1; } -#else +#endif + if (p->flags & PKT_PROFILE) { + return 1; + } + uint64_t sample = SC_ATOMIC_ADD(samples, 1); - if (sample % rate == 0) { + if ((sample % rate) == 0) { p->flags |= PKT_PROFILE; return 1; } -#endif - if (p->flags & PKT_PROFILE) - return 1; return 0; } @@ -1450,17 +1451,20 @@ void SCProfilingInit(void) /* see if we want to profile rules for this packet */ int SCProfileRuleStart(Packet *p) { + /* Move first so we'll always finish even if dynamically disabled */ + if (p->flags & PKT_PROFILE) + return 1; + if (!SC_ATOMIC_GET(profiling_rules_active)) { return 0; } + uint64_t sample = SC_ATOMIC_ADD(samples, 1); if ((sample & rate) == 0) { p->flags |= PKT_PROFILE; return 1; } - if (p->flags & PKT_PROFILE) - return 1; return 0; } diff --git a/src/util-profiling.h b/src/util-profiling.h index 21b60a3c1916..564f62b5c78f 100644 --- a/src/util-profiling.h +++ b/src/util-profiling.h @@ -417,7 +417,7 @@ void SCProfilingRuleThreatAggregate(DetectEngineThreadCtx *det_ctx); } #define RULE_PROFILING_END(ctx, r, m, p) \ - if (profiling_rules_enabled && ((p)->flags & PKT_PROFILE)) { \ + if (profiling_rules_enabled && profiling_rules_entered) { \ profile_rule_end_ = UtilCpuGetTicks(); \ SCProfilingRuleUpdateCounter( \ ctx, r->profiling_id, profile_rule_end_ - profile_rule_start_, m); \