54 static int profiling_prefilter_output_to_file = 0;
57 static char profiling_file_name[PATH_MAX];
58 static const char *profiling_file_mode =
"a";
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_prefilter_output_to_file = 1;
94 fprintf(fp,
" ----------------------------------------------"
95 "------------------------------------------------------"
96 "----------------------------\n");
97 fprintf(fp,
" Stats for: %s\n",
name);
98 fprintf(fp,
" ----------------------------------------------"
99 "------------------------------------------------------"
100 "----------------------------\n");
101 fprintf(fp,
" %-32s %-15s %-15s %-15s %-15s %-15s %-15s %-15s %-15s %-15s\n",
"Prefilter",
102 "Ticks",
"Called",
"Max Ticks",
"Avg",
"Bytes",
"Called",
"Max Bytes",
"Avg Bytes",
104 fprintf(fp,
" -------------------------------- "
115 for (i = 0; i < (int)rules_ctx->
size; i++) {
117 if (d == NULL || d->
called== 0)
120 uint64_t ticks = d->
total;
123 avgticks = (double)(ticks / d->
called);
129 double ticks_per_byte = 0;
135 " %-32s %-15" PRIu64
" %-15" PRIu64
" %-15" PRIu64
" %-15.2f %-15" PRIu64
136 " %-15" PRIu64
" %-15" PRIu64
" %-15.2f %-15.2f\n",
153 gettimeofday(&tval, NULL);
156 if (profiling_prefilter_output_to_file == 1) {
157 SCLogDebug(
"file %s mode %s", profiling_file_name, profiling_file_mode);
159 fp = fopen(profiling_file_name, profiling_file_mode);
162 SCLogError(
"failed to open %s: %s", profiling_file_name, strerror(errno));
169 fprintf(fp,
" ----------------------------------------------"
170 "------------------------------------------------------"
171 "----------------------------\n");
172 fprintf(fp,
" Date: %" PRId32
"/%" PRId32
"/%04d -- "
173 "%02d:%02d:%02d\n", tms->tm_mon + 1, tms->tm_mday, tms->tm_year + 1900,
174 tms->tm_hour,tms->tm_min, tms->tm_sec);
183 SCLogPerf(
"Done dumping prefilter profiling data.");
194 uint64_t bytes, uint64_t bytes_called)
206 p->bytes_called += bytes_called;
207 if (bytes >
p->max_bytes)
208 p->max_bytes = bytes;
209 p->total_bytes += bytes;
217 if (pthread_mutex_init(&
ctx->data_m, NULL) != 0) {
218 FatalError(
"Failed to initialize hash table mutex.");
228 if (
ctx->data != NULL)
230 pthread_mutex_destroy(&
ctx->data_m);
238 SCProfilingPrefilterDump(
de_ctx);
286 SCProfilingPrefilterThreadMerge(det_ctx->
de_ctx, det_ctx);
323 SCLogPerf(
"Registered %"PRIu32
" prefilter profiling counters.", size);