]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
profiling/rules: reduce sync logic scope
authorVictor Julien <vjulien@oisf.net>
Fri, 12 May 2023 11:56:51 +0000 (13:56 +0200)
committerVictor Julien <vjulien@oisf.net>
Fri, 12 May 2023 17:52:15 +0000 (19:52 +0200)
Use a simple once a second scheme.

src/counters.c
src/detect.c
src/detect.h
src/flow-worker.c
src/threadvars.h

index 2b2100a3649f06e8e0d5fd351e46bb5aca551d8d..0a6ace4bbb01b164aa30821f27d7b5762aee0f69 100644 (file)
@@ -512,7 +512,6 @@ static void *StatsWakeupThread(void *arg)
             /* assuming the assignment of an int to be atomic, and even if it's
              * not, it should be okay */
             tv->perf_public_ctx.perf_flag = 1;
-            tv->profile_flag = 1;
 
             if (tv->inq != NULL) {
                 PacketQueue *q = tv->inq->pq;
@@ -533,7 +532,6 @@ static void *StatsWakeupThread(void *arg)
             /* assuming the assignment of an int to be atomic, and even if it's
              * not, it should be okay */
             tv->perf_public_ctx.perf_flag = 1;
-            tv->profile_flag = 1;
 
             tv = tv->next;
         }
index 2648ad74b9aff59db9790712ecad57786eb7f5cc..8284a6597c2c6edf6807b85858af605257112259 100644 (file)
@@ -1792,6 +1792,15 @@ TmEcode Detect(ThreadVars *tv, Packet *p, void *data)
     } else {
         DetectNoFlow(tv, de_ctx, det_ctx, p);
     }
+
+#ifdef PROFILE_RULES
+    /* aggregate statistics */
+    if (SCTIME_SECS(p->ts) != det_ctx->rule_perf_last_sync) {
+        SCProfilingRuleThreatAggregate(det_ctx);
+        det_ctx->rule_perf_last_sync = SCTIME_SECS(p->ts);
+    }
+#endif
+
     return TM_ECODE_OK;
 error:
     return TM_ECODE_FAILED;
index 828428521e38b5ab68d4dcebcba116f7f6f73021..d66135b6c89f8aa2ced1f15be0c905f5a92e9454 100644 (file)
@@ -1188,6 +1188,7 @@ typedef struct DetectEngineThreadCtx_ {
 #ifdef PROFILE_RULES
     struct SCProfileData_ *rule_perf_data;
     int rule_perf_data_size;
+    uint32_t rule_perf_last_sync;
 #endif
 #ifdef PROFILING
     struct SCProfileKeywordData_ *keyword_perf_data;
index 4a8bd9b506b0eff52ebab7c3a3bfdfa60800b79b..9ecfe65f299ad46e24c7ee4197ef9693e302788c 100644 (file)
@@ -614,14 +614,6 @@ housekeeping:
     /* process local work queue */
     FlowWorkerProcessLocalFlows(tv, fw, p);
 
-#ifdef PROFILE_RULES
-    /* aggregate statistics */
-    if (tv->profile_flag == 1) {
-        SCProfilingRuleThreatAggregate((DetectEngineThreadCtx *)detect_thread);
-        tv->profile_flag = 0;
-    }
-#endif
-
     return TM_ECODE_OK;
 }
 
index 6f16349fa28a61c37e64047e010c709f08d8720d..ea448c0949864c0979867aa64e3790033f2b2196 100644 (file)
@@ -127,9 +127,6 @@ typedef struct ThreadVars_ {
     /** public counter store: counter syncs update this */
     StatsPublicThreadContext perf_public_ctx;
 
-    /** profile sync needed */
-    uint32_t profile_flag;
-
     /* mutex and condition used by management threads */
 
     SCCtrlMutex *ctrl_mutex;