Logo ROOT   6.08/07
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 // ROOT
17 #ifndef ROOT_TObject
18 #include "TObject.h"
19 #endif
20 #ifndef ROOT_TTimeStamp
21 #include "TTimeStamp.h"
22 #endif
23 // Memstat
24 #ifndef ROOT_TMemStatHook
25 #include "TMemStatHook.h"
26 #endif
27 #ifndef ROOT_TMemStatDef
28 #include "TMemStatDef.h"
29 #endif
30 
31 class TTree;
32 class TFile;
33 class TH1I;
34 class TObjArray;
35 
36 namespace Memstat {
37 
39  typedef std::map<ULong_t, Int_t> Container_t;
40  typedef Container_t::iterator pos_type;
41  typedef Container_t::value_type value_type;
42 
43  public:
44  bool add(ULong_t addr, Int_t idx) {
45  std::pair<pos_type, bool> ret = fContainer.insert(value_type(addr, idx));
46  return (ret.second);
47  }
48 
49  Int_t find(ULong_t addr) {
50  pos_type iter = fContainer.find(addr);
51  if(fContainer.end() == iter)
52  return -1;
53 
54  return iter->second;
55  }
56 
57  private:
58  Container_t fContainer;
59  };
60 
61  const UShort_t g_digestSize = 16;
62  struct SCustomDigest {
64  memset(fValue, 0, g_digestSize);
65  }
66  SCustomDigest(UChar_t _val[g_digestSize]) {
67  memcpy(fValue, _val, g_digestSize);
68  }
69 
71  };
72  inline bool operator< (const SCustomDigest &a, const SCustomDigest &b)
73  {
74  for(int i = 0; i < g_digestSize; ++i) {
75  if(a.fValue[i] != b.fValue[i])
76  return (a.fValue[i] < b.fValue[i]);
77  }
78  return false;
79  }
80 
81 
82  class TMemStatMng: public TObject {
83  typedef std::map<SCustomDigest, Int_t> CRCSet_t;
84 
85  private:
86  TMemStatMng();
87  virtual ~TMemStatMng();
88 
89  public:
90  void Enable(); //enable memory statistic
91  void Disable(); //Disable memory statistic
92  static TMemStatMng* GetInstance(); //get instance of class - ONLY ONE INSTANCE
93  static void Close(); //close MemStatManager
94  void SetBufferSize(Int_t buffersize);
95  void SetMaxCalls(Int_t maxcalls);
96 
97  public:
98  //stack data members
100  fUseGNUBuiltinBacktrace = newVal;
101  }
102 
103  protected:
104 #if !defined(__APPLE__)
107 #endif
108  void Init();
109  void AddPointer(void *ptr, Int_t size); //add pointer to the table
110  void FillTree();
111  static void *AllocHook(size_t size, const void* /*caller*/);
112  static void FreeHook(void* ptr, const void* /*caller*/);
113  static void MacAllocHook(void *ptr, size_t size);
114  static void MacFreeHook(void *ptr);
115  Int_t generateBTID(UChar_t *CRCdigest, Int_t stackEntries,
116  void **stackPointers);
117 
118 
119  // memory information
120  TFile* fDumpFile; //!file to dump current information
121  TTree *fDumpTree; //!tree to dump information
122  static TMemStatMng *fgInstance; // pointer to instance
123  static void *fgStackTop; // stack top pointer
124 
127  Double_t fBeginTime; //time when monitoring starts
128  ULong64_t fPos; //position in memory where alloc/free happens
129  Int_t fTimems; //10000*(current time - begin time)
130  Int_t fNBytes; //number of bytes allocated/freed
131  Int_t fBtID; //back trace identifier
132  Int_t fMaxCalls; //max number of malloc/frees to register in the output Tree
133  Int_t fBufferSize; //max number of malloc/free to keep in the buffer
134  Int_t fBufN; //current number of alloc or free in the buffer
135  ULong64_t *fBufPos; //position in memory where alloc/free happens
136  Int_t *fBufTimems; //10000*(current time - begin time)
137  Int_t *fBufNBytes; //number of bytes allocated/freed
138  Int_t *fBufBtID; //back trace identifier
139  Int_t *fIndex; //array to sort fBufPos
140  Bool_t *fMustWrite; //flag to write or not the entry
141 
142  private:
146  CRCSet_t fBTChecksums;
148  // for Debug. A counter of all (de)allacations.
151 
152  ClassDef(TMemStatMng, 0) // a manager of memstat sessions.
153  };
154 
155 }
156 
157 #endif
bool add(ULong_t addr, Int_t idx)
Definition: TMemStatMng.h:44
An array of TObjects.
Definition: TObjArray.h:39
ULong64_t * fBufPos
Definition: TMemStatMng.h:135
void SetUseGNUBuiltinBacktrace(Bool_t newVal)
Definition: TMemStatMng.h:99
static TMemStatMng * fgInstance
tree to dump information
Definition: TMemStatMng.h:122
unsigned short UShort_t
Definition: RtypesCore.h:36
const UShort_t g_digestSize
Definition: TMemStatMng.h:61
TObjArray * fFAddrsList
Definition: TMemStatMng.h:144
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
TTimeStamp fTimeStamp
Definition: TMemStatMng.h:126
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
SCustomDigest(UChar_t _val[g_digestSize])
Definition: TMemStatMng.h:66
UChar_t fValue[g_digestSize]
Definition: TMemStatMng.h:70
Container_t::value_type value_type
Definition: TMemStatMng.h:41
#define ClassDef(name, id)
Definition: Rtypes.h:254
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
bool operator<(const SCustomDigest &a, const SCustomDigest &b)
Definition: TMemStatMng.h:72
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:119
TTree * fDumpTree
file to dump current information
Definition: TMemStatMng.h:121
void *(* MallocHookFunc_t)(size_t size, const void *caller)
Definition: TMemStatHook.h:35
Bool_t fUseGNUBuiltinBacktrace
Definition: TMemStatMng.h:125
tomato 1-D histogram with an int per channel (see TH1 documentation)}
Definition: TH1.h:534
PyObject * fValue
unsigned int UInt_t
Definition: RtypesCore.h:42
static void * fgStackTop
Definition: TMemStatMng.h:123
double Double_t
Definition: RtypesCore.h:55
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:83
unsigned long ULong_t
Definition: RtypesCore.h:51
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition: TTimeStamp.h:76
TMemStatHook::MallocHookFunc_t fPreviousMallocHook
Definition: TMemStatMng.h:105
Container_t::iterator pos_type
Definition: TMemStatMng.h:40
Int_t find(ULong_t addr)
Definition: TMemStatMng.h:49
Mother of all ROOT objects.
Definition: TObject.h:37
void FillTree(TTree &myTree, const RooDataSet &data)
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
A TTree object has a header with a name and a title.
Definition: TTree.h:98
unsigned char UChar_t
Definition: RtypesCore.h:34
TMemStatHook::FreeHookFunc_t fPreviousFreeHook
old malloc function
Definition: TMemStatMng.h:106
TMemStatFAddrContainer fFAddrs
Definition: TMemStatMng.h:143
std::map< ULong_t, Int_t > Container_t
Definition: TMemStatMng.h:39