#include "app-layer-parser.h"
#include "detect-dns-query.h"
+#include "util-profiling.h"
#include "util-unittest-helper.h"
#include "rust.h"
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
BUG_ON(engine->alproto == ALPROTO_UNKNOWN);
if (engine->alproto == alproto && engine->ctx.frame_type == frame->type) {
SCLogDebug("frame %p engine %p", frame, engine);
- PREFILTER_PROFILING_START;
+ PREFILTER_PROFILING_START(det_ctx);
engine->cb.PrefilterFrame(det_ctx, engine->pectx, p, frames, frame, idx);
PREFILTER_PROFILING_END(det_ctx, engine->gid);
}
(void)mpm_table[mpm_ctx->mpm_type].Search(
mpm_ctx, &det_ctx->mtcu, &det_ctx->pmq, data, data_len);
SCLogDebug("det_ctx->pmq.rule_id_array_cnt %u", det_ctx->pmq.rule_id_array_cnt);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
}
}
#include "util-unittest.h"
#include "util-unittest-helper.h"
#include "util-validate.h"
-
+#include "util-profiling.h"
#include "util-mpm-ac.h"
struct StreamMpmData {
(void)mpm_table[smd->mpm_ctx->mpm_type].Search(smd->mpm_ctx,
&smd->det_ctx->mtcs, &smd->det_ctx->pmq,
data, data_len);
+ PREFILTER_PROFILING_ADD_BYTES(smd->det_ctx, data_len);
}
return 0;
}
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtc, &det_ctx->pmq,
p->payload, p->payload_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, p->payload_len);
}
}
}
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtc, &det_ctx->pmq,
p->payload, p->payload_len);
+
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, p->payload_len);
}
int PrefilterPktPayloadRegister(DetectEngineCtx *de_ctx,
}
}
- PREFILTER_PROFILING_START;
+ PREFILTER_PROFILING_START(det_ctx);
engine->cb.PrefilterTx(det_ctx, engine->pectx,
p, p->flow, tx->tx_ptr, tx->tx_id, flow_flags);
PREFILTER_PROFILING_END(det_ctx, engine->gid);
/* run packet engines */
PrefilterEngine *engine = sgh->pkt_engines;
do {
- PREFILTER_PROFILING_START;
+ PREFILTER_PROFILING_START(det_ctx);
engine->cb.Prefilter(det_ctx, p, engine->pectx);
PREFILTER_PROFILING_END(det_ctx, engine->gid);
PACKET_PROFILING_DETECT_START(p, PROF_DETECT_PF_PAYLOAD);
PrefilterEngine *engine = sgh->payload_engines;
while (1) {
- PREFILTER_PROFILING_START;
+ PREFILTER_PROFILING_START(det_ctx);
engine->cb.Prefilter(det_ctx, p, engine->pectx);
PREFILTER_PROFILING_END(det_ctx, engine->gid);
if (data != NULL && data_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq, data, data_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
}
}
if (data != NULL && data_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq, data, data_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
}
}
#include "util-unittest.h"
#include "util-unittest-helper.h"
#include "util-file-decompression.h"
+#include "util-profiling.h"
static int DetectFiledataSetup (DetectEngineCtx *, Signature *, const char *);
#ifdef UNITTESTS
if (buffer->inspect_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(
mpm_ctx, &det_ctx->mtcu, &det_ctx->pmq, buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
}
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_file_id++;
}
#include "util-unittest.h"
#include "util-unittest-helper.h"
+#include "util-profiling.h"
#include "app-layer.h"
#include "app-layer-parser.h"
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_file_id++;
}
#include "util-spm-bm.h"
#include "util-unittest.h"
#include "util-unittest-helper.h"
+#include "util-profiling.h"
#include "app-layer.h"
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_file_id++;
}
#include "app-layer-htp.h"
#include "detect-http-client-body.h"
#include "stream-tcp.h"
+#include "util-profiling.h"
static int DetectHttpClientBodySetup(DetectEngineCtx *, Signature *, const char *);
static int DetectHttpClientBodySetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str);
if (buffer->inspect_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(
mpm_ctx, &det_ctx->mtcu, &det_ctx->pmq, buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
}
-/* Copyright (C) 2007-2021 Open Information Security Foundation
+/* Copyright (C) 2007-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "util-debug.h"
#include "util-print.h"
#include "util-memcmp.h"
+#include "util-profiling.h"
#include "app-layer.h"
#include "app-layer-parser.h"
if (data != NULL && data_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq, data, data_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
}
}
-/* Copyright (C) 2007-2019 Open Information Security Foundation
+/* Copyright (C) 2007-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "flow-util.h"
#include "util-debug.h"
+#include "util-profiling.h"
#include "app-layer.h"
#include "app-layer-parser.h"
if (data != NULL && data_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq, data, data_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
}
}
-/* Copyright (C) 2020 Open Information Security Foundation
+/* Copyright (C) 2020-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "detect-http2.h"
#include "util-byte.h"
#include "rust.h"
+#include "util-profiling.h"
#ifdef UNITTESTS
void DetectHTTP2frameTypeRegisterTests (void);
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
-/* Copyright (C) 2020 Open Information Security Foundation
+/* Copyright (C) 2020-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "util-byte.h"
#include "rust-bindings.h"
+#include "util-profiling.h"
static int DetectIkeVendorSetup(DetectEngineCtx *, Signature *, const char *);
if (buffer->inspect_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(
mpm_ctx, &det_ctx->mtcu, &det_ctx->pmq, buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
}
-/* Copyright (C) 2018 Open Information Security Foundation
+/* Copyright (C) 2018-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "rust.h"
#include "app-layer-krb5.h"
+#include "util-profiling.h"
static int g_krb5_cname_buffer_id = 0;
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
-/* Copyright (C) 2018 Open Information Security Foundation
+/* Copyright (C) 2018-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "rust.h"
#include "app-layer-krb5.h"
+#include "util-profiling.h"
static int g_krb5_sname_buffer_id = 0;
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
-/* Copyright (C) 2020 Open Information Security Foundation
+/* Copyright (C) 2020-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "util-unittest.h"
#include "util-spm.h"
#include "util-print.h"
+#include "util-profiling.h"
static int DetectMQTTSubscribeTopicSetup(DetectEngineCtx *, Signature *, const char *);
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
}
-/* Copyright (C) 2020 Open Information Security Foundation
+/* Copyright (C) 2020-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "util-unittest.h"
#include "util-spm.h"
#include "util-print.h"
+#include "util-profiling.h"
static int DetectMQTTUnsubscribeTopicSetup(DetectEngineCtx *, Signature *, const char *);
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
}
-/* Copyright (C) 2021 Open Information Security Foundation
+/* Copyright (C) 2021-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "detect-quic-cyu-hash.h"
#include "detect-engine-build.h"
#include "rust.h"
+#include "util-profiling.h"
#ifdef UNITTESTS
static void DetectQuicCyuHashRegisterTests(void);
if (buffer->inspect_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(
mpm_ctx, &det_ctx->mtcu, &det_ctx->pmq, buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
-/* Copyright (C) 2021 Open Information Security Foundation
+/* Copyright (C) 2021-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "detect-quic-cyu-string.h"
#include "detect-engine-build.h"
#include "rust.h"
+#include "util-profiling.h"
#ifdef UNITTESTS
static void DetectQuicCyuStringRegisterTests(void);
if (buffer->inspect_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(
mpm_ctx, &det_ctx->mtcu, &det_ctx->pmq, buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
local_id++;
#include "app-layer.h"
#include "app-layer-ssl.h"
+#include "util-profiling.h"
#include "util-unittest.h"
#include "util-unittest-helper.h"
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq,
buffer->inspect, buffer->inspect_len);
+ PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
}
cbdata.local_id++;
struct SCProfilePrefilterData_ *prefilter_perf_data;
int prefilter_perf_size;
+ /** bytes inspected by current prefilter callback call */
+ uint64_t prefilter_bytes;
+ /** number of times we inspected a buffer */
+ uint64_t prefilter_bytes_called;
#endif
} DetectEngineThreadCtx;
-/* Copyright (C) 2007-2017 Open Information Security Foundation
+/* Copyright (C) 2007-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
uint64_t called;
uint64_t total;
uint64_t max;
+ uint64_t total_bytes;
+ uint64_t max_bytes;
+ uint64_t bytes_called; /**< number of times total_bytes was updated. Differs from `called` as a
+ prefilter engine may skip mpm if the smallest pattern is bigger than
+ the buffer to inspect. */
const char *name;
} SCProfilePrefilterData;
fprintf(fp, " ----------------------------------------------"
"------------------------------------------------------"
"----------------------------\n");
- fprintf(fp, " %-32s %-15s %-15s %-15s %-15s\n", "Prefilter", "Ticks", "Called", "Max Ticks", "Avg");
+ fprintf(fp, " %-32s %-15s %-15s %-15s %-15s %-15s %-15s %-15s %-15s %-15s\n", "Prefilter",
+ "Ticks", "Called", "Max Ticks", "Avg", "Bytes", "Called", "Max Bytes", "Avg Bytes",
+ "Ticks/Byte");
fprintf(fp, " -------------------------------- "
"--------------- "
"--------------- "
"--------------- "
"--------------- "
- "\n");
+ "--------------- "
+ "--------------- "
+ "--------------- "
+ "--------------- "
+ "--------------- "
+ "\n");
for (i = 0; i < (int)rules_ctx->size; i++) {
SCProfilePrefilterData *d = &rules_ctx->data[i];
if (d == NULL || d->called== 0)
if (ticks && d->called) {
avgticks = (double)(ticks / d->called);
}
+ double avgbytes = 0;
+ if (d->total_bytes && d->called) {
+ avgbytes = (double)(d->total_bytes / d->bytes_called);
+ }
+ double ticks_per_byte = 0;
+ if (ticks && d->total_bytes) {
+ ticks_per_byte = (double)(ticks / d->total_bytes);
+ }
fprintf(fp,
- " %-32s %-15"PRIu64" %-15"PRIu64" %-15"PRIu64" %-15.2f\n",
- d->name,
- ticks,
- d->called,
- d->max,
- avgticks);
+ " %-32s %-15" PRIu64 " %-15" PRIu64 " %-15" PRIu64 " %-15.2f %-15" PRIu64
+ " %-15" PRIu64 " %-15" PRIu64 " %-15.2f %-15.2f\n",
+ d->name, ticks, d->called, d->max, avgticks, d->total_bytes, d->bytes_called,
+ d->max_bytes, avgbytes, ticks_per_byte);
}
}
* \param ticks Number of CPU ticks for this rule.
* \param match Did the rule match?
*/
-void
-SCProfilingPrefilterUpdateCounter(DetectEngineThreadCtx *det_ctx, int id, uint64_t ticks)
+void SCProfilingPrefilterUpdateCounter(DetectEngineThreadCtx *det_ctx, int id, uint64_t ticks,
+ uint64_t bytes, uint64_t bytes_called)
{
if (det_ctx != NULL && det_ctx->prefilter_perf_data != NULL &&
id < (int)det_ctx->de_ctx->prefilter_id)
if (ticks > p->max)
p->max = ticks;
p->total += ticks;
+
+ p->bytes_called += bytes_called;
+ if (bytes > p->max_bytes)
+ p->max_bytes = bytes;
+ p->total_bytes += bytes;
}
}
de_ctx->profile_prefilter_ctx->data[i].total += det_ctx->prefilter_perf_data[i].total;
if (det_ctx->prefilter_perf_data[i].max > de_ctx->profile_prefilter_ctx->data[i].max)
de_ctx->profile_prefilter_ctx->data[i].max = det_ctx->prefilter_perf_data[i].max;
+ de_ctx->profile_prefilter_ctx->data[i].total_bytes +=
+ det_ctx->prefilter_perf_data[i].total_bytes;
+ if (det_ctx->prefilter_perf_data[i].max_bytes >
+ de_ctx->profile_prefilter_ctx->data[i].max_bytes)
+ de_ctx->profile_prefilter_ctx->data[i].max_bytes =
+ det_ctx->prefilter_perf_data[i].max_bytes;
+ de_ctx->profile_prefilter_ctx->data[i].bytes_called +=
+ det_ctx->prefilter_perf_data[i].bytes_called;
}
}
extern int profiling_prefilter_enabled;
extern thread_local int profiling_prefilter_entered;
-#define PREFILTER_PROFILING_START \
- uint64_t profile_prefilter_start_ = 0; \
- uint64_t profile_prefilter_end_ = 0; \
- if (profiling_prefilter_enabled) { \
- if (profiling_prefilter_entered > 0) { \
- SCLogError(SC_ERR_FATAL, "Re-entered profiling, exiting."); \
- abort(); \
- } \
- profiling_prefilter_entered++; \
- profile_prefilter_start_ = UtilCpuGetTicks(); \
+#define PREFILTER_PROFILING_START(det_ctx) \
+ (det_ctx)->prefilter_bytes = 0; \
+ (det_ctx)->prefilter_bytes_called = 0; \
+ uint64_t profile_prefilter_start_ = 0; \
+ uint64_t profile_prefilter_end_ = 0; \
+ if (profiling_prefilter_enabled) { \
+ if (profiling_prefilter_entered > 0) { \
+ SCLogError(SC_ERR_FATAL, "Re-entered profiling, exiting."); \
+ abort(); \
+ } \
+ profiling_prefilter_entered++; \
+ profile_prefilter_start_ = UtilCpuGetTicks(); \
}
/* we allow this macro to be called if profiling_prefilter_entered == 0,
* so that we don't have to refactor some of the detection code. */
-#define PREFILTER_PROFILING_END(ctx, profile_id) \
- if (profiling_prefilter_enabled && profiling_prefilter_entered) { \
- profile_prefilter_end_ = UtilCpuGetTicks(); \
- if (profile_prefilter_end_ > profile_prefilter_start_) \
- SCProfilingPrefilterUpdateCounter((ctx),(profile_id),(profile_prefilter_end_ - profile_prefilter_start_)); \
- profiling_prefilter_entered--; \
+#define PREFILTER_PROFILING_END(ctx, profile_id) \
+ if (profiling_prefilter_enabled && profiling_prefilter_entered) { \
+ profile_prefilter_end_ = UtilCpuGetTicks(); \
+ if (profile_prefilter_end_ > profile_prefilter_start_) \
+ SCProfilingPrefilterUpdateCounter((ctx), (profile_id), \
+ (profile_prefilter_end_ - profile_prefilter_start_), (ctx)->prefilter_bytes, \
+ (ctx)->prefilter_bytes_called); \
+ profiling_prefilter_entered--; \
}
+#define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes) \
+ (det_ctx)->prefilter_bytes += (bytes); \
+ (det_ctx)->prefilter_bytes_called++
+
void SCProfilingRulesGlobalInit(void);
void SCProfilingRuleDestroyCtx(struct SCProfileDetectCtx_ *);
void SCProfilingRuleInitCounters(DetectEngineCtx *);
void SCProfilingPrefilterGlobalInit(void);
void SCProfilingPrefilterDestroyCtx(DetectEngineCtx *);
void SCProfilingPrefilterInitCounters(DetectEngineCtx *);
-void SCProfilingPrefilterUpdateCounter(DetectEngineThreadCtx *det_ctx, int id, uint64_t ticks);
+void SCProfilingPrefilterUpdateCounter(DetectEngineThreadCtx *det_ctx, int id, uint64_t ticks,
+ uint64_t bytes, uint64_t bytes_called);
void SCProfilingPrefilterThreadSetup(struct SCProfilePrefilterDetectCtx_ *, DetectEngineThreadCtx *);
void SCProfilingPrefilterThreadCleanup(DetectEngineThreadCtx *);
#define FLOWWORKER_PROFILING_START(p, id)
#define FLOWWORKER_PROFILING_END(p, id)
-#define PREFILTER_PROFILING_START
+#define PREFILTER_PROFILING_START(ctx)
#define PREFILTER_PROFILING_END(ctx, profile_id)
+#define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes)
#endif /* PROFILING */