]>
Commit | Line | Data |
---|---|---|
064af421 | 1 | /* |
a5f607bc | 2 | * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks. |
064af421 | 3 | * |
a14bc59f BP |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
064af421 | 7 | * |
a14bc59f BP |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
064af421 BP |
15 | */ |
16 | ||
17 | #ifndef COVERAGE_H | |
18 | #define COVERAGE_H 1 | |
19 | ||
20 | /* This file implements a simple form of coverage instrumentation. Points in | |
21 | * source code that are of interest must be explicitly annotated with | |
22 | * COVERAGE_INC. The coverage counters may be logged at any time with | |
23 | * coverage_log(). | |
24 | * | |
25 | * This form of coverage instrumentation is intended to be so lightweight that | |
26 | * it can be enabled in production builds. It is obviously not a substitute | |
27 | * for traditional coverage instrumentation with e.g. "gcov", but it is still | |
28 | * a useful debugging tool. */ | |
29 | ||
30 | #include "vlog.h" | |
31 | ||
32 | /* A coverage counter. */ | |
33 | struct coverage_counter { | |
34 | const char *name; /* Textual name. */ | |
35 | unsigned int count; /* Count within the current epoch. */ | |
36 | unsigned long long int total; /* Total count over all epochs. */ | |
37 | }; | |
38 | ||
d76f09ea BP |
39 | /* Defines COUNTER. There must be exactly one such definition at file scope |
40 | * within a program. */ | |
41 | #if USE_LINKER_SECTIONS | |
42 | #define COVERAGE_DEFINE(COUNTER) \ | |
43 | COVERAGE_DEFINE__(COUNTER); \ | |
f4070db7 | 44 | extern struct coverage_counter *counter_ptr_##COUNTER; \ |
d76f09ea BP |
45 | struct coverage_counter *counter_ptr_##COUNTER \ |
46 | __attribute__((section("coverage"))) = &counter_##COUNTER | |
47 | #else | |
48 | #define COVERAGE_DEFINE(MODULE) \ | |
49 | extern struct coverage_counter counter_##MODULE | |
50 | #endif | |
51 | ||
52 | /* Adds 1 to COUNTER. */ | |
53 | #define COVERAGE_INC(COUNTER) counter_##COUNTER.count++; | |
54 | ||
55 | /* Adds AMOUNT to COUNTER. */ | |
56 | #define COVERAGE_ADD(COUNTER, AMOUNT) counter_##COUNTER.count += (AMOUNT); | |
064af421 | 57 | |
f5c6854a | 58 | void coverage_init(void); |
a5f607bc | 59 | void coverage_log(void); |
064af421 BP |
60 | void coverage_clear(void); |
61 | ||
d76f09ea BP |
62 | /* Implementation detail. */ |
63 | #define COVERAGE_DEFINE__(COUNTER) \ | |
f4070db7 | 64 | extern struct coverage_counter counter_##COUNTER; \ |
d76f09ea BP |
65 | struct coverage_counter counter_##COUNTER = { #COUNTER, 0, 0 } |
66 | ||
064af421 | 67 | #endif /* coverage.h */ |