From: Victor Julien Date: Thu, 26 Sep 2013 16:34:36 +0000 (+0200) Subject: counters: consolidate counters after all ThreadInit functions of a thread have run... X-Git-Tag: suricata-2.0beta2~314 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8080494e9acdff9c82884be182c525aebde2570f;p=thirdparty%2Fsuricata.git counters: consolidate counters after all ThreadInit functions of a thread have run. This prevents duplicate and overwriting memory allocations. --- diff --git a/src/decode.c b/src/decode.c index b0471e3d9f..1185c94e70 100644 --- a/src/decode.c +++ b/src/decode.c @@ -394,9 +394,6 @@ void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv) SCPerfTVRegisterCounter("defrag.max_frag_hits", tv, SC_PERF_TYPE_UINT64, "NULL"); - tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); - SCPerfAddToClubbedTMTable(tv->name, &tv->sc_perf_pctx); - return; } diff --git a/src/detect-engine.c b/src/detect-engine.c index 70340d82e5..313e0dbe91 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -1225,9 +1225,6 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data) /** alert counter setup */ det_ctx->counter_alerts = SCPerfTVRegisterCounter("detect.alert", tv, SC_PERF_TYPE_UINT64, "NULL"); - tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); - SCPerfAddToClubbedTMTable((tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name, - &tv->sc_perf_pctx); /* pass thread data back to caller */ *data = (void *)det_ctx; diff --git a/src/detect.c b/src/detect.c index 143e5eae9e..b344e42128 100644 --- a/src/detect.c +++ b/src/detect.c @@ -10482,6 +10482,10 @@ static int SigTestDetectAlertCounter(void) tv.name = "detect_test"; DetectEngineThreadCtxInit(&tv, de_ctx, (void *)&det_ctx); + /* init counters */ + tv.sc_perf_pca = SCPerfGetAllCountersArray(&tv.sc_perf_pctx); + SCPerfAddToClubbedTMTable((tv.thread_group_name != NULL) ? + tv.thread_group_name : tv.name, &tv.sc_perf_pctx); p = UTHBuildPacket((uint8_t *)"boo", strlen("boo"), IPPROTO_TCP); Detect(&tv, p, det_ctx, NULL, NULL); diff --git a/src/source-mpipe.c b/src/source-mpipe.c index e343b2edf4..14af9bfdbf 100644 --- a/src/source-mpipe.c +++ b/src/source-mpipe.c @@ -428,8 +428,6 @@ static void MpipeRegisterPerfCounters(MpipeThreadVars *ptv, ThreadVars *tv) ptv->counter_no_buffers_7 = SCPerfTVRegisterCounter("mpipe.no_buf7", tv, SC_PERF_TYPE_UINT64, "NULL"); - tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); - SCPerfAddToClubbedTMTable(tv->name, &tv->sc_perf_pctx); } static const gxio_mpipe_buffer_size_enum_t gxio_buffer_sizes[] = { diff --git a/src/stream-tcp.c b/src/stream-tcp.c index c3551b2adf..12d23f2830 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -4526,9 +4526,6 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data) SC_PERF_TYPE_UINT64, "NULL"); - tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); - SCPerfAddToClubbedTMTable(tv->name, &tv->sc_perf_pctx); - SCLogDebug("StreamTcp thread specific ctx online at %p, reassembly ctx %p", stt, stt->ra_ctx); diff --git a/src/tm-threads.c b/src/tm-threads.c index cc783e056d..0bc8fe4f52 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -157,6 +157,10 @@ void *TmThreadsSlot1NoIn(void *td) memset(&s->slot_pre_pq, 0, sizeof(PacketQueue)); memset(&s->slot_post_pq, 0, sizeof(PacketQueue)); + tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); + SCPerfAddToClubbedTMTable((tv->thread_group_name != NULL) ? + tv->thread_group_name : tv->name, &tv->sc_perf_pctx); + TmThreadsSetFlag(tv, THV_INIT_DONE); while (run) { @@ -263,6 +267,10 @@ void *TmThreadsSlot1NoOut(void *td) memset(&s->slot_pre_pq, 0, sizeof(PacketQueue)); memset(&s->slot_post_pq, 0, sizeof(PacketQueue)); + tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); + SCPerfAddToClubbedTMTable((tv->thread_group_name != NULL) ? + tv->thread_group_name : tv->name, &tv->sc_perf_pctx); + TmThreadsSetFlag(tv, THV_INIT_DONE); while (run) { @@ -352,6 +360,10 @@ void *TmThreadsSlot1NoInOut(void *td) memset(&s->slot_pre_pq, 0, sizeof(PacketQueue)); memset(&s->slot_post_pq, 0, sizeof(PacketQueue)); + tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); + SCPerfAddToClubbedTMTable((tv->thread_group_name != NULL) ? + tv->thread_group_name : tv->name, &tv->sc_perf_pctx); + TmThreadsSetFlag(tv, THV_INIT_DONE); while (run) { @@ -438,7 +450,12 @@ void *TmThreadsSlot1(void *td) memset(&s->slot_post_pq, 0, sizeof(PacketQueue)); SCMutexInit(&s->slot_post_pq.mutex_q, NULL); + tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); + SCPerfAddToClubbedTMTable((tv->thread_group_name != NULL) ? + tv->thread_group_name : tv->name, &tv->sc_perf_pctx); + TmThreadsSetFlag(tv, THV_INIT_DONE); + while (run) { if (TmThreadsCheckFlag(tv, THV_PAUSE)) { TmThreadsSetFlag(tv, THV_PAUSED); @@ -670,6 +687,10 @@ void *TmThreadsSlotPktAcqLoop(void *td) { SCMutexInit(&slot->slot_post_pq.mutex_q, NULL); } + tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); + SCPerfAddToClubbedTMTable((tv->thread_group_name != NULL) ? + tv->thread_group_name : tv->name, &tv->sc_perf_pctx); + TmThreadsSetFlag(tv, THV_INIT_DONE); while(run) { @@ -770,6 +791,10 @@ void *TmThreadsSlotVar(void *td) SCMutexInit(&s->slot_post_pq.mutex_q, NULL); } + tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx); + SCPerfAddToClubbedTMTable((tv->thread_group_name != NULL) ? + tv->thread_group_name : tv->name, &tv->sc_perf_pctx); + TmThreadsSetFlag(tv, THV_INIT_DONE); s = (TmSlot *)tv->tm_slots;