54 static int profiling_sghs_output_to_file = 0;
56 static char profiling_file_name[PATH_MAX];
57 static const char *profiling_file_mode =
"a";
58 static int profiling_rulegroup_json = 0;
69 if (filename != NULL) {
71 strlcpy(profiling_file_name, filename,
sizeof(profiling_file_name));
74 snprintf(profiling_file_name,
sizeof(profiling_file_name),
"%s/%s", log_dir,
80 profiling_file_mode =
"a";
82 profiling_file_mode =
"w";
85 profiling_sghs_output_to_file = 1;
88 profiling_rulegroup_json = 1;
100 json_t *js = json_object();
103 json_t *jsa = json_array();
109 gettimeofday(&tval, NULL);
111 json_object_set_new(js,
"timestamp", json_string(timebuf));
113 for (i = 0; i < rules_ctx->
cnt; i++) {
115 if (d == NULL || d->
checks == 0)
128 json_t *jsm = json_object();
130 json_object_set_new(jsm,
"id", json_integer(i));
131 json_object_set_new(jsm,
"checks", json_integer(d->
checks));
132 json_object_set_new(jsm,
"avgmpms", json_real(avgmpms));
133 json_object_set_new(jsm,
"mpm_match_cnt_max", json_integer(d->
mpm_match_cnt_max));
134 json_object_set_new(jsm,
"avgsigs", json_real(avgsigs));
136 json_array_append_new(jsa, jsm);
139 json_object_set_new(js,
"rule_groups", jsa);
141 char *js_s = json_dumps(js,
142 JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII|
144 if (
likely(js_s != NULL)) {
145 fprintf(fp,
"%s", js_s);
158 gettimeofday(&tval, NULL);
161 fprintf(fp,
" ----------------------------------------------"
162 "------------------------------------------------------"
163 "----------------------------\n");
164 fprintf(fp,
" Date: %" PRId32
"/%" PRId32
"/%04d -- "
165 "%02d:%02d:%02d\n", tms->tm_mon + 1, tms->tm_mday, tms->tm_year + 1900,
166 tms->tm_hour,tms->tm_min, tms->tm_sec);
168 fprintf(fp,
" ----------------------------------------------"
169 "------------------------------------------------------"
170 "----------------------------\n");
171 fprintf(fp,
" Stats for: %s %u\n",
name, rules_ctx->
cnt);
172 fprintf(fp,
" ----------------------------------------------"
173 "------------------------------------------------------"
174 "----------------------------\n");
175 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");
176 fprintf(fp,
" ---------------- "
185 for (i = 0; i < rules_ctx->
cnt; i++) {
187 if (d == NULL || d->
checks == 0)
200 fprintf(fp,
" %-16u %-15" PRIu64
" %-15.2f %-15" PRIu64
" %-15.2f %-15" PRIu64
"\n", i,
214 if (profiling_sghs_output_to_file == 1) {
215 SCLogDebug(
"file %s mode %s", profiling_file_name, profiling_file_mode);
217 fp = fopen(profiling_file_name, profiling_file_mode);
220 SCLogError(
"failed to open %s: %s", profiling_file_name, strerror(errno));
227 if (profiling_rulegroup_json) {
236 SCLogPerf(
"Done dumping rulegroup profiling data.");
249 if (det_ctx != NULL && sgh != NULL && det_ctx->
sgh_perf_data != NULL &&
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);