Thrill  0.1
malloc_tracker.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/mem/malloc_tracker.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2013-2015 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
11 #pragma once
12 #ifndef THRILL_MEM_MALLOC_TRACKER_HEADER
13 #define THRILL_MEM_MALLOC_TRACKER_HEADER
14 
15 #include <cstdlib>
16 
17 #if defined(_MSC_VER)
18 // windows/msvc is a mess.
19 #include <BaseTsd.h>
20 using ssize_t = SSIZE_T;
21 #elif defined(__APPLE__)
22 #include <unistd.h>
23 #endif
24 
25 namespace thrill {
26 namespace common {
27 
28 // forward declarations
29 class ProfileThread;
30 class JsonLogger;
31 
32 } // namespace common
33 namespace mem {
34 
35 //! boolean indication that the memory limit is exceeded
36 extern bool memory_exceeded;
37 
38 //! method to flush thread-local memory statistics when memory_exceeded
40 
41 //! set the malloc tracking system to set memory_exceeded when this limit is
42 //! exceed. it does not actually limit allocation!
43 void set_memory_limit_indication(ssize_t size);
44 
45 //! bypass malloc tracker and access malloc() directly
46 void * bypass_malloc(size_t size) noexcept;
47 
48 //! bypass malloc tracker and access free() directly
49 void bypass_free(void* ptr, size_t size) noexcept;
50 
51 //! bypass malloc tracker and access aligned_alloc() directly
52 void * bypass_aligned_alloc(size_t alignment, size_t size) noexcept;
53 
54 //! bypass malloc tracker and access aligned_alloc() directly
55 void bypass_aligned_free(void* ptr, size_t size) noexcept;
56 
57 //! returns the currently allocated amount of memory
58 ssize_t malloc_tracker_current();
59 
60 //! returns the current peak memory allocation
61 ssize_t malloc_tracker_peak();
62 
63 //! resets the peak memory allocation to current
65 
66 //! returns the total number of allocations
68 
69 //! user function which prints current and peak allocation to stderr
71 
72 //! user function which prints new unfreed areas to stdout since the last call
74 
75 //! launch profiler task
76 void StartMemProfiler(common::ProfileThread& sched, common::JsonLogger& logger);
77 
78 } // namespace mem
79 } // namespace thrill
80 
81 #endif // !THRILL_MEM_MALLOC_TRACKER_HEADER
82 
83 /******************************************************************************/
void StartMemProfiler(common::ProfileThread &sched, common::JsonLogger &logger)
launch profiler task
void flush_memory_statistics()
method to flush thread-local memory statistics when memory_exceeded
void * bypass_aligned_alloc(size_t alignment, size_t size) noexcept
bypass malloc tracker and access aligned_alloc() directly
void set_memory_limit_indication(ssize_t size)
bool memory_exceeded
memory limit exceeded indicator
void bypass_aligned_free(void *ptr, size_t size) noexcept
bypass malloc tracker and access aligned_alloc() directly
void bypass_free(void *ptr, size_t size) noexcept
bypass malloc tracker and access free() directly
void malloc_tracker_reset_peak()
user function to reset the peak allocation to current
void malloc_tracker_print_status()
user function which prints current and peak allocation to stderr
ssize_t malloc_tracker_total_allocs()
user function to return total number of allocations
ssize_t malloc_tracker_current()
user function to return the currently allocated amount of memory
void malloc_tracker_print_leaks()
user function which prints new unfreed areas to stdout since the last call
void * bypass_malloc(size_t size) noexcept
bypass malloc tracker and access malloc() directly
ssize_t malloc_tracker_peak()
user function to return the peak allocation