57 static int profiling_sghs_output_to_file = 0;
59 static char profiling_file_name[PATH_MAX];
60 static const char *profiling_file_mode =
"a";
61 static int profiling_rulegroup_json = 0;
72 if (filename != NULL) {
76 snprintf(profiling_file_name,
sizeof(profiling_file_name),
77 "%s/%s", log_dir, filename);
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,
"non_mpm_generic", json_integer(d->
non_mpm_generic));
134 json_object_set_new(jsm,
"non_mpm_syn", json_integer(d->
non_mpm_syn));
135 json_object_set_new(jsm,
"avgmpms", json_real(avgmpms));
136 json_object_set_new(jsm,
"mpm_match_cnt_max", json_integer(d->
mpm_match_cnt_max));
137 json_object_set_new(jsm,
"avgsigs", json_real(avgsigs));
139 json_array_append_new(jsa, jsm);
142 json_object_set_new(js,
"rule_groups", jsa);
144 char *js_s = json_dumps(js,
145 JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII|
147 if (
likely(js_s != NULL)) {
148 fprintf(fp,
"%s", js_s);
161 gettimeofday(&tval, NULL);
164 fprintf(fp,
" ----------------------------------------------"
165 "------------------------------------------------------"
166 "----------------------------\n");
167 fprintf(fp,
" Date: %" PRId32
"/%" PRId32
"/%04d -- "
168 "%02d:%02d:%02d\n", tms->tm_mon + 1, tms->tm_mday, tms->tm_year + 1900,
169 tms->tm_hour,tms->tm_min, tms->tm_sec);
171 fprintf(fp,
" ----------------------------------------------"
172 "------------------------------------------------------"
173 "----------------------------\n");
174 fprintf(fp,
" Stats for: %s %u\n", name, rules_ctx->
cnt);
175 fprintf(fp,
" ----------------------------------------------"
176 "------------------------------------------------------"
177 "----------------------------\n");
178 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");
179 fprintf(fp,
" ---------------- "
188 for (i = 0; i < rules_ctx->
cnt; i++) {
190 if (d == NULL || d->
checks == 0)
204 " %-16u %-15"PRIu64
" %-15"PRIu64
" %-15"PRIu64
" %-15.2f %-15"PRIu64
" %-15.2f %-15"PRIu64
"\n",
225 if (profiling_sghs_output_to_file == 1) {
226 SCLogDebug(
"file %s mode %s", profiling_file_name, profiling_file_mode);
228 fp = fopen(profiling_file_name, profiling_file_mode);
231 SCLogError(
"failed to open %s: %s", profiling_file_name, strerror(errno));
238 if (profiling_rulegroup_json) {
247 SCLogPerf(
"Done dumping rulegroup profiling data.");
283 if (pthread_mutex_init(&ctx->
data_m, NULL) != 0) {
294 if (ctx->
data != NULL)
296 pthread_mutex_destroy(&ctx->
data_m);
304 SCProfilingSghDump(
de_ctx);
330 #define ADD(name) de_ctx->profile_sgh_ctx->data[i].name += det_ctx->sgh_perf_data[i].name
334 ADD(non_mpm_generic);
336 ADD(post_prefilter_sigs_total);
337 ADD(mpm_match_cnt_total);
353 SCProfilingSghThreadMerge(det_ctx->
de_ctx, det_ctx);