00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TMemStatInfo
00013 #define ROOT_TMemStatInfo
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <iosfwd>
00027 #include <iomanip>
00028 #include <sstream>
00029
00030 #ifndef ROOT_TROOT
00031 #include "TROOT.h"
00032 #endif
00033
00034 #ifndef ROOT_TMemStatHelpers
00035 #include "TMemStatHelpers.h"
00036 #endif
00037
00038 class TMemStatStackInfo;
00039 class TMemStatManager;
00040
00041
00042
00043 const int fields_length[] = {18, 15, 19, 12, 8};
00044
00045
00046 class TMemStatInfoStamp: public TObject
00047 {
00048 public:
00049 enum EStampType { kCode, kStack };
00050 TMemStatInfoStamp();
00051 virtual ~TMemStatInfoStamp();
00052 void Print(Option_t* option = "") const;
00053 Bool_t Equal(TMemStatInfoStamp&stamp);
00054 void Inc(Int_t memSize);
00055 void Dec(Int_t memSize);
00056 friend std::ostream& operator<< (std::ostream &_ostream, const TMemStatInfoStamp &_this);
00057
00058 Long64_t fTotalAllocCount;
00059 Long64_t fTotalAllocSize;
00060 Int_t fAllocCount;
00061 Int_t fAllocSize;
00062 Int_t fStampNumber;
00063 Int_t fID;
00064 Short_t fStampType;
00065
00066 ClassDef(TMemStatInfoStamp, 1)
00067 };
00068
00069
00070 class TMemStatCodeInfo: public TObject
00071 {
00072 public:
00073 TMemStatCodeInfo();
00074 void SetInfo(void *info);
00075 virtual ~TMemStatCodeInfo() {
00076 }
00077 void MakeStamp(Int_t stampNumber);
00078 void Print(Option_t* option = "") const;
00079 void Inc(Int_t memSize);
00080 void Dec(Int_t memSize);
00081 friend std::ostream& operator<< (std::ostream &_ostream, const TMemStatCodeInfo &_this);
00082
00083 TMemStatInfoStamp fLastStamp;
00084 TMemStatInfoStamp fCurrentStamp;
00085 TMemStatInfoStamp fMaxStampSize;
00086 TMemStatInfoStamp fMaxStamp;
00087 Long64_t fCode;
00088 TString fInfo;
00089 TString fFunction;
00090 TString fLib;
00091 UInt_t fCodeID;
00092
00093 ClassDef(TMemStatCodeInfo, 1)
00094 };
00095
00096
00097 class TMemStatStackInfo: public TObject
00098 {
00099 public:
00100 enum {kStackHistorySize = 50};
00101 UInt_t fSize;
00102 TMemStatInfoStamp fLastStamp;
00103 TMemStatInfoStamp fCurrentStamp;
00104 TMemStatInfoStamp fMaxStampSize;
00105 TMemStatInfoStamp fMaxStamp;
00106 Int_t fNextHash;
00107 void **fStackSymbols;
00108 UInt_t *fSymbolIndexes;
00109 UInt_t fStackID;
00110
00111 TMemStatStackInfo();
00112 virtual ~TMemStatStackInfo() {}
00113 void Init(Int_t stacksize, void **stackptrs, TMemStatManager *manager, Int_t ID);
00114 void Inc(Int_t memSize, TMemStatManager *manager);
00115 void Dec(Int_t memSize, TMemStatManager *manager);
00116 ULong_t Hash() const;
00117 Int_t Equal(UInt_t size, void **ptr);
00118 void *StackAt(UInt_t i);
00119
00120 void MakeStamp(Int_t stampNumber);
00121 static inline ULong_t HashStack(UInt_t size, void **ptr) {
00122 return TString::Hash(ptr, size*sizeof(void*));
00123 }
00124 friend std::ostream& operator << (std::ostream &_ostream, const TMemStatStackInfo &_this);
00125
00126 ClassDef(TMemStatStackInfo, 1)
00127 };
00128
00129
00130 inline void TMemStatInfoStamp::Inc(int memSize)
00131 {
00132 fTotalAllocCount += 1;
00133 fTotalAllocSize += memSize;
00134 fAllocCount += 1;
00135 fAllocSize += memSize;
00136 }
00137 inline void TMemStatInfoStamp::Dec(int memSize)
00138 {
00139 fAllocCount -= 1;
00140 fAllocSize -= memSize;
00141 }
00142 inline void TMemStatCodeInfo::Dec(int memSize)
00143 {
00144 fCurrentStamp.Dec(memSize);
00145 }
00146
00147 inline ULong_t TMemStatStackInfo::Hash() const
00148 {
00149 return HashStack(fSize, fStackSymbols);
00150 }
00151
00152 inline void *TMemStatStackInfo::StackAt(UInt_t i)
00153 {
00154 return i < fSize ? fStackSymbols[i] : 0;
00155 }
00156
00157
00158
00159 template<class T>
00160 std::ostream& StreemCurrAndMax(std::ostream &_ostream, const T &_this)
00161 {
00162 std::ios::fmtflags old_flags(_ostream.flags(std::ios::left));
00163
00164 _ostream << "\n"
00165 << std::setw(fields_length[0]) << ""
00166 << std::setw(fields_length[1]) << "TotalCount"
00167 << std::setw(fields_length[2]) << "TotalSize"
00168 << std::setw(fields_length[3]) << "Count"
00169 << std::setw(fields_length[4]) << "Size" << std::endl;
00170
00171
00172
00173 std::locale loc("");
00174 std::locale loc_previous = _ostream.imbue(loc);
00175 _ostream.precision(2);
00176 _ostream << std::fixed;
00177
00178 _ostream << std::setw(fields_length[0]) << "Current stamp";
00179 _ostream
00180 << std::setw(fields_length[1]) << _this.fCurrentStamp.fTotalAllocCount
00181 << std::setw(fields_length[2]) << Memstat::dig2bytes(_this.fCurrentStamp.fTotalAllocSize)
00182 << std::setw(fields_length[3]) << _this.fCurrentStamp.fAllocCount
00183 << std::setw(fields_length[4]) << Memstat::dig2bytes(_this.fCurrentStamp.fAllocSize) << std::endl;
00184
00185 _ostream << std::setw(fields_length[0]) << "Max Alloc stamp";
00186 _ostream
00187 << std::setw(fields_length[1]) << _this.fMaxStamp.fTotalAllocCount
00188 << std::setw(fields_length[2]) << Memstat::dig2bytes(_this.fMaxStamp.fTotalAllocSize)
00189 << std::setw(fields_length[3]) << _this.fMaxStamp.fAllocCount
00190 << std::setw(fields_length[4]) << Memstat::dig2bytes(_this.fMaxStamp.fAllocSize) << std::endl;
00191
00192 _ostream << std::setw(fields_length[0]) << "Max Size stamp";
00193 _ostream
00194 << std::setw(fields_length[1]) << _this.fMaxStampSize.fTotalAllocCount
00195 << std::setw(fields_length[2]) << Memstat::dig2bytes(_this.fMaxStampSize.fTotalAllocSize)
00196 << std::setw(fields_length[3]) << _this.fMaxStampSize.fAllocCount
00197 << std::setw(fields_length[4]) << Memstat::dig2bytes(_this.fMaxStampSize.fAllocSize);
00198
00199 _ostream.imbue(loc_previous);
00200 _ostream.flags(old_flags);
00201
00202 return _ostream;
00203 }
00204
00205
00206 #endif