]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
profiling: support log api
authorVictor Julien <victor@inliniac.net>
Tue, 4 Feb 2014 10:34:21 +0000 (11:34 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 4 Feb 2014 12:42:21 +0000 (13:42 +0100)
The log API calls thread modules directly, so the TMM profiling logic
can be applied to it. This patch does so.

The "Thread Module" out now again lists the individual loggers. As the
module are normally called much less frequently the numbers are hard to
compare to pre-log-api numbers.

src/output-file.c
src/output-filedata.c
src/output-packet.c
src/output-tx.c

index c8c2178d3058c2fb3d6807493c8c6852d6ca83db..f6283d70a11f53eb0ccf0ef3ac2c14e63971cb3e 100644 (file)
@@ -29,6 +29,7 @@
 #include "app-layer.h"
 #include "app-layer-parser.h"
 #include "detect-filemagic.h"
+#include "util-profiling.h"
 
 typedef struct OutputLoggerThreadStore_ {
     void *thread_data;
@@ -49,12 +50,17 @@ typedef struct OutputFileLogger_ {
     OutputCtx *output_ctx;
     struct OutputFileLogger_ *next;
     const char *name;
+    TmmId module_id;
 } OutputFileLogger;
 
 static OutputFileLogger *list = NULL;
 
 int OutputRegisterFileLogger(const char *name, FileLogger LogFunc, OutputCtx *output_ctx)
 {
+    int module_id = TmModuleGetIdByName(name);
+    if (module_id < 0)
+        return -1;
+
     OutputFileLogger *op = SCMalloc(sizeof(*op));
     if (op == NULL)
         return -1;
@@ -63,6 +69,7 @@ int OutputRegisterFileLogger(const char *name, FileLogger LogFunc, OutputCtx *ou
     op->LogFunc = LogFunc;
     op->output_ctx = output_ctx;
     op->name = name;
+    op->module_id = (TmmId) module_id;
 
     if (list == NULL)
         list = op;
@@ -141,7 +148,9 @@ static TmEcode OutputFileLog(ThreadVars *tv, Packet *p, void *thread_data, Packe
                     BUG_ON(logger->LogFunc == NULL);
 
                     SCLogDebug("logger %p", logger);
+                    PACKET_PROFILING_TMM_START(p, logger->module_id);
                     logger->LogFunc(tv, store->thread_data, (const Packet *)p, (const File *)ff);
+                    PACKET_PROFILING_TMM_END(p, logger->module_id);
                     file_logged = 1;
 
                     logger = logger->next;
index 65c5ce6e65cbf4be3b25ca1cb12bc2cea9ed582a..d0770cfa57ee8d3af726452d51ebf53bd21b2eef 100644 (file)
@@ -30,6 +30,7 @@
 #include "app-layer-parser.h"
 #include "detect-filemagic.h"
 #include "conf.h"
+#include "util-profiling.h"
 
 typedef struct OutputLoggerThreadStore_ {
     void *thread_data;
@@ -50,6 +51,7 @@ typedef struct OutputFiledataLogger_ {
     OutputCtx *output_ctx;
     struct OutputFiledataLogger_ *next;
     const char *name;
+    TmmId module_id;
 } OutputFiledataLogger;
 
 static OutputFiledataLogger *list = NULL;
@@ -60,6 +62,10 @@ static int g_waldo_deinit = 0;
 
 int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, OutputCtx *output_ctx)
 {
+    int module_id = TmModuleGetIdByName(name);
+    if (module_id < 0)
+        return -1;
+
     OutputFiledataLogger *op = SCMalloc(sizeof(*op));
     if (op == NULL)
         return -1;
@@ -68,6 +74,7 @@ int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, Outpu
     op->LogFunc = LogFunc;
     op->output_ctx = output_ctx;
     op->name = name;
+    op->module_id = (TmmId) module_id;
 
     if (list == NULL)
         list = op;
@@ -187,8 +194,10 @@ static TmEcode OutputFiledataLog(ThreadVars *tv, Packet *p, void *thread_data, P
                     BUG_ON(logger->LogFunc == NULL);
 
                     SCLogDebug("logger %p", logger);
+                    PACKET_PROFILING_TMM_START(p, logger->module_id);
                     logger->LogFunc(tv, store->thread_data, (const Packet *)p, (const File *)ff,
                             (const FileData *)write_ffd, flags);
+                    PACKET_PROFILING_TMM_END(p, logger->module_id);
                     file_logged = 1;
 
                     logger = logger->next;
index fcc073043ced8e5d251fd4bba5d328f4d5ba1d25..6f9ddde55afa9971bf2e6f3d6ac099bc217f34da 100644 (file)
@@ -26,6 +26,7 @@
 #include "suricata-common.h"
 #include "tm-modules.h"
 #include "output-packet.h"
+#include "util-profiling.h"
 
 typedef struct OutputLoggerThreadStore_ {
     void *thread_data;
@@ -47,11 +48,16 @@ typedef struct OutputPacketLogger_ {
     OutputCtx *output_ctx;
     struct OutputPacketLogger_ *next;
     const char *name;
+    TmmId module_id;
 } OutputPacketLogger;
 
 static OutputPacketLogger *list = NULL;
 
 int OutputRegisterPacketLogger(const char *name, PacketLogger LogFunc, PacketLogCondition ConditionFunc, OutputCtx *output_ctx) {
+    int module_id = TmModuleGetIdByName(name);
+    if (module_id < 0)
+        return -1;
+
     OutputPacketLogger *op = SCMalloc(sizeof(*op));
     if (op == NULL)
         return -1;
@@ -61,6 +67,7 @@ int OutputRegisterPacketLogger(const char *name, PacketLogger LogFunc, PacketLog
     op->ConditionFunc = ConditionFunc;
     op->output_ctx = output_ctx;
     op->name = name;
+    op->module_id = (TmmId) module_id;
 
     if (list == NULL)
         list = op;
@@ -91,7 +98,9 @@ static TmEcode OutputPacketLog(ThreadVars *tv, Packet *p, void *thread_data, Pac
         BUG_ON(logger->LogFunc == NULL || logger->ConditionFunc == NULL);
 
         if ((logger->ConditionFunc(tv, (const Packet *)p)) == TRUE) {
+            PACKET_PROFILING_TMM_START(p, logger->module_id);
             logger->LogFunc(tv, store->thread_data, (const Packet *)p);
+            PACKET_PROFILING_TMM_END(p, logger->module_id);
         }
 
         logger = logger->next;
index 7c56353a06e335287ba74490a8d219d6f4033254..f6e5235439f45a794170887aac0ef009f5838c30 100644 (file)
@@ -28,6 +28,7 @@
 #include "output-tx.h"
 #include "app-layer.h"
 #include "app-layer-parser.h"
+#include "util-profiling.h"
 
 typedef struct OutputLoggerThreadStore_ {
     void *thread_data;
@@ -49,12 +50,17 @@ typedef struct OutputTxLogger_ {
     OutputCtx *output_ctx;
     struct OutputTxLogger_ *next;
     const char *name;
+    TmmId module_id;
 } OutputTxLogger;
 
 static OutputTxLogger *list = NULL;
 
 int OutputRegisterTxLogger(const char *name, AppProto alproto, TxLogger LogFunc, OutputCtx *output_ctx)
 {
+    int module_id = TmModuleGetIdByName(name);
+    if (module_id < 0)
+        return -1;
+
     OutputTxLogger *op = SCMalloc(sizeof(*op));
     if (op == NULL)
         return -1;
@@ -64,6 +70,7 @@ int OutputRegisterTxLogger(const char *name, AppProto alproto, TxLogger LogFunc,
     op->LogFunc = LogFunc;
     op->output_ctx = output_ctx;
     op->name = name;
+    op->module_id = (TmmId) module_id;
 
     if (list == NULL)
         list = op;
@@ -149,7 +156,9 @@ static TmEcode OutputTxLog(ThreadVars *tv, Packet *p, void *thread_data, PacketQ
             SCLogDebug("logger %p", logger);
             if (logger->alproto == alproto) {
                 SCLogDebug("alproto match, logging tx_id %ju", tx_id);
+                PACKET_PROFILING_TMM_START(p, logger->module_id);
                 logger->LogFunc(tv, store->thread_data, p, f, alstate, tx, tx_id);
+                PACKET_PROFILING_TMM_END(p, logger->module_id);
                 proto_logged = 1;
             }