timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::component::malloc_gotcha Struct Reference

#include "timemory/components/gotcha/memory_allocations.hpp"

+ Collaboration diagram for tim::component::malloc_gotcha:

Public Types

using value_type = double
 
using this_type = malloc_gotcha
 
using base_type = base< this_type, value_type >
 
using storage_type = typename base_type::storage_type
 
using string_hash = std::hash< std::string >
 
template<typename Tp >
using gotcha_component_type = push_back_t< Tp, this_type >
 
template<typename Tp >
using gotcha_type = gotcha< data_size, push_back_t< Tp, this_type >, type_list< this_type > >
 
template<typename Tp >
using component_type = push_back_t< Tp, gotcha_type< Tp > >
 

Public Member Functions

void start ()
 
void stop ()
 
double get () const
 
double get_display () const
 
void set_prefix ()
 
void audit (audit::incoming, size_t nbytes)
 nbytes is passed to malloc More...
 
void audit (audit::incoming, size_t nmemb, size_t size)
 nmemb and size is passed to calloc More...
 
void audit (audit::outgoing, void *ptr)
 void* is returned from malloc and calloc More...
 
void audit (audit::incoming, void *ptr)
 void* is passed to free More...
 
void set_prefix (const char *_prefix)
 
this_typeoperator+= (const this_type &rhs)
 
this_typeoperator-= (const this_type &rhs)
 

Static Public Member Functions

static std::string label ()
 
static std::string description ()
 
static void global_finalize ()
 
template<typename Tp >
static void configure ()
 
template<typename Tp >
static void tear_down ()
 
template<typename... Args>
static opaque get_opaque (Args &&...)
 

Static Public Attributes

static constexpr size_t data_size = 3
 

Detailed Description

Definition at line 53 of file memory_allocations.hpp.

Member Typedef Documentation

◆ base_type

◆ component_type

Definition at line 99 of file memory_allocations.hpp.

◆ gotcha_component_type

◆ gotcha_type

◆ storage_type

using tim::component::malloc_gotcha::storage_type = typename base_type::storage_type

Definition at line 66 of file memory_allocations.hpp.

◆ string_hash

using tim::component::malloc_gotcha::string_hash = std::hash<std::string>

Definition at line 67 of file memory_allocations.hpp.

◆ this_type

◆ value_type

Definition at line 63 of file memory_allocations.hpp.

Member Function Documentation

◆ audit() [1/4]

void tim::component::malloc_gotcha::audit ( audit::incoming  ,
size_t  nbytes 
)
inline

nbytes is passed to malloc

Definition at line 134 of file memory_allocations.hpp.

135 {
136 DEBUG_PRINT_HERE("%s(%i)", m_prefix, (int) nbytes);
137 // malloc
138 value = (nbytes);
139 DEBUG_PRINT_HERE("value: %12.8f, accum: %12.8f", value, accum);
140 }
#define DEBUG_PRINT_HERE(...)
Definition: macros.hpp:168

References DEBUG_PRINT_HERE.

◆ audit() [2/4]

void tim::component::malloc_gotcha::audit ( audit::incoming  ,
size_t  nmemb,
size_t  size 
)
inline

nmemb and size is passed to calloc

Definition at line 143 of file memory_allocations.hpp.

144 {
145 DEBUG_PRINT_HERE("%s(%i, %i)", m_prefix, (int) nmemb, (int) size);
146 // calloc
147 value = (nmemb * size);
148 DEBUG_PRINT_HERE("value: %12.8f, accum: %12.8f", value, accum);
149 }

References DEBUG_PRINT_HERE.

◆ audit() [3/4]

void tim::component::malloc_gotcha::audit ( audit::incoming  ,
void *  ptr 
)
inline

void* is passed to free

Definition at line 163 of file memory_allocations.hpp.

164 {
165 DEBUG_PRINT_HERE("%s(%p)", m_prefix, ptr);
166 auto itr = get_allocation_map().find(ptr);
167 if(itr != get_allocation_map().end())
168 {
169 value = itr->second;
170 DEBUG_PRINT_HERE("value: %12.8f, accum: %12.8f", value, accum);
171 get_allocation_map().erase(itr);
172 }
173 else
174 {
176 {
177 printf("[%s]> free of unknown pointer size: %p\n",
178 this_type::get_label().c_str(), ptr);
179 }
180 }
181 }
return _hash_map end()

