Go to the documentation of this file.
25 #ifndef __UTIL_PROFILE_H__
26 #define __UTIL_PROFILE_H__
43 #define RULE_PROFILING_START(p) \
44 uint64_t profile_rule_start_ = 0; \
45 uint64_t profile_rule_end_ = 0; \
46 if (profiling_rules_enabled && SCProfileRuleStart((p))) { \
47 if (profiling_rules_entered > 0) { \
48 SCLogError("Re-entered profiling, exiting."); \
51 profiling_rules_entered++; \
52 profile_rule_start_ = UtilCpuGetTicks(); \
55 #define RULE_PROFILING_END(ctx, r, m, p) \
56 if (profiling_rules_enabled && ((p)->flags & PKT_PROFILE)) { \
57 profile_rule_end_ = UtilCpuGetTicks(); \
58 SCProfilingRuleUpdateCounter(ctx, r->profiling_id, \
59 profile_rule_end_ - profile_rule_start_, m); \
60 profiling_rules_entered--; \
66 #define KEYWORD_PROFILING_SET_LIST(ctx, list) { \
67 (ctx)->keyword_perf_list = (list); \
70 #define KEYWORD_PROFILING_START \
71 uint64_t profile_keyword_start_ = 0; \
72 uint64_t profile_keyword_end_ = 0; \
73 if (profiling_keyword_enabled) { \
74 if (profiling_keyword_entered > 0) { \
75 SCLogError("Re-entered profiling, exiting."); \
78 profiling_keyword_entered++; \
79 profile_keyword_start_ = UtilCpuGetTicks(); \
84 #define KEYWORD_PROFILING_END(ctx, type, m) \
85 if (profiling_keyword_enabled && profiling_keyword_entered) { \
86 profile_keyword_end_ = UtilCpuGetTicks(); \
87 SCProfilingKeywordUpdateCounter((ctx),(type),(profile_keyword_end_ - profile_keyword_start_),(m)); \
88 profiling_keyword_entered--; \
93 #define PACKET_PROFILING_START(p) \
94 if (profiling_packets_enabled) { \
95 (p)->profile = SCProfilePacketStart(); \
96 if ((p)->profile != NULL) \
97 (p)->profile->ticks_start = UtilCpuGetTicks(); \
100 #define PACKET_PROFILING_RESTART(p) \
101 if (profiling_packets_enabled) { \
102 if ((p)->profile != NULL) \
103 (p)->profile->ticks_start = UtilCpuGetTicks(); \
106 #define PACKET_PROFILING_END(p) \
107 if (profiling_packets_enabled && (p)->profile != NULL) { \
108 (p)->profile->ticks_end = UtilCpuGetTicks(); \
109 SCProfilingAddPacket((p)); \
112 #ifdef PROFILE_LOCKING
113 #define PACKET_PROFILING_RESET_LOCKS do { \
114 mutex_lock_cnt = 0; \
115 mutex_lock_wait_ticks = 0; \
116 mutex_lock_contention = 0; \
118 spin_lock_wait_ticks = 0; \
119 spin_lock_contention = 0; \
121 rww_lock_wait_ticks = 0; \
122 rww_lock_contention = 0; \
124 rwr_lock_wait_ticks = 0; \
125 rwr_lock_contention = 0; \
130 #define PACKET_PROFILING_COPY_LOCKS(p, id) do { \
131 (p)->profile->tmm[(id)].mutex_lock_cnt = mutex_lock_cnt; \
132 (p)->profile->tmm[(id)].mutex_lock_wait_ticks = mutex_lock_wait_ticks; \
133 (p)->profile->tmm[(id)].mutex_lock_contention = mutex_lock_contention; \
134 (p)->profile->tmm[(id)].spin_lock_cnt = spin_lock_cnt; \
135 (p)->profile->tmm[(id)].spin_lock_wait_ticks = spin_lock_wait_ticks; \
136 (p)->profile->tmm[(id)].spin_lock_contention = spin_lock_contention; \
137 (p)->profile->tmm[(id)].rww_lock_cnt = rww_lock_cnt; \
138 (p)->profile->tmm[(id)].rww_lock_wait_ticks = rww_lock_wait_ticks; \
139 (p)->profile->tmm[(id)].rww_lock_contention = rww_lock_contention; \
140 (p)->profile->tmm[(id)].rwr_lock_cnt = rwr_lock_cnt; \
141 (p)->profile->tmm[(id)].rwr_lock_wait_ticks = rwr_lock_wait_ticks; \
142 (p)->profile->tmm[(id)].rwr_lock_contention = rwr_lock_contention; \
144 SCProfilingAddPacketLocks((p)); \
147 #define PACKET_PROFILING_RESET_LOCKS
148 #define PACKET_PROFILING_COPY_LOCKS(p, id)
151 #define PACKET_PROFILING_TMM_START(p, id) \
152 if (profiling_packets_enabled && (p)->profile != NULL) { \
153 if ((id) < TMM_SIZE) { \
154 (p)->profile->tmm[(id)].ticks_start = UtilCpuGetTicks();\
155 PACKET_PROFILING_RESET_LOCKS; \
159 #define PACKET_PROFILING_TMM_END(p, id) \
160 if (profiling_packets_enabled && (p)->profile != NULL) { \
161 if ((id) < TMM_SIZE) { \
162 PACKET_PROFILING_COPY_LOCKS((p), (id)); \
163 (p)->profile->tmm[(id)].ticks_end = UtilCpuGetTicks(); \
167 #define FLOWWORKER_PROFILING_START(p, id) \
168 if (profiling_packets_enabled && (p)->profile != NULL) { \
169 if ((id) < PROFILE_FLOWWORKER_SIZE) { \
170 (p)->profile->flowworker[(id)].ticks_start = UtilCpuGetTicks();\
174 #define FLOWWORKER_PROFILING_END(p, id) \
175 if (profiling_packets_enabled && (p)->profile != NULL) { \
176 if ((id) < PROFILE_FLOWWORKER_SIZE) { \
177 (p)->profile->flowworker[(id)].ticks_end = UtilCpuGetTicks(); \
181 #define PACKET_PROFILING_RESET(p) \
182 if (profiling_packets_enabled && (p)->profile != NULL) { \
183 SCFree((p)->profile); \
184 (p)->profile = NULL; \
187 #define PACKET_PROFILING_APP_START(dp, id) \
188 if (profiling_packets_enabled) { \
189 (dp)->ticks_start = UtilCpuGetTicks(); \
190 (dp)->alproto = (id); \
193 #define PACKET_PROFILING_APP_END(dp, id) \
194 if (profiling_packets_enabled) { \
195 BUG_ON((id) != (dp)->alproto); \
196 (dp)->ticks_end = UtilCpuGetTicks(); \
197 if ((dp)->ticks_start != 0 && (dp)->ticks_start < ((dp)->ticks_end)) { \
198 (dp)->ticks_spent = ((dp)->ticks_end - (dp)->ticks_start); \
202 #define PACKET_PROFILING_APP_PD_START(dp) \
203 if (profiling_packets_enabled) { \
204 (dp)->proto_detect_ticks_start = UtilCpuGetTicks(); \
207 #define PACKET_PROFILING_APP_PD_END(dp) \
208 if (profiling_packets_enabled) { \
209 (dp)->proto_detect_ticks_end = UtilCpuGetTicks(); \
210 if ((dp)->proto_detect_ticks_start != 0 && (dp)->proto_detect_ticks_start < ((dp)->proto_detect_ticks_end)) { \
211 (dp)->proto_detect_ticks_spent = \
212 ((dp)->proto_detect_ticks_end - (dp)->proto_detect_ticks_start); \
216 #define PACKET_PROFILING_APP_RESET(dp) \
217 if (profiling_packets_enabled) { \
218 (dp)->ticks_start = 0; \
219 (dp)->ticks_end = 0; \
220 (dp)->ticks_spent = 0; \
222 (dp)->proto_detect_ticks_start = 0; \
223 (dp)->proto_detect_ticks_end = 0; \
224 (dp)->proto_detect_ticks_spent = 0; \
227 #define PACKET_PROFILING_APP_STORE(dp, p) \
228 if (profiling_packets_enabled && (p)->profile != NULL) { \
229 if ((dp)->alproto < ALPROTO_MAX) { \
230 (p)->profile->app[(dp)->alproto].ticks_spent += (dp)->ticks_spent; \
231 (p)->profile->proto_detect += (dp)->proto_detect_ticks_spent; \
235 #define PACKET_PROFILING_DETECT_START(p, id) \
236 if (profiling_packets_enabled && (p)->profile != NULL) { \
237 if ((id) < PROF_DETECT_SIZE) { \
238 (p)->profile->detect[(id)].ticks_start = UtilCpuGetTicks(); \
242 #define PACKET_PROFILING_DETECT_END(p, id) \
243 if (profiling_packets_enabled && (p)->profile != NULL) { \
244 if ((id) < PROF_DETECT_SIZE) { \
245 (p)->profile->detect[(id)].ticks_end = UtilCpuGetTicks();\
246 if ((p)->profile->detect[(id)].ticks_start != 0 && \
247 (p)->profile->detect[(id)].ticks_start < (p)->profile->detect[(id)].ticks_end) { \
248 (p)->profile->detect[(id)].ticks_spent += \
249 ((p)->profile->detect[(id)].ticks_end - (p)->profile->detect[(id)].ticks_start); \
254 #define PACKET_PROFILING_LOGGER_START(p, id) \
255 if (profiling_packets_enabled && (p)->profile != NULL) { \
256 if ((id) < LOGGER_SIZE) { \
257 (p)->profile->logger[(id)].ticks_start = UtilCpuGetTicks(); \
261 #define PACKET_PROFILING_LOGGER_END(p, id) \
262 if (profiling_packets_enabled && (p)->profile != NULL) { \
263 if ((id) < LOGGER_SIZE) { \
264 (p)->profile->logger[(id)].ticks_end = UtilCpuGetTicks();\
265 if ((p)->profile->logger[(id)].ticks_start != 0 && \
266 (p)->profile->logger[(id)].ticks_start < (p)->profile->logger[(id)].ticks_end) { \
267 (p)->profile->logger[(id)].ticks_spent += \
268 ((p)->profile->logger[(id)].ticks_end - (p)->profile->logger[(id)].ticks_start); \
273 #define SGH_PROFILING_RECORD(det_ctx, sgh) \
274 if (profiling_sghs_enabled) { \
275 SCProfilingSghUpdateCounter((det_ctx), (sgh)); \
281 #define PREFILTER_PROFILING_START(det_ctx) \
282 (det_ctx)->prefilter_bytes = 0; \
283 (det_ctx)->prefilter_bytes_called = 0; \
284 uint64_t profile_prefilter_start_ = 0; \
285 uint64_t profile_prefilter_end_ = 0; \
286 if (profiling_prefilter_enabled) { \
287 if (profiling_prefilter_entered > 0) { \
288 SCLogError("Re-entered profiling, exiting."); \
291 profiling_prefilter_entered++; \
292 profile_prefilter_start_ = UtilCpuGetTicks(); \
297 #define PREFILTER_PROFILING_END(ctx, profile_id) \
298 if (profiling_prefilter_enabled && profiling_prefilter_entered) { \
299 profile_prefilter_end_ = UtilCpuGetTicks(); \
300 if (profile_prefilter_end_ > profile_prefilter_start_) \
301 SCProfilingPrefilterUpdateCounter((ctx), (profile_id), \
302 (profile_prefilter_end_ - profile_prefilter_start_), (ctx)->prefilter_bytes, \
303 (ctx)->prefilter_bytes_called); \
304 profiling_prefilter_entered--; \
307 #define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes) \
308 (det_ctx)->prefilter_bytes += (bytes); \
309 (det_ctx)->prefilter_bytes_called++
331 uint64_t bytes, uint64_t bytes_called);
349 #define RULE_PROFILING_START(p)
350 #define RULE_PROFILING_END(a,b,c,p)
352 #define KEYWORD_PROFILING_SET_LIST(a,b)
353 #define KEYWORD_PROFILING_START
354 #define KEYWORD_PROFILING_END(a,b,c)
356 #define PACKET_PROFILING_START(p)
357 #define PACKET_PROFILING_RESTART(p)
358 #define PACKET_PROFILING_END(p)
360 #define PACKET_PROFILING_TMM_START(p, id)
361 #define PACKET_PROFILING_TMM_END(p, id)
363 #define PACKET_PROFILING_RESET(p)
365 #define PACKET_PROFILING_APP_START(dp, id)
366 #define PACKET_PROFILING_APP_END(dp, id)
367 #define PACKET_PROFILING_APP_RESET(dp)
368 #define PACKET_PROFILING_APP_STORE(dp, p)
370 #define PACKET_PROFILING_APP_PD_START(dp)
371 #define PACKET_PROFILING_APP_PD_END(dp)
373 #define PACKET_PROFILING_DETECT_START(p, id)
374 #define PACKET_PROFILING_DETECT_END(p, id)
376 #define PACKET_PROFILING_LOGGER_START(p, id)
377 #define PACKET_PROFILING_LOGGER_END(p, id)
379 #define SGH_PROFILING_RECORD(det_ctx, sgh)
381 #define FLOWWORKER_PROFILING_START(p, id)
382 #define FLOWWORKER_PROFILING_END(p, id)
384 #define PREFILTER_PROFILING_START(ctx)
385 #define PREFILTER_PROFILING_END(ctx, profile_id)
386 #define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes)
void SCProfilingRuleUpdateCounter(DetectEngineThreadCtx *, uint16_t, uint64_t, int)
Update a rule counter.
thread_local int profiling_rules_entered
void SCProfilingSghDestroyCtx(DetectEngineCtx *)
void SCProfilingRegisterTests(void)
void SCProfilingInit(void)
Initialize profiling.
Container for matching data for a signature group.
void SCProfilingPrefilterGlobalInit(void)
thread_local int profiling_prefilter_entered
void SCProfilingRulesGlobalInit(void)
main detection engine ctx
PktProfiling * SCProfilePacketStart(void)
void SCProfilingPrefilterThreadCleanup(DetectEngineThreadCtx *)
void SCProfilingKeywordUpdateCounter(DetectEngineThreadCtx *det_ctx, int id, uint64_t ticks, int match)
Update a rule counter.
int SCProfileRuleStart(Packet *p)
int profiling_packets_enabled
void SCProfilingDump(void)
void SCProfilingKeywordThreadSetup(struct SCProfileKeywordDetectCtx_ *, DetectEngineThreadCtx *)
void SCProfilingKeywordInitCounters(DetectEngineCtx *)
Register the keyword profiling counters.
void SCProfilingPrintPacketProfile(Packet *)
void SCProfilingRuleDestroyCtx(struct SCProfileDetectCtx_ *)
thread_local int profiling_keyword_entered
void SCProfilingRuleThreadCleanup(DetectEngineThreadCtx *)
void SCProfilingPrefilterUpdateCounter(DetectEngineThreadCtx *det_ctx, int id, uint64_t ticks, uint64_t bytes, uint64_t bytes_called)
Update a rule counter.
int profiling_keyword_enabled
void SCProfilingPrefilterInitCounters(DetectEngineCtx *)
Register the prefilter profiling counters.
void SCProfilingAddPacket(Packet *)
void SCProfilingKeywordThreadCleanup(DetectEngineThreadCtx *)
void SCProfilingSghUpdateCounter(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh)
Update a rule counter.
void SCProfilingSghsGlobalInit(void)
int profiling_sghs_enabled
void SCProfilingDestroy(void)
Free resources used by profiling.
void SCProfilingKeywordDestroyCtx(DetectEngineCtx *)
void SCProfilingPrefilterDestroyCtx(DetectEngineCtx *)
void SCProfilingSghInitCounters(DetectEngineCtx *)
Register the keyword profiling counters.
void SCProfilingSghThreadSetup(struct SCProfileSghDetectCtx_ *, DetectEngineThreadCtx *)
void SCProfilingSghThreadCleanup(DetectEngineThreadCtx *)
void SCProfilingKeywordsGlobalInit(void)
int profiling_rules_enabled
void SCProfilingRuleInitCounters(DetectEngineCtx *)
Register the rule profiling counters.
void SCProfilingPrefilterThreadSetup(struct SCProfilePrefilterDetectCtx_ *, DetectEngineThreadCtx *)
int profiling_prefilter_enabled
void SCProfilingRuleThreadSetup(struct SCProfileDetectCtx_ *, DetectEngineThreadCtx *)