~ubuntu-branches/ubuntu/maverick/clamav/maverick-backports

« back to all changes in this revision

Viewing changes to libclamav/perflogging.h

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran, Stephen Gran, Michael Tautschnig
  • Date: 2010-04-26 21:41:18 UTC
  • mfrom: (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100426214118-i6lo606wnh7ywfj6
Tags: 0.96+dfsg-4
[ Stephen Gran ]
* Fixed typo in clamav-milter's postinst

[ Michael Tautschnig ]
* Fixed typo in clamav-freshclam's postinst (closes: #579271)
* Debconf translation updates
  - Portuguese (closes: #579068)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Gather statistics from performance sensitive code.
 
3
 *
 
4
 *  Copyright (C) 2008 Sourcefire, Inc.
 
5
 *
 
6
 *  Authors: Török Edvin
 
7
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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,
 
20
 *  MA 02110-1301, USA.
 
21
 */
 
22
#ifndef PERFLOGGING_H
 
23
#define PERFLOGGING_H
 
24
 
 
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 */
 
28
 
 
29
/* #define CLI_PERF_LOGGING */
 
30
#ifdef CLI_PERF_LOGGING
 
31
 
 
32
#ifndef __GNUC__
 
33
#error "Performance logging requires GNU C compatible compiler"
 
34
#else
 
35
/*TODO: maybe we need a GCC version check too here */
 
36
#include <pthread.h>
 
37
#include <assert.h>
 
38
#include "cltypes.h"
 
39
 
 
40
enum perf_log_sumable {
 
41
        RAW_BYTES_SCANNED,
 
42
        FILTER_BYTES_SCANNED,
 
43
  AC_SCANNED,
 
44
        BM_SCANNED,
 
45
        __LAST_SUMABLE
 
46
};
 
47
 
 
48
enum perf_log_countable {
 
49
        TRIE_SCANNED,
 
50
        FILTER_LOAD,
 
51
        FILTER_END_LOAD,
 
52
        TRIE_ORIG_LEN,
 
53
        __LAST_COUNTABLE
 
54
};
 
55
 
 
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;
 
61
 
 
62
extern uint64_t cli_perf_sum[__LAST_SUMABLE];
 
63
extern uint64_t cli_perf_count[__LAST_COUNTABLE][256];
 
64
 
 
65
void cli_perf_register(void);
 
66
void cli_perf_flush(void);
 
67
 
 
68
static inline void cli_perf_enter(void)
 
69
{
 
70
        if (!cli_perf_registered) cli_perf_register();
 
71
        if (cli_perf_sum_tls[RAW_BYTES_SCANNED] - last_flushed > 100*1024*1024) {
 
72
                cli_perf_flush();
 
73
                last_flushed = cli_perf_sum_tls[RAW_BYTES_SCANNED];
 
74
        }
 
75
}
 
76
 
 
77
static inline void cli_perf_log_add(enum perf_log_sumable kind, uint64_t add)
 
78
{
 
79
        cli_perf_enter();
 
80
        assert( kind < __LAST_SUMABLE);
 
81
        cli_perf_sum_tls[kind] += add;
 
82
}
 
83
 
 
84
static inline void cli_perf_log_count2(enum perf_log_countable kind, uint8_t event, uint64_t cnt)
 
85
{
 
86
        cli_perf_enter();
 
87
        assert( kind < __LAST_COUNTABLE);
 
88
        cli_perf_count_tls[kind][event] += cnt;
 
89
}
 
90
 
 
91
static inline void cli_perf_log_count(enum perf_log_countable kind, uint8_t event)
 
92
{
 
93
        cli_perf_log_count2(kind, event, 1);
 
94
}
 
95
 
 
96
#endif
 
97
 
 
98
#else
 
99
#define cli_perf_log_count(a,b) do {} while(0)
 
100
#endif
 
101
 
 
102
#endif