00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Riostream.h"
00039 #include "TObject.h"
00040
00041 #include "TMemStatInfo.h"
00042 #include "TMemStatManager.h"
00043 #include "TMemStatDepend.h"
00044
00045
00046 ClassImp(TMemStatCodeInfo)
00047 ClassImp(TMemStatInfoStamp)
00048 ClassImp(TMemStatStackInfo)
00049
00050
00051
00052
00053
00054
00055 TMemStatInfoStamp::TMemStatInfoStamp():
00056 fTotalAllocCount(0),
00057 fTotalAllocSize(0),
00058 fAllocCount(0),
00059 fAllocSize(0),
00060 fStampNumber(0),
00061 fID(0),
00062 fStampType(0)
00063 {
00064 }
00065
00066
00067 TMemStatInfoStamp::~TMemStatInfoStamp()
00068 {
00069 }
00070
00071
00072 void TMemStatInfoStamp::Print(Option_t* ) const
00073 {
00074
00075
00076 cout << *this << endl;
00077 }
00078
00079
00080 std::ostream& operator << (std::ostream &_ostream, const TMemStatInfoStamp &_this)
00081 {
00082
00083
00084 _ostream
00085 << std::setw(fields_length[1]) << "TotalCount"
00086 << std::setw(fields_length[2]) << "TotalSize"
00087 << std::setw(fields_length[3]) << "Count"
00088 << std::setw(fields_length[4]) << "Size" << std::endl;
00089
00090
00091
00092 std::locale loc("");
00093 std::locale loc_previous = _ostream.imbue(loc);
00094 _ostream.precision(2);
00095 _ostream << std::fixed;
00096
00097 _ostream
00098 << std::setw(fields_length[1]) << _this.fTotalAllocCount
00099 << std::setw(fields_length[2]) << Memstat::dig2bytes(_this.fTotalAllocSize)
00100 << std::setw(fields_length[3]) << _this.fAllocCount
00101 << std::setw(fields_length[4]) << Memstat::dig2bytes(_this.fAllocSize);
00102
00103 _ostream.imbue(loc_previous);
00104
00105 return _ostream;
00106 }
00107
00108
00109
00110
00111
00112
00113 TMemStatCodeInfo::TMemStatCodeInfo():
00114 fLastStamp(),
00115 fCurrentStamp(),
00116 fMaxStampSize(),
00117 fMaxStamp(),
00118 fCode(0),
00119 fInfo(0),
00120 fFunction(),
00121 fLib(),
00122 fCodeID(0)
00123 {
00124
00125
00126 fLastStamp.fStampType = TMemStatInfoStamp::kCode;
00127 fCurrentStamp.fStampType = TMemStatInfoStamp::kCode;
00128 fMaxStampSize.fStampType = TMemStatInfoStamp::kCode;
00129 fMaxStamp.fStampType = TMemStatInfoStamp::kCode;
00130 }
00131
00132
00133 void TMemStatCodeInfo::Inc(Int_t memSize)
00134 {
00135
00136
00137 fCurrentStamp.Inc(memSize);
00138 if (fCurrentStamp.fAllocCount > fMaxStamp.fAllocCount)
00139 fMaxStamp = fCurrentStamp;
00140 if (fCurrentStamp.fAllocSize > fMaxStampSize.fAllocSize)
00141 fMaxStampSize = fCurrentStamp;
00142 }
00143
00144
00145 void TMemStatCodeInfo::SetInfo(void *info)
00146 {
00147
00148
00149 char *zero = 0;
00150 fCode = (Long64_t)((char*)info - zero);
00151 TString strLine;
00152 TMemStatDepend::GetSymbols(info, fInfo, fLib, fFunction, strLine);
00153 }
00154
00155
00156 void TMemStatCodeInfo::Print(Option_t * ) const
00157 {
00158
00159
00160 StreemCurrAndMax(cout, *this) << endl;
00161
00162 cout << fCodeID << "\t" << fInfo.Data() << endl;
00163 cout << fCodeID << "\t" << fLib.Data() << '\t' << fFunction.Data() << endl;
00164 }
00165
00166
00167 void TMemStatCodeInfo::MakeStamp(Int_t stampNumber)
00168 {
00169
00170
00171 if (fCurrentStamp.Equal(fLastStamp))
00172 return;
00173
00174 TMemStatInfoStamp &newStamp = TMemStatManager::GetInstance()->AddStamp();
00175 fCurrentStamp.fStampNumber = stampNumber;
00176 newStamp = fCurrentStamp;
00177 fLastStamp = newStamp;
00178 }
00179
00180
00181 std::ostream& operator << (std::ostream &_ostream, const TMemStatCodeInfo &_this)
00182 {
00183
00184 _ostream
00185 << _this.fFunction.Data()
00186 << '\t' << _this.fLib.Data();
00187
00188 return _ostream;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 TMemStatStackInfo::TMemStatStackInfo():
00198 TObject(),
00199 fSize(0),
00200 fLastStamp(),
00201 fCurrentStamp(),
00202 fMaxStampSize(),
00203 fMaxStamp(),
00204 fNextHash(-1),
00205 fStackSymbols(0),
00206 fSymbolIndexes(0),
00207 fStackID(0)
00208 {
00209
00210
00211 fLastStamp.fStampType = TMemStatInfoStamp::kStack;
00212 fCurrentStamp.fStampType = TMemStatInfoStamp::kStack;
00213 fMaxStampSize.fStampType = TMemStatInfoStamp::kStack;
00214 fMaxStamp.fStampType = TMemStatInfoStamp::kStack;
00215 }
00216
00217
00218 void TMemStatStackInfo::Init(int stacksize, void **stackptrs, TMemStatManager *manager, Int_t ID)
00219 {
00220
00221 fStackID = ID;
00222 fSize = stacksize;
00223 fLastStamp.fID = fStackID;
00224 fCurrentStamp.fID = fStackID;
00225
00226 fStackSymbols = new void*[stacksize];
00227 memcpy(fStackSymbols, stackptrs, stacksize * sizeof(void *));
00228 fSymbolIndexes = new UInt_t[stacksize];
00229
00230 for (Int_t i = 0; i < stacksize; ++i) {
00231 TMemStatCodeInfo & cinfo = manager->GetCodeInfo(stackptrs[i]);
00232 if (cinfo.fCode == 0)
00233 cinfo.SetInfo(stackptrs[i]);
00234
00235 fSymbolIndexes[i] = cinfo.fCodeID;
00236 }
00237 }
00238
00239
00240 int TMemStatStackInfo::Equal(unsigned int size, void **ptr)
00241 {
00242
00243
00244 if (size != fSize)
00245 return 0;
00246 for (size_t i = 0; i < size; ++i)
00247 if (ptr[i] != fStackSymbols[i])
00248 return 0;
00249 return 1;
00250 }
00251
00252
00253 Bool_t TMemStatInfoStamp::Equal(TMemStatInfoStamp&stamp)
00254 {
00255
00256 if (fTotalAllocCount != stamp.fTotalAllocCount)
00257 return kFALSE;
00258 if (fAllocCount != stamp.fAllocCount)
00259 return kFALSE;
00260 return kTRUE;
00261 }
00262
00263
00264 void TMemStatStackInfo::MakeStamp(Int_t stampNumber)
00265 {
00266
00267
00268 if (fCurrentStamp.Equal(fLastStamp))
00269 return;
00270
00271 TMemStatInfoStamp &newStamp = TMemStatManager::GetInstance()->AddStamp();
00272 fCurrentStamp.fStampNumber = stampNumber;
00273 newStamp = fCurrentStamp;
00274 fLastStamp = newStamp;
00275 }
00276
00277
00278 void TMemStatStackInfo::Inc(Int_t memSize, TMemStatManager *manager)
00279 {
00280
00281 fCurrentStamp.Inc(memSize);
00282 if (fCurrentStamp.fAllocCount > fMaxStamp.fAllocCount)
00283 fMaxStamp = fCurrentStamp;
00284 if (fCurrentStamp.fAllocSize > fMaxStampSize.fAllocSize)
00285 fMaxStampSize = fCurrentStamp;
00286 for (UInt_t i = 0; i < fSize; ++i)
00287 manager->fCodeInfoArray[fSymbolIndexes[i]].Inc(memSize);
00288 }
00289
00290
00291 void TMemStatStackInfo::Dec(int memSize, TMemStatManager *manager)
00292 {
00293
00294 if (fCurrentStamp.fAllocCount)
00295 fCurrentStamp.fAllocCount -= 1;
00296 fCurrentStamp.fAllocSize -= memSize;
00297 for (UInt_t i = 0; i < fSize; ++i)
00298 manager->fCodeInfoArray[fSymbolIndexes[i]].Dec(memSize);
00299 }
00300
00301
00302 std::ostream& operator << (std::ostream &_ostream, const TMemStatStackInfo &_this)
00303 {
00304
00305 return StreemCurrAndMax(_ostream, _this);
00306 }