58 static int profiling_sghs_output_to_file = 0;
60 static char profiling_file_name[PATH_MAX];
61 static const char *profiling_file_mode =
"a";
62 static int profiling_rulegroup_json = 0;
73 if (filename != NULL) {
75 strlcpy(profiling_file_name, filename,
sizeof(profiling_file_name));
78 snprintf(profiling_file_name,
sizeof(profiling_file_name),
"%s/%s", log_dir,
84 profiling_file_mode =
"a";
86 profiling_file_mode =
"w";
89 profiling_sghs_output_to_file = 1;
92 profiling_rulegroup_json = 1;
104 json_t *js = json_object();
107 json_t *jsa = json_array();
113 gettimeofday(&tval, NULL);
115 json_object_set_new(js,
"timestamp", json_string(timebuf));
117 for (i = 0; i < rules_ctx->
cnt; i++) {
119 if (d == NULL || d->
checks == 0)
132 json_t *jsm = json_object();
134 json_object_set_new(jsm,
"id", json_integer(i));
135 json_object_set_new(jsm,
"checks", json_integer(d->
checks));
136 json_object_set_new(jsm,
"non_mpm_generic", json_integer(d->
non_mpm_generic));
137 json_object_set_new(jsm,
"non_mpm_syn", json_integer(d->
non_mpm_syn));
138 json_object_set_new(jsm,
"avgmpms", json_real(avgmpms));
139 json_object_set_new(jsm,
"mpm_match_cnt_max", json_integer(d->
mpm_match_cnt_max));
140 json_object_set_new(jsm,
"avgsigs", json_real(avgsigs));
142 json_array_append_new(jsa, jsm);
145 json_object_set_new(js,
"rule_groups", jsa);
147 char *js_s = json_dumps(js,
148 JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII|
150 if (
likely(js_s != NULL)) {
151 fprintf(fp,
"%s", js_s);
164 gettimeofday(&tval, NULL);
167 fprintf(fp,
" ----------------------------------------------"
168 "------------------------------------------------------"
169 "----------------------------\n");
170 fprintf(fp,
" Date: %" PRId32
"/%" PRId32
"/%04d -- "
171 "%02d:%02d:%02d\n", tms->tm_mon + 1, tms->tm_mday, tms->tm_year + 1900,
172 tms->tm_hour,tms->tm_min, tms->tm_sec);
174 fprintf(fp,
" ----------------------------------------------"
175 "------------------------------------------------------"
176 "----------------------------\n");
177 fprintf(fp,
" Stats for: %s %u\n", name, rules_ctx->
cnt);
178 fprintf(fp,
" ----------------------------------------------"
179 "------------------------------------------------------"
180 "----------------------------\n");
181 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");
182 fprintf(fp,
" ---------------- "
191 for (i = 0; i < rules_ctx->
cnt; i++) {
193 if (d == NULL || d->
checks == 0)
207 " %-16u %-15"PRIu64
" %-15"PRIu64
" %-15"PRIu64
" %-15.2f %-15"PRIu64
" %-15.2f %-15"PRIu64
"\n",
228 if (profiling_sghs_output_to_file == 1) {
229 SCLogDebug(
"file %s mode %s", profiling_file_name, profiling_file_mode);
231 fp = fopen(profiling_file_name, profiling_file_mode);
234 SCLogError(
"failed to open %s: %s", profiling_file_name, strerror(errno));
241 if (profiling_rulegroup_json) {
250 SCLogPerf(
"Done dumping rulegroup profiling data.");
286 if (pthread_mutex_init(&
ctx->data_m, NULL) != 0) {
297 if (
ctx->data != NULL)
299 pthread_mutex_destroy(&
ctx->data_m);
307 SCProfilingSghDump(
de_ctx);
333 #define ADD(name) de_ctx->profile_sgh_ctx->data[i].name += det_ctx->sgh_perf_data[i].name
337 ADD(non_mpm_generic);
339 ADD(post_prefilter_sigs_total);
340 ADD(mpm_match_cnt_total);
356 SCProfilingSghThreadMerge(det_ctx->
de_ctx, det_ctx);