References tim::debug, DEBUG_PRINT_HERE, tim::component::base< malloc_gotcha, double >::get_label(), and tim::verbose.

◆ audit() [4/4]

void tim::component::malloc_gotcha::audit ( audit::outgoing  ,
void *  ptr 
)
inline

void* is returned from malloc and calloc

Definition at line 152 of file memory_allocations.hpp.

153 {
154 DEBUG_PRINT_HERE("%s(%p)", m_prefix, ptr);
155 if(ptr)
156 {
157 get_allocation_map()[ptr] = value;
158 DEBUG_PRINT_HERE("value: %12.8f, accum: %12.8f", value, accum);
159 }
160 }

References DEBUG_PRINT_HERE.

◆ configure()

template<typename Tp >
static void tim::component::malloc_gotcha::configure ( )
static

◆ description()

static std::string tim::component::malloc_gotcha::description ( )
inlinestatic

Definition at line 71 of file memory_allocations.hpp.

72 {
73#if defined(TIMEMORY_USE_CUDA)
74 return "GOTCHA wrapper for memory allocation functions: malloc, calloc, free, "
75 "cudaMalloc, cudaMallocHost, cudaMallocManaged, cudaHostAlloc, cudaFree, "
76 "cudaFreeHost";
77#elif defined(TIMEMORY_USE_HIP)
78 return "GOTCHA wrapper for memory allocation functions: malloc, calloc, free, "
79 "hipMalloc, hipMallocHost, hipMallocManaged, hipHostAlloc, hipFree, "
80 "hipFreeHost";
81#else
82 return "GOTCHA wrapper for memory allocation functions: malloc, calloc, free";
83#endif
84 }

◆ get()

double tim::component::malloc_gotcha::get ( ) const
inline

Definition at line 127 of file memory_allocations.hpp.

127{ return accum / base_type::get_unit(); }
static int64_t get_unit()

References tim::component::base< Tp, Value >::get_unit().

Referenced by get_display().

◆ get_display()

double tim::component::malloc_gotcha::get_display ( ) const
inline

Definition at line 129 of file memory_allocations.hpp.

129{ return get(); }

References get().

◆ get_opaque()

template<typename... Args>
static opaque tim::component::empty_base::get_opaque ( Args &&  ...)
inlinestaticinherited

Definition at line 72 of file declaration.hpp.

73 {
74 return opaque{};
75 }

◆ global_finalize()

static void tim::component::malloc_gotcha::global_finalize ( )
inlinestatic

Definition at line 101 of file memory_allocations.hpp.

102 {
103 for(auto& itr : get_cleanup_list())
104 itr();
105 get_cleanup_list().clear();
106 }

◆ label()

static std::string tim::component::malloc_gotcha::label ( )
inlinestatic

Definition at line 70 of file memory_allocations.hpp.

70{ return "malloc_gotcha"; }

◆ operator+=()

this_type & tim::component::malloc_gotcha::operator+= ( const this_type rhs)
inline

Definition at line 236 of file memory_allocations.hpp.

237 {
238 value += rhs.value;
239 accum += rhs.accum;
240 return *this;
241 }

◆ operator-=()

this_type & tim::component::malloc_gotcha::operator-= ( const this_type rhs)
inline

Definition at line 245 of file memory_allocations.hpp.

246 {
247 value -= rhs.value;
248 accum -= rhs.accum;
249 return *this;
250 }

◆ set_prefix() [1/2]

void tim::component::malloc_gotcha::set_prefix ( )

◆ set_prefix() [2/2]

void tim::component::malloc_gotcha::set_prefix ( const char *  _prefix)
inline

Definition at line 232 of file memory_allocations.hpp.

232{ m_prefix = _prefix; }
char const std::string & _prefix
Definition: config.cpp:55

References tim::_prefix.

◆ start()

void tim::component::malloc_gotcha::start ( )
inline

Definition at line 119 of file memory_allocations.hpp.

119{ value = 0; }

◆ stop()

void tim::component::malloc_gotcha::stop ( )
inline

Definition at line 121 of file memory_allocations.hpp.

122 {
123 // value should be updated via audit in-between start() and stop()
124 accum += value;
125 }

◆ tear_down()

template<typename Tp >
static void tim::component::malloc_gotcha::tear_down ( )
static

Member Data Documentation

◆ data_size

constexpr size_t tim::component::malloc_gotcha::data_size = 3
staticconstexpr

Definition at line 60 of file memory_allocations.hpp.


The documentation for this struct was generated from the following file: