2 * Copyright 2018-2019 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
17 #ifndef __HEAP_TRACER_H__
18 #define __HEAP_TRACER_H__
22 #include <unordered_map>
27 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
30 #define vm_calloc_simple(nmemb, size) vm_calloc(nmemb, size, "%s: %s(%d)", __MODULE__, __func__, __LINE__)
31 #define vm_malloc_simple(size) vm_malloc(size, "%s: %s(%d)", __MODULE__, __func__, __LINE__)
32 #define vm_free_simple(ptr) vm_free(ptr, "%s: %s(%d)", __MODULE__, __func__, __LINE__)
33 #define vm_strdup_simple(ptr) vm_strdup(ptr, "%s: %s(%d)", __MODULE__, __func__, __LINE__)
34 #define vm_mark_unmanaged_simple(ptr) vm_mark_unmanaged(ptr, "%s: %s(%d)", __MODULE__, __func__, __LINE__)
36 void *vm_calloc(size_t nmemb, size_t size, const char *fmt, ...);
37 void *vm_malloc(size_t size, const char *fmt, ...);
38 void vm_free(void *ptr, const char *fmt, ...);
39 char *vm_strdup(const char *s, const char *fmt, ...);
40 void *vm_mark_unmanaged(void *ptr, const char *fmt, ...);
45 virtual ~HeapTracer();
47 bool Insert(void *ptr, std::string description, size_t size = 0);
48 bool Delete(void *ptr, std::string description);
49 std::string Find(void *ptr);
51 void MarkUnmanaged(void *ptr, std::string description);
58 std::string description;
62 std::mutex mManagedTableMutex;
63 std::unordered_map<void*, AllocationEntry> mManagedTable;
65 std::mutex mUnmanagedRecordsMutex;
66 std::list<AllocationEntry> mUnmanagedRecords;
67 size_t mUnmanagedRecordsSize{0};
69 enum class EntryOperation {
74 AllocationEntry entry;
75 EntryOperation operation;
78 std::list<EntryHistory> mEntryHistory;
81 #endif /* __HEAP_TRACER_H__ */