55 static int profiling_sghs_output_to_file = 0;
57 static char profiling_file_name[PATH_MAX];
58 static const char *profiling_file_mode =
"a";
59 static int profiling_rulegroup_json = 0;
70 if (filename != NULL) {
72 strlcpy(profiling_file_name, filename,
sizeof(profiling_file_name));
75 snprintf(profiling_file_name,
sizeof(profiling_file_name),
"%s/%s", log_dir,
81 profiling_file_mode =
"a";
83 profiling_file_mode =
"w";
86 profiling_sghs_output_to_file = 1;
89 profiling_rulegroup_json = 1;
101 json_t *js = json_object();
104 json_t *jsa = json_array();
110 gettimeofday(&tval, NULL);
112 json_object_set_new(js,
"timestamp", json_string(timebuf));
114 for (i = 0; i < rules_ctx->
cnt; i++) {
116 if (d == NULL || d->
checks == 0)
129 json_t *jsm = json_object();
131 json_object_set_new(jsm,
"id", json_integer(i));
132 json_object_set_new(jsm,
"checks", json_integer(d->
checks));
133 json_object_set_new(jsm,
"avgmpms", json_real(avgmpms));
134 json_object_set_new(jsm,
"mpm_match_cnt_max", json_integer(d->
mpm_match_cnt_max));
135 json_object_set_new(jsm,
"avgsigs", json_real(avgsigs));
137 json_array_append_new(jsa, jsm);
140 json_object_set_new(js,
"rule_groups", jsa);
142 char *js_s = json_dumps(js,
143 JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII|
145 if (
likely(js_s != NULL)) {
146 fprintf(fp,
"%s", js_s);
159 gettimeofday(&tval, NULL);
162 fprintf(fp,
" ----------------------------------------------"
163 "------------------------------------------------------"
164 "----------------------------\n");
165 fprintf(fp,
" Date: %" PRId32
"/%" PRId32
"/%04d -- "
166 "%02d:%02d:%02d\n", tms->tm_mon + 1, tms->tm_mday, tms->tm_year + 1900,
167 tms->tm_hour,tms->tm_min, tms->tm_sec);
169 fprintf(fp,
" ----------------------------------------------"
170 "------------------------------------------------------"
171 "----------------------------\n");
172 fprintf(fp,
" Stats for: %s %u\n",
name, rules_ctx->
cnt);
173 fprintf(fp,
" ----------------------------------------------"
174 "------------------------------------------------------"
175 "----------------------------\n");
176 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");
177 fprintf(fp,
" ---------------- "
186 for (i = 0; i < rules_ctx->
cnt; i++) {
188 if (d == NULL || d->
checks == 0)
201 fprintf(fp,
" %-16u %-15" PRIu64
" %-15.2f %-15" PRIu64
" %-15.2f %-15" PRIu64
"\n", i,
215 if (profiling_sghs_output_to_file == 1) {
216 SCLogDebug(
"file %s mode %s", profiling_file_name, profiling_file_mode);
218 fp = fopen(profiling_file_name, profiling_file_mode);
221 SCLogError(
"failed to open %s: %s", profiling_file_name, strerror(errno));
228 if (profiling_rulegroup_json) {
237 SCLogPerf(
"Done dumping rulegroup profiling data.");
267 if (pthread_mutex_init(&
ctx->data_m, NULL) != 0) {
278 if (
ctx->data != NULL)
280 pthread_mutex_destroy(&
ctx->data_m);
288 SCProfilingSghDump(
de_ctx);
314 #define ADD(name) de_ctx->profile_sgh_ctx->data[i].name += det_ctx->sgh_perf_data[i].name
318 ADD(post_prefilter_sigs_total);
319 ADD(mpm_match_cnt_total);
335 SCProfilingSghThreadMerge(det_ctx->
de_ctx, det_ctx);