Logo ROOT   master
Reference Guide
Go to the documentation of this file.
1 // @(#)root/memstat:$Id$
2 // Author: Anar Manafov (A.Manafov@gsi.de) 2008-03-02
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
14 // STD
15 #include <map>
16 // ROOT
17 #include "TObject.h"
18 #include "TTimeStamp.h"
19 // Memstat
20 #include "TMemStatHook.h"
21 #include "TMemStatDef.h"
23 class TTree;
24 class TFile;
25 class TH1I;
26 class TObjArray;
28 namespace Memstat {
31  typedef std::map<ULong_t, Int_t> Container_t;
32  typedef Container_t::iterator pos_type;
33  typedef Container_t::value_type value_type;
35  public:
36  bool add(ULong_t addr, Int_t idx) {
37  std::pair<pos_type, bool> ret = fContainer.insert(value_type(addr, idx));
38  return (ret.second);
39  }
41  Int_t find(ULong_t addr) {
42  pos_type iter = fContainer.find(addr);
43  if(fContainer.end() == iter)
44  return -1;
46  return iter->second;
47  }
49  private:
51  };
53  const UShort_t g_digestSize = 16;
54  struct SCustomDigest {
56  memset(fValue, 0, g_digestSize);
57  }
59  memcpy(fValue, _val, g_digestSize);
60  }
63  };
64  inline bool operator< (const SCustomDigest &a, const SCustomDigest &b)
65  {
66  for(int i = 0; i < g_digestSize; ++i) {
67  if(a.fValue[i] != b.fValue[i])
68  return (a.fValue[i] < b.fValue[i]);
69  }
70  return false;
71  }
74  class TMemStatMng: public TObject {
75  typedef std::map<SCustomDigest, Int_t> CRCSet_t;
77  private:
78  TMemStatMng();
79  virtual ~TMemStatMng();
81  public:
82  void Enable(); //enable memory statistic
83  void Disable(); //Disable memory statistic
84  static TMemStatMng* GetInstance(); //get instance of class - ONLY ONE INSTANCE
85  static void Close(); //close MemStatManager
86  void SetBufferSize(Int_t buffersize);
87  void SetMaxCalls(Int_t maxcalls);
89  public:
90  //stack data members
92  fUseGNUBuiltinBacktrace = newVal;
93  }
95  protected:
96 #if !defined(__APPLE__)
99 #endif
100  void Init();
101  void AddPointer(void *ptr, Int_t size); //add pointer to the table
102  void FillTree();
103  static void *AllocHook(size_t size, const void* /*caller*/);
104  static void FreeHook(void* ptr, const void* /*caller*/);
105  static void MacAllocHook(void *ptr, size_t size);
106  static void MacFreeHook(void *ptr);
107  Int_t generateBTID(UChar_t *CRCdigest, Int_t stackEntries,
108  void **stackPointers);
111  // memory information
112  TFile* fDumpFile; //!file to dump current information
113  TTree *fDumpTree; //!tree to dump information
114  static TMemStatMng *fgInstance; // pointer to instance
115  static void *fgStackTop; // stack top pointer
119  Double_t fBeginTime; //time when monitoring starts
120  ULong64_t fPos; //position in memory where alloc/free happens
121  Int_t fTimems; //10000*(current time - begin time)
122  Int_t fNBytes; //number of bytes allocated/freed
123  Int_t fBtID; //back trace identifier
124  Int_t fMaxCalls; //max number of malloc/frees to register in the output Tree
125  Int_t fBufferSize; //max number of malloc/free to keep in the buffer
126  Int_t fBufN; //current number of alloc or free in the buffer
127  ULong64_t *fBufPos; //position in memory where alloc/free happens
128  Int_t *fBufTimems; //10000*(current time - begin time)
129  Int_t *fBufNBytes; //number of bytes allocated/freed
130  Int_t *fBufBtID; //back trace identifier
131  Int_t *fIndex; //array to sort fBufPos
132  Bool_t *fMustWrite; //flag to write or not the entry
134  private:
140  // for Debug. A counter of all (de)allacations.
144  ClassDef(TMemStatMng, 0) // a manager of memstat sessions.
145  };
147 }
149 #endif
void SetMaxCalls(Int_t maxcalls)
Set the maximum number of new/delete registered in the output Tree.
bool add(ULong_t addr, Int_t idx)
Definition: TMemStatMng.h:36
void Enable()
Enable memory hooks.
An array of TObjects.
Definition: TObjArray.h:37
ULong64_t * fBufPos
Definition: TMemStatMng.h:127
void FillTree()
loop on all entries in the buffer and fill the output Tree entries with alloc and free in the buffer ...
void SetUseGNUBuiltinBacktrace(Bool_t newVal)
Definition: TMemStatMng.h:91
static TMemStatMng * fgInstance
tree to dump information
Definition: TMemStatMng.h:114
static void Close()
Close - a static function This method stops the manager, flashes all the buffered data and closes the...
unsigned short UShort_t
Definition: RtypesCore.h:36
static void * AllocHook(size_t size, const void *)
AllocHook - a static function A glibc memory allocation hook.
const UShort_t g_digestSize
Definition: TMemStatMng.h:53
TObjArray * fFAddrsList
Definition: TMemStatMng.h:136
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:48
TTimeStamp fTimeStamp
Definition: TMemStatMng.h:118
void Init()
old free function
Definition: TMemStatMng.cxx:73
SCustomDigest(UChar_t _val[g_digestSize])
Definition: TMemStatMng.h:58
static void MacAllocHook(void *ptr, size_t size)
AllocHook - a static function a special memory hook for Mac OS X memory zones.
UChar_t fValue[g_digestSize]
Definition: TMemStatMng.h:62
Container_t::value_type value_type
Definition: TMemStatMng.h:33
#define ClassDef(name, id)
Definition: Rtypes.h:326
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
bool operator<(const SCustomDigest &a, const SCustomDigest &b)
Definition: TMemStatMng.h:64
TTree * fDumpTree
file to dump current information
Definition: TMemStatMng.h:113
void *(* MallocHookFunc_t)(size_t size, const void *caller)
Definition: TMemStatHook.h:35
virtual ~TMemStatMng()
if an instance is destructed - the hooks are reseted to old hooks
Bool_t fUseGNUBuiltinBacktrace
Definition: TMemStatMng.h:117
static void MacFreeHook(void *ptr)
AllocHook - a static function a special memory hook for Mac OS X memory zones.
auto * a
Definition: textangle.C:12
1-D histogram with an int per channel (see TH1 documentation)}
Definition: TH1.h:530
void AddPointer(void *ptr, Int_t size)
Add pointer to table.
unsigned int UInt_t
Definition: RtypesCore.h:42
static void * fgStackTop
Definition: TMemStatMng.h:115
void Disable()
Disble memory hooks.
void(* FreeHookFunc_t)(void *ptr, const void *caller)
Definition: TMemStatHook.h:36
unsigned long long ULong64_t
Definition: RtypesCore.h:70
std::map< SCustomDigest, Int_t > CRCSet_t
Definition: TMemStatMng.h:75
unsigned long ULong_t
Definition: RtypesCore.h:51
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition: TTimeStamp.h:71
void SetBufferSize(Int_t buffersize)
Set the maximum number of alloc/free calls to be buffered.
TMemStatHook::MallocHookFunc_t fPreviousMallocHook
Definition: TMemStatMng.h:97
Container_t::iterator pos_type
Definition: TMemStatMng.h:32
Int_t find(ULong_t addr)
Definition: TMemStatMng.h:41
Mother of all ROOT objects.
Definition: TObject.h:37
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
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.
static void FreeHook(void *ptr, const void *)
FreeHook - a static function A glibc memory deallocation hook.
A TTree represents a columnar dataset.
Definition: TTree.h:72
unsigned char UChar_t
Definition: RtypesCore.h:34
static TMemStatMng * GetInstance()
GetInstance - a static function Initialize a singleton of MemStat manager.
TMemStatHook::FreeHookFunc_t fPreviousFreeHook
old malloc function
Definition: TMemStatMng.h:98
TMemStatFAddrContainer fFAddrs
Definition: TMemStatMng.h:135
std::map< ULong_t, Int_t > Container_t
Definition: TMemStatMng.h:31