65 static int profiling_sghs_output_to_file = 0;
67 static char profiling_file_name[PATH_MAX];
68 static const char *profiling_file_mode =
"a";
69 #ifdef HAVE_LIBJANSSON 70 static int profiling_rulegroup_json = 0;
82 if (filename != NULL) {
86 snprintf(profiling_file_name,
sizeof(profiling_file_name),
87 "%s/%s", log_dir, filename);
91 profiling_file_mode =
"a";
93 profiling_file_mode =
"w";
96 profiling_sghs_output_to_file = 1;
99 #ifdef HAVE_LIBJANSSON 100 profiling_rulegroup_json = 1;
109 #ifdef HAVE_LIBJANSSON 116 json_t *js = json_object();
119 json_t *jsa = json_array();
125 gettimeofday(&tval, NULL);
127 json_object_set_new(js,
"timestamp", json_string(timebuf));
129 for (i = 0; i < rules_ctx->
cnt; i++) {
131 if (d == NULL || d->
checks == 0)
144 json_t *jsm = json_object();
146 json_object_set_new(jsm,
"id", json_integer(i));
147 json_object_set_new(jsm,
"checks", json_integer(d->
checks));
148 json_object_set_new(jsm,
"non_mpm_generic", json_integer(d->
non_mpm_generic));
149 json_object_set_new(jsm,
"non_mpm_syn", json_integer(d->
non_mpm_syn));
150 json_object_set_new(jsm,
"avgmpms", json_real(avgmpms));
151 json_object_set_new(jsm,
"mpm_match_cnt_max", json_integer(d->
mpm_match_cnt_max));
152 json_object_set_new(jsm,
"avgsigs", json_real(avgsigs));
154 json_array_append_new(jsa, jsm);
157 json_object_set_new(js,
"rule_groups", jsa);
159 char *js_s = json_dumps(js,
160 JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII|
162 if (
likely(js_s != NULL)) {
163 fprintf(fp,
"%s", js_s);
177 gettimeofday(&tval, NULL);
180 fprintf(fp,
" ----------------------------------------------" 181 "------------------------------------------------------" 182 "----------------------------\n");
183 fprintf(fp,
" Date: %" PRId32
"/%" PRId32
"/%04d -- " 184 "%02d:%02d:%02d\n", tms->tm_mon + 1, tms->tm_mday, tms->tm_year + 1900,
185 tms->tm_hour,tms->tm_min, tms->tm_sec);
187 fprintf(fp,
" ----------------------------------------------" 188 "------------------------------------------------------" 189 "----------------------------\n");
190 fprintf(fp,
" Stats for: %s %u\n", name, rules_ctx->
cnt);
191 fprintf(fp,
" ----------------------------------------------" 192 "------------------------------------------------------" 193 "----------------------------\n");
194 fprintf(fp,
" %-16s %-15s %-15s %-15s %-15s %-15s %-15s %-15s\n",
"Sgh",
"Checks",
"Non-MPM(gen)",
"Non-Mpm(syn)",
"MPM Matches",
"MPM Match Max",
"Post-Filter",
"Post-Filter Max");
195 fprintf(fp,
" ---------------- " 204 for (i = 0; i < rules_ctx->
cnt; i++) {
206 if (d == NULL || d->
checks == 0)
220 " %-16u %-15"PRIu64
" %-15"PRIu64
" %-15"PRIu64
" %-15.2f %-15"PRIu64
" %-15.2f %-15"PRIu64
"\n",
241 if (profiling_sghs_output_to_file == 1) {
242 SCLogDebug(
"file %s mode %s", profiling_file_name, profiling_file_mode);
244 fp = fopen(profiling_file_name, profiling_file_mode);
255 #ifdef HAVE_LIBJANSSON 256 if (profiling_rulegroup_json) {
267 SCLogPerf(
"Done dumping rulegroup profiling data.");
303 if (pthread_mutex_init(&ctx->
data_m, NULL) != 0) {
305 "Failed to initialize mutex.");
316 if (ctx->
data != NULL)
318 pthread_mutex_destroy(&ctx->
data_m);
325 if (de_ctx != NULL) {
326 SCProfilingSghDump(de_ctx);
352 #define ADD(name) de_ctx->profile_sgh_ctx->data[i].name += det_ctx->sgh_perf_data[i].name 375 SCProfilingSghThreadMerge(det_ctx->
de_ctx, det_ctx);
struct SCProfileSghData_ * sgh_perf_data
SignatureNonPrefilterStore * non_pf_syn_store_array
void SCProfilingSghThreadSetup(SCProfileSghDetectCtx *ctx, DetectEngineThreadCtx *det_ctx)
uint32_t non_pf_store_cnt
struct SCProfileSghData_ SCProfileSghData
uint64_t post_prefilter_sigs_total
void SCProfilingSghInitCounters(DetectEngineCtx *de_ctx)
Register the keyword profiling counters.
Container for matching data for a signature group.
int ConfNodeChildValueIsTrue(const ConfNode *node, const char *key)
Test if a configuration node has a true value.
main detection engine ctx
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
void CreateIsoTimeString(const struct timeval *ts, char *str, size_t size)
struct tm * SCLocalTime(time_t timep, struct tm *result)
struct SCProfileSghDetectCtx_ SCProfileSghDetectCtx
struct SCProfileSghDetectCtx_ * profile_sgh_ctx
int profiling_sghs_enabled
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
int ConfValIsTrue(const char *val)
Check if a value is true.
const char * ConfigGetLogDirectory()
uint64_t mpm_match_cnt_total
uint32_t rule_id_array_cnt
void SCProfilingSghDestroyCtx(DetectEngineCtx *de_ctx)
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
SignatureNonPrefilterStore * non_pf_store_ptr
uint64_t post_prefilter_sigs_max
void SCProfilingSghUpdateCounter(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh)
Update a rule counter.
void SCProfilingSghsGlobalInit(void)
uint64_t mpm_match_cnt_max
void SCProfilingSghThreadCleanup(DetectEngineThreadCtx *det_ctx)