Warning, /PerfTools/AllocMonitorPreload/README.md is written in an unsupported language. File is not indexed.
0001 # PerfTools/AllocMonitorPreload Description
0002
0003 ## Introduction
0004
0005 This package works with the [PerfTools/AllocMonitor](../AllocMonitor/README.md) package to provide a general facility to watch allocations and deallocations. See the README.md in that package for details on how to use the facility.
0006
0007 ## Technical Details
0008
0009 This package overrides the standard C and C++ allocation and deallocation functions. These overridden functions call the
0010 appropriate methods of `cms::perftools::AllocMonitorRegistry` to allow monitoring of memory allocations and
0011 deallocations. The overridden C and C++ standard methods use `dlsym` to find the original functions (i.e. what ever
0012 versions of those methods were compiled into the executable) and then call those original functions to do the actual
0013 allocation/deallocation.
0014
0015 To support standard library C++ on linux, one only needs to override the standard C methods to intercept all
0016 allocations/deallocations. However, to intercept calls for jemalloc or tcmalloc, one must also override the C++
0017 methods. This is complicated as one must call `dlsym` using the _mangled_ names of the C++ methods. As the exact
0018 mangled name can be different on different operating systems or CPU types the exact name used will have to be updated
0019 in this code to use different systems. `AllocMonitorRegistry` makes sure that if a standard function calls another
0020 standard function to do the actual work, that only one callback will be issued.
0021
0022 There is no C or C++ standard method one can call to ask how much actual memory is associated with a given address
0023 returned by an allocator. To provide such information, we use the GNU standard `malloc_usable_size` method. To have
0024 this facility support additional operating systems, an equivalent method would be needed.
0025
0026 The facility starts and stops calls to the `cms::perftools::AllocMonitorRegistry` via the use of the functions `alloc_monitor_start` and `alloc_monitor_stop`. The `AllocMonitorRegistry` use `dlsym` to locate these methods (avoiding link
0027 time dependencies with this package) and if the method is not available by the first request to register a monitor the
0028 code throws an exception. The destructor of `AllocMonitorRegistry` calls the stop method. In this way, the facility can
0029 never call methods on `AllocMonitorRegistry` when the registry is not available.
0030