Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
malloc_tracker.cpp File Reference
#include <thrill/common/json_logger.hpp>
#include <thrill/common/porting.hpp>
#include <thrill/common/profile_thread.hpp>
#include <thrill/mem/malloc_tracker.hpp>
#include <tlx/backtrace.hpp>
#include <tlx/define.hpp>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <limits>
#include <mutex>
#include <utility>
+ Include dependency graph for malloc_tracker.cpp:

Go to the source code of this file.




#define _GNU_SOURCE
#define BYPASS_CHECKER   0
#define COUNTER_ZERO   { 0 }
#define INIT_HEAP_SIZE   1024 * 1024
 a simple memory heap for allocations prior to dlsym loading More...
#define LEAK_CHECKER   0
#define PPREFIX   "malloc_tracker ### "
 output More...
#define USE_ATOMICS   0


using aligned_alloc_type = void *(*)(size_t, size_t)
using CounterType = ssize_t
using free_type = void(*)(void *)
using malloc_type = void *(*)(size_t)
 function pointer to the real procedures, loaded using dlsym() More...
using realloc_type = void *(*)(void *, size_t)


void * bypass_aligned_alloc (size_t alignment, size_t size) noexcept
 bypass malloc tracker and access aligned_alloc() directly More...
void bypass_aligned_free (void *ptr, size_t size) noexcept
 bypass malloc tracker and access aligned_alloc() directly More...
void bypass_free (void *ptr, size_t size) noexcept
 bypass malloc tracker and access free() directly More...
void * bypass_malloc (size_t size) noexcept
 bypass malloc tracker and access malloc() directly More...
void * calloc (size_t nmemb, size_t size) NOEXCEPT
static void dec_count (size_t dec)
 decrement allocation to statistics More...
void flush_memory_statistics ()
 method to flush thread-local memory statistics when memory_exceeded More...
void free (void *ptr) NOEXCEPT
 exported free symbol that overrides loading from libc More...
static ssize_t get (const CounterType &a)
static void inc_count (size_t inc)
 add allocation to statistics More...
void * malloc (size_t size) NOEXCEPT
 exported malloc symbol that overrides loading from libc More...
ssize_t malloc_tracker_current ()
 user function to return the currently allocated amount of memory More...
ssize_t malloc_tracker_peak ()
 user function to return the peak allocation More...
void malloc_tracker_print_leaks ()
 user function which prints new unfreed areas to stdout since the last call More...
void malloc_tracker_print_status ()
 user function which prints current and peak allocation to stderr More...
void malloc_tracker_reset_peak ()
 user function to reset the peak allocation to current More...
ssize_t malloc_tracker_total_allocs ()
 user function to return total number of allocations More...
static void preinit_free (void *ptr)
static void * preinit_malloc (size_t size) noexcept
static void * preinit_realloc (void *ptr, size_t size)
void * realloc (void *ptr, size_t size) NOEXCEPT
 exported realloc() symbol that overrides loading from libc More...
void set_memory_limit_indication (ssize_t size)
void StartMemProfiler (common::ProfileThread &sched, common::JsonLogger &logger)
 launch profiler task More...
static ssize_t sync_add_and_fetch (CounterType &curr, ssize_t inc)
static ssize_t sync_sub_and_fetch (CounterType &curr, ssize_t dec)
static void update_memprofile (ssize_t float_current, ssize_t base_current)
void update_peak (ssize_t float_curr, ssize_t base_curr)


static CounterType base_curr { 0 }
static CounterType current_allocs { 0 }
static CounterType float_curr { 0 }
static constexpr size_t init_alignment = sizeof(size_t)
 align allocations to init_heap to this number by rounding up allocations More...
static char init_heap [1024 *1024]
static CounterType init_heap_use { 0 }
static constexpr bool log_bypass_operations = 0
static constexpr size_t log_bypass_operations_threshold = 100000
static constexpr bool log_operations = 0
static constexpr int log_operations_init_heap = 0
static constexpr size_t log_operations_threshold = 100000
bool memory_exceeded = false
 memory limit exceeded indicator More...
ssize_t memory_limit_indication = std::numeric_limits<ssize_t>::max()
static OhlcBar mp_base
static constexpr bool mp_enable = true
static OhlcBar mp_float
static CounterType mp_next_bar { 0 }
static constexpr size_t padding = 16
static CounterType peak_bytes { 0 }
static constexpr bool profile_bypass_operations = 0
static constexpr bool profile_operations = 0
static aligned_alloc_type real_aligned_alloc = nullptr
static free_type real_free = nullptr
static malloc_type real_malloc = nullptr
static realloc_type real_realloc = nullptr
static constexpr size_t sentinel = 0xDEADC0DE
 a sentinel value prefixed to each allocation More...
static const ssize_t tl_delay_threshold = 1024 * 1024
static thread_local LocalStats tl_stats = { 0, 0, 0 }
static CounterType total_allocs { 0 }
static CounterType total_bytes { 0 }

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 12 of file malloc_tracker.cpp.


Definition at line 54 of file malloc_tracker.cpp.

#define BYPASS_CHECKER   0

Definition at line 75 of file malloc_tracker.cpp.

#define COUNTER_ZERO   { 0 }

Definition at line 115 of file malloc_tracker.cpp.


Definition at line 186 of file malloc_tracker.cpp.

#define INIT_HEAP_SIZE   1024 * 1024

a simple memory heap for allocations prior to dlsym loading

Definition at line 145 of file malloc_tracker.cpp.

Referenced by preinit_malloc().

#define LEAK_CHECKER   0

Definition at line 78 of file malloc_tracker.cpp.

#define USE_ATOMICS   0

Definition at line 101 of file malloc_tracker.cpp.

Function Documentation

void* calloc ( size_t  nmemb,
size_t  size 

exported calloc() symbol that overrides loading from libc, implemented using our malloc

Definition at line 1076 of file malloc_tracker.cpp.

References malloc().

void* malloc ( size_t  size)
static void preinit_free ( void *  ptr)
static void* preinit_malloc ( size_t  size)
static void* preinit_realloc ( void *  ptr,
size_t  size 

keep old area

allocate new area and copy data

Definition at line 692 of file malloc_tracker.cpp.

References free(), thrill::mem::log_operations_init_heap, malloc(), thrill::mem::padding, PPREFIX, and thrill::mem::sentinel.

Referenced by realloc().