timemory  3.2.1
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 ()
 

Static Public Attributes

static constexpr size_t data_size = 3
 

Detailed Description

Definition at line 52 of file memory_allocations.hpp.

Member Typedef Documentation

◆ base_type

◆ component_type

template<typename Tp >
using tim::component::malloc_gotcha::component_type = push_back_t<Tp, gotcha_type<Tp> >

Definition at line 94 of file memory_allocations.hpp.

◆ gotcha_component_type

Definition at line 87 of file memory_allocations.hpp.

◆ gotcha_type

◆ storage_type

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

Definition at line 65 of file memory_allocations.hpp.

◆ string_hash

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

Definition at line 66 of file memory_allocations.hpp.

◆ this_type

◆ value_type

Definition at line 62 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 129 of file memory_allocations.hpp.

130  {
131  DEBUG_PRINT_HERE("%s(%i)", m_prefix, (int) nbytes);
132  // malloc
133  value = (nbytes);
134  DEBUG_PRINT_HERE("value: %12.8f, accum: %12.8f", value, accum);
135  }
#define DEBUG_PRINT_HERE(...)
Definition: macros.hpp:163

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 138 of file memory_allocations.hpp.

139  {
140  DEBUG_PRINT_HERE("%s(%i, %i)", m_prefix, (int) nmemb, (int) size);
141  // calloc
142  value = (nmemb * size);
143  DEBUG_PRINT_HERE("value: %12.8f, accum: %12.8f", value, accum);
144  }

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 158 of file memory_allocations.hpp.

159  {
160  DEBUG_PRINT_HERE("%s(%p)", m_prefix, ptr);
161  auto itr = get_allocation_map().find(ptr);
162  if(itr != get_allocation_map().end())
163  {
164  value = itr->second;
165  DEBUG_PRINT_HERE("value: %12.8f, accum: %12.8f", value, accum);
166  get_allocation_map().erase(itr);
167  }
168  else
169  {
170  if(settings::verbose() > 1 || settings::debug())
171  {
172  printf("[%s]> free of unknown pointer size: %p\n",
173  this_type::get_label().c_str(), ptr);
174  }
175  }
176  }

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 147 of file memory_allocations.hpp.

148  {
149  DEBUG_PRINT_HERE("%s(%p)", m_prefix, ptr);
150  if(ptr)
151  {
152  get_allocation_map()[ptr] = value;
153  DEBUG_PRINT_HERE("value: %12.8f, accum: %12.8f", value, accum);
154  }
155  }

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 70 of file memory_allocations.hpp.

71  {
72 #if defined(TIMEMORY_USE_CUDA)
73  return "GOTCHA wrapper for memory allocation functions: malloc, calloc, free, "
74  "cudaMalloc, cudaMallocHost, cudaMallocManaged, cudaHostAlloc, cudaFree, "
75  "cudaFreeHost";
76 #else
77  return "GOTCHA wrapper for memory allocation functions: malloc, calloc, free";
78 #endif
79  }

◆ get()

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

Definition at line 122 of file memory_allocations.hpp.

122 { 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 124 of file memory_allocations.hpp.

124 { return get(); }

References get().

◆ global_finalize()

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

Definition at line 96 of file memory_allocations.hpp.

97  {
98  for(auto& itr : get_cleanup_list())
99  itr();
100  get_cleanup_list().clear();
101  }

◆ label()

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

Definition at line 69 of file memory_allocations.hpp.

69 { return "malloc_gotcha"; }

◆ operator+=()

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

Definition at line 228 of file memory_allocations.hpp.

229  {
230  value += rhs.value;
231  accum += rhs.accum;
232  return *this;
233  }

◆ operator-=()

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

Definition at line 237 of file memory_allocations.hpp.

238  {
239  value -= rhs.value;
240  accum -= rhs.accum;
241  return *this;
242  }

◆ 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 224 of file memory_allocations.hpp.

224 { m_prefix = _prefix; }
char const std::string & _prefix
Definition: definition.hpp:59

References tim::_prefix.

◆ start()

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

Definition at line 114 of file memory_allocations.hpp.

114 { value = 0; }

◆ stop()

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

Definition at line 116 of file memory_allocations.hpp.

117  {
118  // value should be updated via audit in-between start() and stop()
119  accum += value;
120  }

◆ 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 59 of file memory_allocations.hpp.


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