ATLAS Offline Software
Static Public Member Functions | Static Public Attributes | List of all members
PerfMon::MemStats Struct Reference

placeholder for the stats More...

#include <MemStatsHooks.h>

Collaboration diagram for PerfMon::MemStats:

Static Public Member Functions

static bool enable (const bool flag)
 switch to enable or disable the global malloc hooks More...
 
static void installHooks ()
 install our hooks More...
 
static void uninstallHooks ()
 uninstall our hooks More...
 
static void saveHooks ()
 save current hooks More...
 
static bool enabled ()
 return the current flag value More...
 
static unsigned long long nbytes ()
 return the number of bytes allocated so far More...
 
static unsigned long long nmallocs ()
 return the number of times malloc has been called so far More...
 
static unsigned long long nfrees ()
 return the number of times free has been called so far More...
 
static void start ()
 initialize library More...
 
static void stop ()
 finalize library More...
 

Static Public Attributes

static std::atomic< bool > m_enabled = false
 flag disabling or enabling the global malloc hooks More...
 
static unsigned long long m_nbytes ATLAS_THREAD_SAFE
 number of bytes allocated so far More...
 
static unsigned long long m_nmallocs ATLAS_THREAD_SAFE
 number of times malloc has been called so far More...
 
static unsigned long long m_nfrees ATLAS_THREAD_SAFE
 number of times free has been called so far More...
 

Detailed Description

placeholder for the stats

Definition at line 32 of file MemStatsHooks.h.

Member Function Documentation

◆ enable()

static bool PerfMon::MemStats::enable ( const bool  flag)
inlinestatic

switch to enable or disable the global malloc hooks

Returns
the old value of the flag

Definition at line 48 of file MemStatsHooks.h.

49  {
50  bool old_value = m_enabled;
51  m_enabled = flag;
52  return old_value;
53  }

◆ enabled()

static bool PerfMon::MemStats::enabled ( )
inlinestatic

return the current flag value

Definition at line 65 of file MemStatsHooks.h.

65 { return m_enabled; }

◆ installHooks()

void PerfMon::MemStats::installHooks ( )
static

install our hooks

Definition at line 100 of file MemStatsHooks.cxx.

101 {
102 #if HAVE_MALLOC_HOOKS
103  __free_hook = pmon_mem_free;
104  __realloc_hook = pmon_mem_realloc;
105  __malloc_hook = pmon_mem_malloc;
106 #endif
107  pthread_mutex_unlock(&pmon_mem_lock);
108 }

◆ nbytes()

static unsigned long long PerfMon::MemStats::nbytes ( )
inlinestatic

return the number of bytes allocated so far

Definition at line 67 of file MemStatsHooks.h.

67 { return m_nbytes; }

◆ nfrees()

static unsigned long long PerfMon::MemStats::nfrees ( )
inlinestatic

return the number of times free has been called so far

Definition at line 71 of file MemStatsHooks.h.

71 { return m_nfrees; }

◆ nmallocs()

static unsigned long long PerfMon::MemStats::nmallocs ( )
inlinestatic

return the number of times malloc has been called so far

Definition at line 69 of file MemStatsHooks.h.

69 { return m_nmallocs; }

◆ saveHooks()

void PerfMon::MemStats::saveHooks ( )
static

save current hooks

Definition at line 120 of file MemStatsHooks.cxx.

121 {
122 #if HAVE_MALLOC_HOOKS
123  // store old hooks in buffer for reset later
124  // prevent storing ourselves in case of a double-call by user
125  if ( __malloc_hook != pmon_mem_malloc ) {
126  orig_malloc = __malloc_hook;
127  }
128 
129  if ( __realloc_hook != pmon_mem_realloc ) {
130  orig_realloc = __realloc_hook;
131  }
132 
133  if ( __free_hook != pmon_mem_free ) {
134  orig_free = __free_hook;
135  }
136 #endif
137 
138  return;
139 }

◆ start()

void PerfMon::MemStats::start ( )
static

initialize library

Definition at line 70 of file MemStatsHooks.cxx.

71 {
72  if (0 != pthread_mutex_init(&pmon_mem_lock, NULL)) {
73  throw std::runtime_error("perfmon: could not initialize pthread mutex");
74  }
75  pthread_mutex_lock(&pmon_mem_lock);
76  saveHooks();
78  installHooks();
79  } else {
80  // installHooks unlocks the mutex...
81  pthread_mutex_unlock(&pmon_mem_lock);
82  }
83 }

◆ stop()

void PerfMon::MemStats::stop ( )
static

finalize library

Definition at line 85 of file MemStatsHooks.cxx.

86 {
87  // we actually don't want to ever un-install the hooks as
88  // this might break daisy chains of hooks: if our hooks were installed first
89  // uninstalling them will put the NULL ones back in, and won't give a chance
90  // for later-registered hooks to do their properly afterwards.
91 
92  // if (PerfMon::MemStats::m_enabled) {
93  // uninstallHooks();
94  // }
95  if (0 != pthread_mutex_destroy(&pmon_mem_lock)) {
96  throw std::runtime_error("perfmon: could not destroy pthread mutex");
97  }
98 }

◆ uninstallHooks()

void PerfMon::MemStats::uninstallHooks ( )
static

uninstall our hooks

Definition at line 110 of file MemStatsHooks.cxx.

111 {
112  pthread_mutex_lock(&pmon_mem_lock);
113 #if HAVE_MALLOC_HOOKS
114  __free_hook = orig_free;
115  __realloc_hook = orig_realloc;
116  __malloc_hook = orig_malloc;
117 #endif
118 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/3]

unsigned long long m_nbytes PerfMon::MemStats::ATLAS_THREAD_SAFE
static

number of bytes allocated so far

Definition at line 38 of file MemStatsHooks.h.

◆ ATLAS_THREAD_SAFE [2/3]

unsigned long long m_nmallocs PerfMon::MemStats::ATLAS_THREAD_SAFE
static

number of times malloc has been called so far

Definition at line 41 of file MemStatsHooks.h.

◆ ATLAS_THREAD_SAFE [3/3]

unsigned long long m_nfrees PerfMon::MemStats::ATLAS_THREAD_SAFE
static

number of times free has been called so far

Definition at line 44 of file MemStatsHooks.h.

◆ m_enabled

std::atomic< bool > PerfMon::MemStats::m_enabled = false
static

flag disabling or enabling the global malloc hooks

Definition at line 35 of file MemStatsHooks.h.


The documentation for this struct was generated from the following files:
PerfMon::MemStats::saveHooks
static void saveHooks()
save current hooks
Definition: MemStatsHooks.cxx:120
master.flag
bool flag
Definition: master.py:29
PerfMon::MemStats::m_enabled
static std::atomic< bool > m_enabled
flag disabling or enabling the global malloc hooks
Definition: MemStatsHooks.h:35
PerfMon::MemStats::installHooks
static void installHooks()
install our hooks
Definition: MemStatsHooks.cxx:100