aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/assert.h
blob: af3a6c39b7575b9e881357b29f2accbd573a6ebd (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/vespalib/stllike/string.h>

namespace vespalib::assert {

/**
 * How many times has asserts against this key failed.
 * @param key
 * @return
 */
size_t getNumAsserts(const char *key);

/**
 * Get the filename that will be used for remembering asserts.
 * @param key
 * @return
 */
vespalib::string getAssertLogFileName(const char *key);

/**
 * If there is no record on file that this assert has failed, it will be recorded and aborted.
 * However if there is a record of it, it will merely be logged the first and then every #freq time.
 * @param expr that failed the assert
 * @param key unique name of assert
 * @param logFreq how often will a failing assert be logged.
 */
void assertOnceOrLog(const char *expr, const char *key, size_t logFreq);

}

#define ASSERT_ONCE_OR_LOG(expr, key, freq) { \
    if ( ! (expr) ) {                  \
        vespalib::assert::assertOnceOrLog(#expr, key, freq); \
    }                                  \
}