1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2012 Couchbase, Inc
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17
18#include "config.h"
19
20#include "memory_tracker.h"
21
22/**
23 * THIS FILE SHOULD NEVER ACTUALLY BE RUN. IT IS JUST USED TO GET SOME OF OUR
24 * TESTS TO COMPILE.
25 */
26
27extern "C" {
28    static bool mock_add_new_hook(void (*)(const void* ptr, size_t size)) {
29        return false;
30    }
31
32    static bool mock_remove_new_hook(void (*)(const void* ptr, size_t size)) {
33        return false;
34    }
35
36    static bool mock_add_delete_hook(void (*)(const void* ptr)) {
37        return false;
38    }
39
40    static bool mock_remove_delete_hook(void (*)(const void* ptr)) {
41        return false;
42    }
43
44    static int mock_get_extra_stats_size() {
45        return 0;
46    }
47
48    static void mock_get_allocator_stats(allocator_stats*) {
49        // Empty
50    }
51
52    static size_t mock_get_allocation_size(const void*) {
53        return 0;
54    }
55}
56
57ALLOCATOR_HOOKS_API* getHooksApi(void) {
58    static ALLOCATOR_HOOKS_API hooksApi;
59    hooksApi.add_new_hook = mock_add_new_hook;
60    hooksApi.remove_new_hook = mock_remove_new_hook;
61    hooksApi.add_delete_hook = mock_add_delete_hook;
62    hooksApi.remove_delete_hook = mock_remove_delete_hook;
63    hooksApi.get_extra_stats_size = mock_get_extra_stats_size;
64    hooksApi.get_allocator_stats = mock_get_allocator_stats;
65    hooksApi.get_allocation_size = mock_get_allocation_size;
66    return &hooksApi;
67}
68
69bool MemoryTracker::tracking = false;
70MemoryTracker *MemoryTracker::instance = 0;
71
72MemoryTracker *MemoryTracker::getInstance() {
73    if (!instance) {
74        instance = new MemoryTracker();
75    }
76    return instance;
77}
78
79MemoryTracker::MemoryTracker() {
80    // Do nothing
81}
82
83MemoryTracker::~MemoryTracker() {
84    // Do nothing
85}
86
87void MemoryTracker::getAllocatorStats(std::map<std::string, size_t> &allocator_stats) {
88    (void) allocator_stats;
89    // Do nothing
90}
91
92bool MemoryTracker::trackingMemoryAllocations() {
93    // This should ALWAYS return false
94    return tracking;
95}
96
97size_t MemoryTracker::getFragmentation() {
98    return 0;
99}
100
101size_t MemoryTracker::getTotalBytesAllocated() {
102    return 0;
103}
104
105size_t MemoryTracker::getTotalHeapBytes() {
106    return 0;
107}
108
109