File: perflogging.h

package info (click to toggle)
clamav 0.98.7+dfsg-0+deb6u2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 60,204 kB
  • ctags: 49,129
  • sloc: cpp: 267,090; ansic: 152,211; sh: 35,196; python: 2,630; makefile: 2,220; perl: 1,690; pascal: 1,218; lisp: 184; csh: 117; xml: 38; asm: 32; exp: 4
file content (102 lines) | stat: -rw-r--r-- 2,747 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 *  Gather statistics from performance sensitive code.
 *
 *  Copyright (C) 2008 Sourcefire, Inc.
 *
 *  Authors: Török Edvin
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *  MA 02110-1301, USA.
 */
#ifndef PERFLOGGING_H
#define PERFLOGGING_H

/* this is a compile-time selectable, default off module to log certain
 * statistics, such as which tries are used, efficiency of filtering and so on.
 * it must have as little overhead as possible */

/* #define CLI_PERF_LOGGING */
#ifdef CLI_PERF_LOGGING

#ifndef __GNUC__
#error "Performance logging requires GNU C compatible compiler"
#else
/*TODO: maybe we need a GCC version check too here */
#include <pthread.h>
#include <assert.h>
#include "cltypes.h"

enum perf_log_sumable {
	RAW_BYTES_SCANNED,
	FILTER_BYTES_SCANNED,
  AC_SCANNED,
	BM_SCANNED,
	__LAST_SUMABLE
};

enum perf_log_countable {
	TRIE_SCANNED,
	FILTER_LOAD,
	FILTER_END_LOAD,
	TRIE_ORIG_LEN,
	__LAST_COUNTABLE
};

extern __thread int last_flushed;
extern __thread int cli_perf_registered;
extern __thread uint64_t cli_perf_sum_tls[__LAST_SUMABLE];
extern __thread uint64_t cli_perf_count_tls[__LAST_COUNTABLE][256];
extern __thread int last_flushed;

extern uint64_t cli_perf_sum[__LAST_SUMABLE];
extern uint64_t cli_perf_count[__LAST_COUNTABLE][256];

void cli_perf_register(void);
void cli_perf_flush(void);

static inline void cli_perf_enter(void)
{
	if (!cli_perf_registered) cli_perf_register();
	if (cli_perf_sum_tls[RAW_BYTES_SCANNED] - last_flushed > 100*1024*1024) {
		cli_perf_flush();
		last_flushed = cli_perf_sum_tls[RAW_BYTES_SCANNED];
	}
}

static inline void cli_perf_log_add(enum perf_log_sumable kind, uint64_t add)
{
	cli_perf_enter();
	assert( kind < __LAST_SUMABLE);
	cli_perf_sum_tls[kind] += add;
}

static inline void cli_perf_log_count2(enum perf_log_countable kind, uint8_t event, uint64_t cnt)
{
	cli_perf_enter();
	assert( kind < __LAST_COUNTABLE);
	cli_perf_count_tls[kind][event] += cnt;
}

static inline void cli_perf_log_count(enum perf_log_countable kind, uint8_t event)
{
	cli_perf_log_count2(kind, event, 1);
}

#endif

#else
#define cli_perf_log_count(a,b) do {} while(0)
#endif

#endif