summaryrefslogtreecommitdiffstats
path: root/document/src/tests/heapdebugger.h
blob: 1706b99a0a9a8e3ae8cf6594d1dc0f875e4d9b8d (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/*
 * Author: Ove Martin Malm
 */

#pragma once
#include <cstddef>


/**
 *  This function is used for counting memory usage. Must be called before any block is allocated
 * (pt. linux only)
 * Parameter controls operation
 */
extern void enableHeapUsageMonitor(int param = 0);


/**
 * This function return the current memory used.
 * @return   Net number of bytes allocated on the heap
 */
extern size_t getHeapUsage(void);

/**
 * This enables heap debugging. Must be called before any block is allocated
 * Parameter controls operation
 * (pt. linux only)
 */
extern void enableHeapCorruptCheck(int param = 0);

#define HEAPCHECKMODE_REMOVE        -1      // Deinstall
#define HEAPCHECKMODE_NORMAL        0       // Normal
#define HEAPCHECKMODE_EXTENSIVE     1       // All allocated blocks checked on all ops..
#define HEAPCHECKMODE_DISABLED      2       // No checking (but extra bytes allocated)



/**
 * Run a heap check now. Will lock the heap and run through a full check. Will crash if it fails...
 */
extern void checkHeapNow(void);


/**
 * And this enables linux mcheck function with an approprate callback function. (absolutely linux only)
 * see man mcheck
 */
extern void enableMCheck(void);