00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ROOT_TMemStatMng
00012 #define ROOT_TMemStatMng
00013
00014
00015 #include <map>
00016
00017 #include "TTimeStamp.h"
00018
00019 #include "TMemStatHook.h"
00020 #include "TMemStatDef.h"
00021
00022
00023 class TTree;
00024 class TFile;
00025 class TH1I;
00026 class TObjArray;
00027
00028 namespace memstat {
00029
00030 class TMemStatFAddrContainer {
00031 typedef std::map<ULong_t, Int_t> Container_t;
00032 typedef Container_t::iterator pos_type;
00033 typedef Container_t::value_type value_type;
00034
00035 public:
00036 bool add(ULong_t addr, Int_t idx) {
00037 std::pair<pos_type, bool> ret = fContainer.insert(value_type(addr, idx));
00038 return (ret.second);
00039 }
00040
00041 Int_t find(ULong_t addr) {
00042 pos_type iter = fContainer.find(addr);
00043 if(fContainer.end() == iter)
00044 return -1;
00045
00046 return iter->second;
00047 }
00048
00049 private:
00050 Container_t fContainer;
00051 };
00052
00053 const UShort_t g_digestSize = 16;
00054 struct SCustomDigest {
00055 SCustomDigest() {
00056 memset(fValue, 0, g_digestSize);
00057 }
00058 SCustomDigest(UChar_t _val[g_digestSize]) {
00059 memcpy(fValue, _val, g_digestSize);
00060 }
00061
00062 UChar_t fValue[g_digestSize];
00063 };
00064 inline bool operator< (const SCustomDigest &a, const SCustomDigest &b)
00065 {
00066 for(int i = 0; i < g_digestSize; ++i) {
00067 if(a.fValue[i] != b.fValue[i])
00068 return (a.fValue[i] < b.fValue[i]);
00069 }
00070 return false;
00071 }
00072
00073
00074 class TMemStatMng: public TObject {
00075 typedef std::map<SCustomDigest, Int_t> CRCSet_t;
00076
00077 private:
00078 TMemStatMng();
00079 virtual ~TMemStatMng();
00080
00081 public:
00082 void Enable();
00083 void Disable();
00084 static TMemStatMng* GetInstance();
00085 static void Close();
00086 void SetBufferSize(Int_t buffersize);
00087 void SetMaxCalls(Int_t maxcalls);
00088
00089 public:
00090
00091 void SetUseGNUBuiltinBacktrace(Bool_t newVal) {
00092 fUseGNUBuiltinBacktrace = newVal;
00093 }
00094
00095 protected:
00096 #if !defined(__APPLE__)
00097 TMemStatHook::MallocHookFunc_t fPreviousMallocHook;
00098 TMemStatHook::FreeHookFunc_t fPreviousFreeHook;
00099 #endif
00100 void Init();
00101 void AddPointer(void *ptr, Int_t size);
00102 void FillTree();
00103 static void *AllocHook(size_t size, const void* );
00104 static void FreeHook(void* ptr, const void* );
00105 static void MacAllocHook(void *ptr, size_t size);
00106 static void MacFreeHook(void *ptr);
00107 Int_t generateBTID(UChar_t *CRCdigest, Int_t stackEntries,
00108 void **stackPointers);
00109
00110
00111
00112 TFile* fDumpFile;
00113 TTree *fDumpTree;
00114 static TMemStatMng *fgInstance;
00115 static void *fgStackTop;
00116
00117 Bool_t fUseGNUBuiltinBacktrace;
00118 TTimeStamp fTimeStamp;
00119 Double_t fBeginTime;
00120 ULong64_t fPos;
00121 Int_t fTimems;
00122 Int_t fNBytes;
00123 Int_t fBtID;
00124 Int_t fMaxCalls;
00125 Int_t fBufferSize;
00126 Int_t fBufN;
00127 ULong64_t *fBufPos;
00128 Int_t *fBufTimems;
00129 Int_t *fBufNBytes;
00130 Int_t *fBufBtID;
00131 Int_t *fIndex;
00132 Bool_t *fMustWrite;
00133
00134 private:
00135 TMemStatFAddrContainer fFAddrs;
00136 TObjArray *fFAddrsList;
00137 TH1I *fHbtids;
00138 CRCSet_t fBTChecksums;
00139 Int_t fBTCount;
00140
00141 UInt_t fBTIDCount;
00142 TNamed *fSysInfo;
00143
00144 ClassDef(TMemStatMng, 0)
00145 };
00146
00147 }
00148
00149 #endif