profiling: fix keyword profiling

pull/2559/head
Victor Julien 9 years ago
parent a1465bc4fa
commit a9a228a289

@ -696,7 +696,7 @@ typedef struct DetectEngineCtx_ {
#ifdef PROFILING #ifdef PROFILING
struct SCProfileDetectCtx_ *profile_ctx; struct SCProfileDetectCtx_ *profile_ctx;
struct SCProfileKeywordDetectCtx_ *profile_keyword_ctx; struct SCProfileKeywordDetectCtx_ *profile_keyword_ctx;
struct SCProfileKeywordDetectCtx_ *profile_keyword_ctx_per_list[DETECT_SM_LIST_MAX]; struct SCProfileKeywordDetectCtx_ **profile_keyword_ctx_per_list;
struct SCProfileSghDetectCtx_ *profile_sgh_ctx; struct SCProfileSghDetectCtx_ *profile_sgh_ctx;
uint32_t profile_match_logging_threshold; uint32_t profile_match_logging_threshold;
#endif #endif
@ -913,7 +913,7 @@ typedef struct DetectEngineThreadCtx_ {
struct SCProfileData_ *rule_perf_data; struct SCProfileData_ *rule_perf_data;
int rule_perf_data_size; int rule_perf_data_size;
struct SCProfileKeywordData_ *keyword_perf_data; struct SCProfileKeywordData_ *keyword_perf_data;
struct SCProfileKeywordData_ *keyword_perf_data_per_list[DETECT_SM_LIST_MAX]; struct SCProfileKeywordData_ **keyword_perf_data_per_list;
int keyword_perf_list; /**< list we're currently inspecting, DETECT_SM_LIST_* */ int keyword_perf_list; /**< list we're currently inspecting, DETECT_SM_LIST_* */
struct SCProfileSghData_ *sgh_perf_data; struct SCProfileSghData_ *sgh_perf_data;
#endif #endif

@ -159,6 +159,7 @@ SCProfilingKeywordDump(DetectEngineCtx *de_ctx)
if (profiling_keyword_enabled == 0) if (profiling_keyword_enabled == 0)
return; return;
const int nlists = DetectBufferTypeMaxId();
gettimeofday(&tval, NULL); gettimeofday(&tval, NULL);
tms = SCLocalTime(tval.tv_sec, &local_tm); tms = SCLocalTime(tval.tv_sec, &local_tm);
@ -186,16 +187,23 @@ SCProfilingKeywordDump(DetectEngineCtx *de_ctx)
/* global stats first */ /* global stats first */
DoDump(de_ctx->profile_keyword_ctx, fp, "total"); DoDump(de_ctx->profile_keyword_ctx, fp, "total");
/* per buffer stats next, but only if there are stats to print */ /* per buffer stats next, but only if there are stats to print */
for (i = 0; i < DETECT_SM_LIST_MAX; i++) { for (i = 0; i < nlists; i++) {
int j; int j;
uint64_t checks = 0; uint64_t checks = 0;
for (j = 0; j < DETECT_TBLSIZE; j++) { for (j = 0; j < DETECT_TBLSIZE; j++) {
checks += de_ctx->profile_keyword_ctx_per_list[i]->data[j].checks; checks += de_ctx->profile_keyword_ctx_per_list[i]->data[j].checks;
} }
if (checks) if (checks) {
DoDump(de_ctx->profile_keyword_ctx_per_list[i], fp, const char *name = NULL;
DetectSigmatchListEnumToString(i)); if (i < DETECT_SM_LIST_DYNAMIC_START) {
name = DetectSigmatchListEnumToString(i);
} else {
name = DetectBufferTypeGetNameById(i);
}
DoDump(de_ctx->profile_keyword_ctx_per_list[i], fp, name);
}
} }
fprintf(fp,"\n"); fprintf(fp,"\n");
@ -228,7 +236,7 @@ SCProfilingKeywordUpdateCounter(DetectEngineThreadCtx *det_ctx, int id, uint64_t
p->ticks_no_match += ticks; p->ticks_no_match += ticks;
/* store per list (buffer type) as well */ /* store per list (buffer type) as well */
if (det_ctx->keyword_perf_list >= 0 && det_ctx->keyword_perf_list < DETECT_SM_LIST_MAX) { if (det_ctx->keyword_perf_list >= 0) {// && det_ctx->keyword_perf_list < DETECT_SM_LIST_MAX) {
p = &det_ctx->keyword_perf_data_per_list[det_ctx->keyword_perf_list][id]; p = &det_ctx->keyword_perf_data_per_list[det_ctx->keyword_perf_list][id];
p->checks++; p->checks++;
p->matches += match; p->matches += match;
@ -274,10 +282,13 @@ void SCProfilingKeywordDestroyCtx(DetectEngineCtx *de_ctx)
SCProfilingKeywordDump(de_ctx); SCProfilingKeywordDump(de_ctx);
DetroyCtx(de_ctx->profile_keyword_ctx); DetroyCtx(de_ctx->profile_keyword_ctx);
const int nlists = DetectBufferTypeMaxId();
int i; int i;
for (i = 0; i < DETECT_SM_LIST_MAX; i++) { for (i = 0; i < nlists; i++) {
DetroyCtx(de_ctx->profile_keyword_ctx_per_list[i]); DetroyCtx(de_ctx->profile_keyword_ctx_per_list[i]);
} }
SCFree(de_ctx->profile_keyword_ctx_per_list);
} }
} }
@ -292,8 +303,12 @@ void SCProfilingKeywordThreadSetup(SCProfileKeywordDetectCtx *ctx, DetectEngineT
det_ctx->keyword_perf_data = a; det_ctx->keyword_perf_data = a;
} }
const int nlists = DetectBufferTypeMaxId();
det_ctx->keyword_perf_data_per_list = SCCalloc(nlists, sizeof(SCProfileKeywordData *));
BUG_ON(det_ctx->keyword_perf_data_per_list == NULL);
int i; int i;
for (i = 0; i < DETECT_SM_LIST_MAX; i++) { for (i = 0; i < nlists; i++) {
SCProfileKeywordData *b = SCMalloc(sizeof(SCProfileKeywordData) * DETECT_TBLSIZE); SCProfileKeywordData *b = SCMalloc(sizeof(SCProfileKeywordData) * DETECT_TBLSIZE);
if (b != NULL) { if (b != NULL) {
memset(b, 0x00, sizeof(SCProfileKeywordData) * DETECT_TBLSIZE); memset(b, 0x00, sizeof(SCProfileKeywordData) * DETECT_TBLSIZE);
@ -320,8 +335,9 @@ static void SCProfilingKeywordThreadMerge(DetectEngineCtx *de_ctx, DetectEngineT
de_ctx->profile_keyword_ctx->data[i].max = det_ctx->keyword_perf_data[i].max; de_ctx->profile_keyword_ctx->data[i].max = det_ctx->keyword_perf_data[i].max;
} }
const int nlists = DetectBufferTypeMaxId();
int j; int j;
for (j = 0; j < DETECT_SM_LIST_MAX; j++) { for (j = 0; j < nlists; j++) {
for (i = 0; i < DETECT_TBLSIZE; i++) { for (i = 0; i < DETECT_TBLSIZE; i++) {
de_ctx->profile_keyword_ctx_per_list[j]->data[i].checks += det_ctx->keyword_perf_data_per_list[j][i].checks; de_ctx->profile_keyword_ctx_per_list[j]->data[i].checks += det_ctx->keyword_perf_data_per_list[j][i].checks;
de_ctx->profile_keyword_ctx_per_list[j]->data[i].matches += det_ctx->keyword_perf_data_per_list[j][i].matches; de_ctx->profile_keyword_ctx_per_list[j]->data[i].matches += det_ctx->keyword_perf_data_per_list[j][i].matches;
@ -345,12 +361,13 @@ void SCProfilingKeywordThreadCleanup(DetectEngineThreadCtx *det_ctx)
SCFree(det_ctx->keyword_perf_data); SCFree(det_ctx->keyword_perf_data);
det_ctx->keyword_perf_data = NULL; det_ctx->keyword_perf_data = NULL;
const int nlists = DetectBufferTypeMaxId();
int i; int i;
for (i = 0; i < DETECT_SM_LIST_MAX; i++) { for (i = 0; i < nlists; i++) {
SCFree(det_ctx->keyword_perf_data_per_list[i]); SCFree(det_ctx->keyword_perf_data_per_list[i]);
det_ctx->keyword_perf_data_per_list[i] = NULL; det_ctx->keyword_perf_data_per_list[i] = NULL;
} }
SCFree(det_ctx->keyword_perf_data_per_list);
} }
/** /**
@ -364,6 +381,8 @@ SCProfilingKeywordInitCounters(DetectEngineCtx *de_ctx)
if (profiling_keyword_enabled == 0) if (profiling_keyword_enabled == 0)
return; return;
const int nlists = DetectBufferTypeMaxId();
de_ctx->profile_keyword_ctx = SCProfilingKeywordInitCtx(); de_ctx->profile_keyword_ctx = SCProfilingKeywordInitCtx();
BUG_ON(de_ctx->profile_keyword_ctx == NULL); BUG_ON(de_ctx->profile_keyword_ctx == NULL);
@ -371,8 +390,11 @@ SCProfilingKeywordInitCounters(DetectEngineCtx *de_ctx)
BUG_ON(de_ctx->profile_keyword_ctx->data == NULL); BUG_ON(de_ctx->profile_keyword_ctx->data == NULL);
memset(de_ctx->profile_keyword_ctx->data, 0x00, sizeof(SCProfileKeywordData) * DETECT_TBLSIZE); memset(de_ctx->profile_keyword_ctx->data, 0x00, sizeof(SCProfileKeywordData) * DETECT_TBLSIZE);
de_ctx->profile_keyword_ctx_per_list = SCCalloc(nlists, sizeof(SCProfileKeywordDetectCtx *));
BUG_ON(de_ctx->profile_keyword_ctx_per_list == NULL);
int i; int i;
for (i = 0; i < DETECT_SM_LIST_MAX; i++) { for (i = 0; i < nlists; i++) {
de_ctx->profile_keyword_ctx_per_list[i] = SCProfilingKeywordInitCtx(); de_ctx->profile_keyword_ctx_per_list[i] = SCProfilingKeywordInitCtx();
BUG_ON(de_ctx->profile_keyword_ctx_per_list[i] == NULL); BUG_ON(de_ctx->profile_keyword_ctx_per_list[i] == NULL);
de_ctx->profile_keyword_ctx_per_list[i]->data = SCMalloc(sizeof(SCProfileKeywordData) * DETECT_TBLSIZE); de_ctx->profile_keyword_ctx_per_list[i]->data = SCMalloc(sizeof(SCProfileKeywordData) * DETECT_TBLSIZE);

Loading…
Cancel
Save