Logo ROOT  
Reference Guide
TMemStatMng.h
Go to the documentation of this file.
1 // @(#)root/memstat:$Id$
2 // Author: Anar Manafov (A.Manafov@gsi.de) 2008-03-02
3 
4 /*************************************************************************
5 * Copyright (C) 1995-2010, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11 #ifndef ROOT_TMemStatMng
12 #define ROOT_TMemStatMng
13 
14 // STD
15 #include <map>
16 #include <cstring>
17 // ROOT
18 #include "TObject.h"
19 #include "TTimeStamp.h"
20 // Memstat
21 #include "TMemStatHook.h"
22 #include "TMemStatDef.h"
23 
24 class TTree;
25 class TFile;
26 class TH1I;
27 class TObjArray;
28 
29 namespace Memstat {
30 
32  typedef std::map<ULong_t, Int_t> Container_t;
33  typedef Container_t::iterator pos_type;
34  typedef Container_t::value_type value_type;
35 
36  public:
37  bool add(ULong_t addr, Int_t idx) {
38  std::pair<pos_type, bool> ret = fContainer.insert(value_type(addr, idx));
39  return (ret.second);
40  }
41 
42  Int_t find(ULong_t addr) {
43  pos_type iter = fContainer.find(addr);
44  if(fContainer.end() == iter)
45  return -1;
46 
47  return iter->second;
48  }
49 
50  private:
52  };
53 
54  const UShort_t g_digestSize = 16;
55  struct SCustomDigest {
57  memset(fValue, 0, g_digestSize);
58  }
60  memcpy(fValue, _val, g_digestSize);
61  }
62 
64  };
65  inline bool operator< (const SCustomDigest &a, const SCustomDigest &b)
66  {
67  for(int i = 0; i < g_digestSize; ++i) {
68  if(a.fValue[i] != b.fValue[i])
69  return (a.fValue[i] < b.fValue[i]);
70  }
71  return false;
72  }
73 
74 
75  class TMemStatMng: public TObject {
76  typedef std::map<SCustomDigest, Int_t> CRCSet_t;
77 
78  private:
79  TMemStatMng();
80  virtual ~TMemStatMng();
81 
82  public:
83  void Enable(); //enable memory statistic
84  void Disable(); //Disable memory statistic
85  static TMemStatMng* GetInstance(); //get instance of class - ONLY ONE INSTANCE
86  static void Close(); //close MemStatManager
87  void SetBufferSize(Int_t buffersize);
88  void SetMaxCalls(Int_t maxcalls);
89 
90  public:
91  //stack data members
93  fUseGNUBuiltinBacktrace = newVal;
94  }
95 
96  protected:
97 #if !defined(__APPLE__)
100 #endif
101  void Init();
102  void AddPointer(void *ptr, Int_t size); //add pointer to the table
103  void FillTree();
104  static void *AllocHook(size_t size, const void* /*caller*/);
105  static void FreeHook(void* ptr, const void* /*caller*/);
106  static void MacAllocHook(void *ptr, size_t size);
107  static void MacFreeHook(void *ptr);
108  Int_t generateBTID(UChar_t *CRCdigest, Int_t stackEntries,
109  void **stackPointers);
110 
111 
112  // memory information
113  TFile* fDumpFile; //!file to dump current information
114  TTree *fDumpTree; //!tree to dump information
115  static TMemStatMng *fgInstance; // pointer to instance
116  static void *fgStackTop; // stack top pointer
117 
120  Double_t fBeginTime; //time when monitoring starts
121  ULong64_t fPos; //position in memory where alloc/free happens
122  Int_t fTimems; //10000*(current time - begin time)
123  Int_t fNBytes; //number of bytes allocated/freed
124  Int_t fBtID; //back trace identifier
125  Int_t fMaxCalls; //max number of malloc/frees to register in the output Tree
126  Int_t fBufferSize; //max number of malloc/free to keep in the buffer
127  Int_t fBufN; //current number of alloc or free in the buffer
128  ULong64_t *fBufPos; //position in memory where alloc/free happens
129  Int_t *fBufTimems; //10000*(current time - begin time)
130  Int_t *fBufNBytes; //number of bytes allocated/freed
131  Int_t *fBufBtID; //back trace identifier
132  Int_t *fIndex; //array to sort fBufPos
133  Bool_t *fMustWrite; //flag to write or not the entry
134 
135  private:
141  // for Debug. A counter of all (de)allacations.
144 
145  ClassDef(TMemStatMng, 0) // a manager of memstat sessions.
146  };
147 
148 }
149 
150 #endif
Memstat::TMemStatMng::fBufBtID
Int_t * fBufBtID
Definition: TMemStatMng.h:131
Memstat::TMemStatMng::fgStackTop
static void * fgStackTop
Definition: TMemStatMng.h:116
Memstat::TMemStatFAddrContainer::fContainer
Container_t fContainer
Definition: TMemStatMng.h:51
Memstat::TMemStatMng::fDumpTree
TTree * fDumpTree
file to dump current information
Definition: TMemStatMng.h:114
Memstat::TMemStatMng::fDumpFile
TFile * fDumpFile
Definition: TMemStatMng.h:113
TObjArray
Definition: TObjArray.h:37
Memstat::TMemStatMng::fBTCount
Int_t fBTCount
Definition: TMemStatMng.h:140
Memstat::TMemStatFAddrContainer::Container_t
std::map< ULong_t, Int_t > Container_t
Definition: TMemStatMng.h:32
Memstat::TMemStatMng::fBTChecksums
CRCSet_t fBTChecksums
Definition: TMemStatMng.h:139
UShort_t
unsigned short UShort_t
Definition: RtypesCore.h:40
Memstat::TMemStatMng::fIndex
Int_t * fIndex
Definition: TMemStatMng.h:132
TH1I
1-D histogram with an int per channel (see TH1 documentation)}
Definition: TH1.h:531
Memstat::TMemStatMng::generateBTID
Int_t generateBTID(UChar_t *CRCdigest, Int_t stackEntries, void **stackPointers)
An internal function, which returns a bitid for a corresponding CRC digest cache variables.
Definition: TMemStatMng.cxx:343
TTimeStamp.h
Memstat::TMemStatMng::Close
static void Close()
Close - a static function This method stops the manager, flashes all the buffered data and closes the...
Definition: TMemStatMng.cxx:132
TTree
Definition: TTree.h:79
Memstat::TMemStatFAddrContainer::pos_type
Container_t::iterator pos_type
Definition: TMemStatMng.h:33
Memstat::TMemStatMng::fBufferSize
Int_t fBufferSize
Definition: TMemStatMng.h:126
Memstat::TMemStatMng::AddPointer
void AddPointer(void *ptr, Int_t size)
Add pointer to table.
Definition: TMemStatMng.cxx:430
Memstat::TMemStatMng
Definition: TMemStatMng.h:75
Memstat::TMemStatMng::MacAllocHook
static void MacAllocHook(void *ptr, size_t size)
AllocHook - a static function a special memory hook for Mac OS X memory zones.
Definition: TMemStatMng.cxx:266
Memstat::g_digestSize
const UShort_t g_digestSize
Definition: TMemStatMng.h:54
b
#define b(i)
Definition: RSha256.hxx:118
bool
Memstat::TMemStatMng::SetMaxCalls
void SetMaxCalls(Int_t maxcalls)
Set the maximum number of new/delete registered in the output Tree.
Definition: TMemStatMng.cxx:223
Memstat::TMemStatFAddrContainer::find
Int_t find(ULong_t addr)
Definition: TMemStatMng.h:42
Memstat::TMemStatMng::fPos
ULong64_t fPos
Definition: TMemStatMng.h:121
Memstat
Definition: TMemStatBacktrace.h:22
Memstat::TMemStatMng::Disable
void Disable()
Disble memory hooks.
Definition: TMemStatMng.cxx:247
Memstat::TMemStatMng::fTimeStamp
TTimeStamp fTimeStamp
Definition: TMemStatMng.h:119
Memstat::SCustomDigest
Definition: TMemStatMng.h:55
Memstat::TMemStatMng::fSysInfo
TNamed * fSysInfo
Definition: TMemStatMng.h:143
Memstat::TMemStatFAddrContainer
Definition: TMemStatMng.h:31
Memstat::TMemStatMng::fBeginTime
Double_t fBeginTime
Definition: TMemStatMng.h:120
a
auto * a
Definition: textangle.C:12
TNamed
Definition: TNamed.h:29
Memstat::TMemStatMng::fTimems
Int_t fTimems
Definition: TMemStatMng.h:122
Memstat::TMemStatMng::fUseGNUBuiltinBacktrace
Bool_t fUseGNUBuiltinBacktrace
Definition: TMemStatMng.h:118
Memstat::TMemStatMng::fBTIDCount
UInt_t fBTIDCount
Definition: TMemStatMng.h:142
Memstat::TMemStatMng::fPreviousMallocHook
TMemStatHook::MallocHookFunc_t fPreviousMallocHook
Definition: TMemStatMng.h:98
Memstat::operator<
bool operator<(const SCustomDigest &a, const SCustomDigest &b)
Definition: TMemStatMng.h:65
Memstat::TMemStatMng::fFAddrs
TMemStatFAddrContainer fFAddrs
Definition: TMemStatMng.h:136
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
Memstat::TMemStatMng::SetBufferSize
void SetBufferSize(Int_t buffersize)
Set the maximum number of alloc/free calls to be buffered.
Definition: TMemStatMng.cxx:207
Memstat::TMemStatFAddrContainer::value_type
Container_t::value_type value_type
Definition: TMemStatMng.h:34
Memstat::TMemStatFAddrContainer::add
bool add(ULong_t addr, Int_t idx)
Definition: TMemStatMng.h:37
Memstat::TMemStatMng::fBufNBytes
Int_t * fBufNBytes
Definition: TMemStatMng.h:130
TFile
Definition: TFile.h:54
Memstat::SCustomDigest::SCustomDigest
SCustomDigest()
Definition: TMemStatMng.h:56
unsigned int
Memstat::TMemStatMng::fNBytes
Int_t fNBytes
Definition: TMemStatMng.h:123
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
Double_t
double Double_t
Definition: RtypesCore.h:59
Memstat::TMemStatMng::FillTree
void FillTree()
loop on all entries in the buffer and fill the output Tree entries with alloc and free in the buffer ...
Definition: TMemStatMng.cxx:466
TObject.h
Memstat::TMemStatMng::fBufN
Int_t fBufN
Definition: TMemStatMng.h:127
Memstat::TMemStatMng::FreeHook
static void FreeHook(void *ptr, const void *)
FreeHook - a static function A glibc memory deallocation hook.
Definition: TMemStatMng.cxx:323
UChar_t
unsigned char UChar_t
Definition: RtypesCore.h:38
Memstat::TMemStatMng::MacFreeHook
static void MacFreeHook(void *ptr)
AllocHook - a static function a special memory hook for Mac OS X memory zones.
Definition: TMemStatMng.cxx:284
Memstat::TMemStatMng::Enable
void Enable()
Enable memory hooks.
Definition: TMemStatMng.cxx:231
TMemStatHook::MallocHookFunc_t
void *(* MallocHookFunc_t)(size_t size, const void *caller)
Definition: TMemStatHook.h:41
Memstat::TMemStatMng::AllocHook
static void * AllocHook(size_t size, const void *)
AllocHook - a static function A glibc memory allocation hook.
Definition: TMemStatMng.cxx:301
TObject
Definition: TObject.h:37
Memstat::TMemStatMng::fFAddrsList
TObjArray * fFAddrsList
Definition: TMemStatMng.h:137
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
Memstat::TMemStatMng::~TMemStatMng
virtual ~TMemStatMng()
if an instance is destructed - the hooks are reseted to old hooks
Definition: TMemStatMng.cxx:191
Memstat::TMemStatMng::fBtID
Int_t fBtID
Definition: TMemStatMng.h:124
Memstat::TMemStatMng::SetUseGNUBuiltinBacktrace
void SetUseGNUBuiltinBacktrace(Bool_t newVal)
Definition: TMemStatMng.h:92
Memstat::TMemStatMng::fBufTimems
Int_t * fBufTimems
Definition: TMemStatMng.h:129
Memstat::TMemStatMng::CRCSet_t
std::map< SCustomDigest, Int_t > CRCSet_t
Definition: TMemStatMng.h:76
Memstat::TMemStatMng::fHbtids
TH1I * fHbtids
Definition: TMemStatMng.h:138
Memstat::TMemStatMng::fMaxCalls
Int_t fMaxCalls
Definition: TMemStatMng.h:125
Memstat::TMemStatMng::GetInstance
static TMemStatMng * GetInstance()
GetInstance - a static function Initialize a singleton of MemStat manager.
Definition: TMemStatMng.cxx:118
Memstat::SCustomDigest::SCustomDigest
SCustomDigest(UChar_t _val[g_digestSize])
Definition: TMemStatMng.h:59
TMemStatHook.h
TTimeStamp
Definition: TTimeStamp.h:71
TMemStatHook::FreeHookFunc_t
void(* FreeHookFunc_t)(void *ptr, const void *caller)
Definition: TMemStatHook.h:42
TMemStatDef.h
Memstat::SCustomDigest::fValue
UChar_t fValue[g_digestSize]
Definition: TMemStatMng.h:63
Memstat::TMemStatMng::Init
void Init()
old free function
Definition: TMemStatMng.cxx:73
Memstat::TMemStatMng::fPreviousFreeHook
TMemStatHook::FreeHookFunc_t fPreviousFreeHook
old malloc function
Definition: TMemStatMng.h:99
Memstat::TMemStatMng::TMemStatMng
TMemStatMng()
Definition: TMemStatMng.cxx:38
Memstat::TMemStatMng::fBufPos
ULong64_t * fBufPos
Definition: TMemStatMng.h:128
Memstat::TMemStatMng::fgInstance
static TMemStatMng * fgInstance
tree to dump information
Definition: TMemStatMng.h:115
int
Memstat::TMemStatMng::fMustWrite
Bool_t * fMustWrite
Definition: TMemStatMng.h:133