2
* Gather statistics from performance sensitive code.
4
* Copyright (C) 2008 Sourcefire, Inc.
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License version 2 as
10
* published by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25
/* this is a compile-time selectable, default off module to log certain
26
* statistics, such as which tries are used, efficiency of filtering and so on.
27
* it must have as little overhead as possible */
29
/* #define CLI_PERF_LOGGING */
30
#ifdef CLI_PERF_LOGGING
33
#error "Performance logging requires GNU C compatible compiler"
35
/*TODO: maybe we need a GCC version check too here */
40
enum perf_log_sumable {
48
enum perf_log_countable {
56
extern __thread int last_flushed;
57
extern __thread int cli_perf_registered;
58
extern __thread uint64_t cli_perf_sum_tls[__LAST_SUMABLE];
59
extern __thread uint64_t cli_perf_count_tls[__LAST_COUNTABLE][256];
60
extern __thread int last_flushed;
62
extern uint64_t cli_perf_sum[__LAST_SUMABLE];
63
extern uint64_t cli_perf_count[__LAST_COUNTABLE][256];
65
void cli_perf_register(void);
66
void cli_perf_flush(void);
68
static inline void cli_perf_enter(void)
70
if (!cli_perf_registered) cli_perf_register();
71
if (cli_perf_sum_tls[RAW_BYTES_SCANNED] - last_flushed > 100*1024*1024) {
73
last_flushed = cli_perf_sum_tls[RAW_BYTES_SCANNED];
77
static inline void cli_perf_log_add(enum perf_log_sumable kind, uint64_t add)
80
assert( kind < __LAST_SUMABLE);
81
cli_perf_sum_tls[kind] += add;
84
static inline void cli_perf_log_count2(enum perf_log_countable kind, uint8_t event, uint64_t cnt)
87
assert( kind < __LAST_COUNTABLE);
88
cli_perf_count_tls[kind][event] += cnt;
91
static inline void cli_perf_log_count(enum perf_log_countable kind, uint8_t event)
93
cli_perf_log_count2(kind, event, 1);
99
#define cli_perf_log_count(a,b) do {} while(0)