/* 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;
/* 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;
}
/* 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;
}
/** 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;
#include "util-signal.h"
#include "util-buffer.h"
#include "util-path.h"
+#include "util-profiling.h"
#if (defined BUILD_UNIX_SOCKET) && (defined HAVE_SYS_UN_H) && (defined HAVE_SYS_STAT_H) && (defined HAVE_SYS_TYPES_H)
#include <sys/un.h>
SCReturnInt(retval);
}
+#ifdef PROFILE_RULES
+static TmEcode UnixManagerRulesetProfileCommand(json_t *cmd, json_t *server_msg, void *data)
+{
+ SCEnter();
+ TmEcode retval;
+ DetectEngineCtx *de_ctx = DetectEngineGetCurrent();
+
+ retval = SCProfileRuleTriggerDump(de_ctx);
+ json_object_set_new(server_msg, "message", json_string("OK"));
+ SCReturnInt(retval);
+}
+#endif
+
static TmEcode UnixManagerShowFailedRules(json_t *cmd,
json_t *server_msg, void *data)
{
UnixManagerRegisterCommand("ruleset-reload-time", UnixManagerReloadTimeCommand, NULL, 0);
UnixManagerRegisterCommand("ruleset-stats", UnixManagerRulesetStatsCommand, NULL, 0);
UnixManagerRegisterCommand("ruleset-failed-rules", UnixManagerShowFailedRules, NULL, 0);
+#ifdef PROFILE_RULES
+ UnixManagerRegisterCommand("ruleset-profile", UnixManagerRulesetProfileCommand, NULL, 0);
+#endif
UnixManagerRegisterCommand("register-tenant-handler", UnixSocketRegisterTenantHandler, &command, UNIX_CMD_TAKE_ARGS);
UnixManagerRegisterCommand("unregister-tenant-handler", UnixSocketUnregisterTenantHandler, &command, UNIX_CMD_TAKE_ARGS);
UnixManagerRegisterCommand("register-tenant", UnixSocketRegisterTenant, &command, UNIX_CMD_TAKE_ARGS);
}
}
-static void SCProfilingRuleThreadMerge(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx)
+static void SCProfilingRuleThreadMerge(
+ DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, int reset)
{
if (de_ctx == NULL || de_ctx->profile_ctx == NULL || de_ctx->profile_ctx->data == NULL ||
- det_ctx == NULL || det_ctx->rule_perf_data == NULL)
+ det_ctx == NULL || det_ctx->rule_perf_data == NULL)
return;
int i;
de_ctx->profile_ctx->data[i].matches += det_ctx->rule_perf_data[i].matches;
de_ctx->profile_ctx->data[i].ticks_match += det_ctx->rule_perf_data[i].ticks_match;
de_ctx->profile_ctx->data[i].ticks_no_match += det_ctx->rule_perf_data[i].ticks_no_match;
+ if (reset) {
+ det_ctx->rule_perf_data[i].checks = 0;
+ det_ctx->rule_perf_data[i].matches = 0;
+ det_ctx->rule_perf_data[i].ticks_match = 0;
+ det_ctx->rule_perf_data[i].ticks_no_match = 0;
+ }
if (det_ctx->rule_perf_data[i].max > de_ctx->profile_ctx->data[i].max)
de_ctx->profile_ctx->data[i].max = det_ctx->rule_perf_data[i].max;
}
return;
pthread_mutex_lock(&det_ctx->de_ctx->profile_ctx->data_m);
- SCProfilingRuleThreadMerge(det_ctx->de_ctx, det_ctx);
+ SCProfilingRuleThreadMerge(det_ctx->de_ctx, det_ctx, 0);
pthread_mutex_unlock(&det_ctx->de_ctx->profile_ctx->data_m);
SCFree(det_ctx->rule_perf_data);
det_ctx->rule_perf_data_size = 0;
}
+void SCProfilingRuleThreatAggregate(DetectEngineThreadCtx *det_ctx)
+{
+
+ if (det_ctx == NULL || det_ctx->de_ctx == NULL || det_ctx->de_ctx->profile_ctx == NULL)
+ return;
+ pthread_mutex_lock(&det_ctx->de_ctx->profile_ctx->data_m);
+ SCProfilingRuleThreadMerge(det_ctx->de_ctx, det_ctx, 1);
+ pthread_mutex_unlock(&det_ctx->de_ctx->profile_ctx->data_m);
+}
+
/**
* \brief Register the rule profiling counters.
*
SCLogPerf("Registered %"PRIu32" rule profiling counters.", count);
}
+int SCProfileRuleTriggerDump(DetectEngineCtx *de_ctx)
+{
+ SCProfilingRuleDump(de_ctx->profile_ctx);
+ return TM_ECODE_OK;
+}
+
#endif /* PROFILING */