2 * Copyright (c) 2009 Nicira Networks.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
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. */
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. */
39 /* Increments the counter with the given NAME. Coverage counters need not be
40 * declared explicitly, but when you add the first coverage counter to a given
41 * file, you must also add that file to COVERAGE_FILES in lib/automake.mk. */
42 #define COVERAGE_INC(NAME) \
44 extern struct coverage_counter NAME##_count; \
45 NAME##_count.count++; \
48 /* Adds AMOUNT to the coverage counter with the given NAME. */
49 #define COVERAGE_ADD(NAME, AMOUNT) \
51 extern struct coverage_counter NAME##_count; \
52 NAME##_count.count += AMOUNT; \
55 void coverage_init(void);
56 void coverage_log(enum vlog_level, bool suppress_dups);
57 void coverage_clear(void);
59 #endif /* coverage.h */