#define PKT_IS_FRAGMENT (1<<19) /**< Packet is a fragment */
#define PKT_IS_INVALID (1<<20)
+#define PKT_PROFILE (1<<21)
/** \brief return 1 if the packet is a pseudo packet */
#define PKT_IS_PSEUDOPKT(p) ((p)->flags & PKT_PSEUDO_STREAM_END)
inspect_flags = 0;
match = 0;
- RULE_PROFILING_START;
+ RULE_PROFILING_START(p);
if (alproto_supports_txs) {
FLOWLOCK_WRLOCK(f);
htp_state = (HtpState *)alstate;
if (htp_state->conn == NULL) {
FLOWLOCK_UNLOCK(f);
- RULE_PROFILING_END(det_ctx, s, match);
+ RULE_PROFILING_END(det_ctx, s, match, p);
goto end;
}
}
inspect_tx = AppLayerParserGetTx(f->proto, alproto, alstate, inspect_tx_id);
if (inspect_tx == NULL) {
FLOWLOCK_UNLOCK(f);
- RULE_PROFILING_END(det_ctx, s, match);
+ RULE_PROFILING_END(det_ctx, s, match, p);
goto end;
}
while (engine != NULL) {
inspect_flags |= DE_STATE_FLAG_SIG_CANT_MATCH;
}
}
- RULE_PROFILING_END(det_ctx, s, match);
+ RULE_PROFILING_END(det_ctx, s, match, p);
if (s->sm_lists[DETECT_SM_LIST_AMATCH] != NULL) {
if (sm == NULL || inspect_flags & DE_STATE_FLAG_SIG_CANT_MATCH) {
PACKET_PROFILING_DETECT_START(p, PROF_DETECT_RULES);
/* inspect the sigs against the packet */
for (idx = 0; idx < det_ctx->match_array_cnt; idx++) {
- RULE_PROFILING_START;
+ RULE_PROFILING_START(p);
state_alert = 0;
#ifdef PROFILING
smatch = 0;
DetectFlowvarProcessList(det_ctx, pflow);
DetectReplaceFree(det_ctx->replist);
det_ctx->replist = NULL;
- RULE_PROFILING_END(det_ctx, s, smatch);
+ RULE_PROFILING_END(det_ctx, s, smatch, p);
det_ctx->flags = 0;
continue;
return NULL;
}
+/* see if we want to profile rules for this packet */
+int SCProfileRuleStart(Packet *p) {
+#ifdef PROFILE_LOCKING
+ if (p->profile != NULL) {
+ p->flags |= PKT_PROFILE;
+ return 1;
+ }
+#else
+ uint64_t sample = SC_ATOMIC_ADD(samples, 1);
+ if (sample % rate == 0) {
+ p->flags |= PKT_PROFILE;
+ return 1;
+ }
+#endif
+ return 0;
+}
+
#define CASE_CODE(E) case E: return #E
/**
void SCProfilingPrintPacketProfile(Packet *);
void SCProfilingAddPacket(Packet *);
+int SCProfileRuleStart(Packet *p);
-#define RULE_PROFILING_START \
+#define RULE_PROFILING_START(p) \
uint64_t profile_rule_start_ = 0; \
uint64_t profile_rule_end_ = 0; \
- if (profiling_rules_enabled) { \
+ if (profiling_rules_enabled && SCProfileRuleStart((p))) { \
if (profiling_rules_entered > 0) { \
SCLogError(SC_ERR_FATAL, "Re-entered profiling, exiting."); \
exit(1); \
profile_rule_start_ = UtilCpuGetTicks(); \
}
-#define RULE_PROFILING_END(ctx, r, m) \
- if (profiling_rules_enabled) { \
+#define RULE_PROFILING_END(ctx, r, m, p) \
+ if (profiling_rules_enabled && ((p)->flags & PKT_PROFILE)) { \
profile_rule_end_ = UtilCpuGetTicks(); \
SCProfilingRuleUpdateCounter(ctx, r->profiling_id, \
profile_rule_end_ - profile_rule_start_, m); \
#else
-#define RULE_PROFILING_START
-#define RULE_PROFILING_END(a,b,c)
+#define RULE_PROFILING_START(p)
+#define RULE_PROFILING_END(a,b,c,p)
#define KEYWORD_PROFILING_SET_LIST(a,b)
#define KEYWORD_PROFILING_START