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 static int profiling_rulegroup_json = 0;
80 if (filename != NULL) {
84 snprintf(profiling_file_name,
sizeof(profiling_file_name),
85 "%s/%s", log_dir, filename);
89 profiling_file_mode =
"a";
91 profiling_file_mode =
"w";
94 profiling_sghs_output_to_file = 1;
97 profiling_rulegroup_json = 1;
109 json_t *js = json_object();
112 json_t *jsa = json_array();
118 gettimeofday(&tval, NULL);
120 json_object_set_new(js,
"timestamp", json_string(timebuf));
122 for (i = 0; i < rules_ctx->
cnt; i++) {
124 if (d == NULL || d->
checks == 0)
137 json_t *jsm = json_object();
139 json_object_set_new(jsm,
"id", json_integer(i));
140 json_object_set_new(jsm,
"checks", json_integer(d->
checks));
141 json_object_set_new(jsm,
"non_mpm_generic", json_integer(d->
non_mpm_generic));
142 json_object_set_new(jsm,
"non_mpm_syn", json_integer(d->
non_mpm_syn));
143 json_object_set_new(jsm,
"avgmpms", json_real(avgmpms));
144 json_object_set_new(jsm,
"mpm_match_cnt_max", json_integer(d->
mpm_match_cnt_max));
145 json_object_set_new(jsm,
"avgsigs", json_real(avgsigs));
147 json_array_append_new(jsa, jsm);
150 json_object_set_new(js,
"rule_groups", jsa);
152 char *js_s = json_dumps(js,
153 JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII|
155 if (
likely(js_s != NULL)) {
156 fprintf(fp,
"%s", js_s);
169 gettimeofday(&tval, NULL);
172 fprintf(fp,
" ----------------------------------------------"
173 "------------------------------------------------------"
174 "----------------------------\n");
175 fprintf(fp,
" Date: %" PRId32
"/%" PRId32
"/%04d -- "
176 "%02d:%02d:%02d\n", tms->tm_mon + 1, tms->tm_mday, tms->tm_year + 1900,
177 tms->tm_hour,tms->tm_min, tms->tm_sec);
179 fprintf(fp,
" ----------------------------------------------"
180 "------------------------------------------------------"
181 "----------------------------\n");
182 fprintf(fp,
" Stats for: %s %u\n", name, rules_ctx->
cnt);
183 fprintf(fp,
" ----------------------------------------------"
184 "------------------------------------------------------"
185 "----------------------------\n");
186 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");
187 fprintf(fp,
" ---------------- "
196 for (i = 0; i < rules_ctx->
cnt; i++) {
198 if (d == NULL || d->
checks == 0)
212 " %-16u %-15"PRIu64
" %-15"PRIu64
" %-15"PRIu64
" %-15.2f %-15"PRIu64
" %-15.2f %-15"PRIu64
"\n",
233 if (profiling_sghs_output_to_file == 1) {
234 SCLogDebug(
"file %s mode %s", profiling_file_name, profiling_file_mode);
236 fp = fopen(profiling_file_name, profiling_file_mode);
247 if (profiling_rulegroup_json) {
256 SCLogPerf(
"Done dumping rulegroup profiling data.");
292 if (pthread_mutex_init(&ctx->
data_m, NULL) != 0) {
303 if (ctx->
data != NULL)
305 pthread_mutex_destroy(&ctx->
data_m);
313 SCProfilingSghDump(
de_ctx);
339 #define ADD(name) de_ctx->profile_sgh_ctx->data[i].name += det_ctx->sgh_perf_data[i].name
343 ADD(non_mpm_generic);
345 ADD(post_prefilter_sigs_total);
346 ADD(mpm_match_cnt_total);
362 SCProfilingSghThreadMerge(det_ctx->
de_ctx, det_ctx);