#include "Riostream.h"
#include "TObject.h"
#include "TMemStatInfo.h"
#include "TMemStatManager.h"
#include "TMemStatDepend.h"
ClassImp(TMemStatCodeInfo)
ClassImp(TMemStatInfoStamp)
ClassImp(TMemStatStackInfo)
TMemStatInfoStamp::TMemStatInfoStamp():
fTotalAllocCount(0),
fTotalAllocSize(0),
fAllocCount(0),
fAllocSize(0),
fStampNumber(0),
fID(0),
fStampType(0)
{
}
TMemStatInfoStamp::~TMemStatInfoStamp()
{
}
void TMemStatInfoStamp::Print(Option_t* ) const
{
cout << *this << endl;
}
std::ostream& operator << (std::ostream &_ostream, const TMemStatInfoStamp &_this)
{
_ostream
<< std::setw(fields_length[1]) << "TotalCount"
<< std::setw(fields_length[2]) << "TotalSize"
<< std::setw(fields_length[3]) << "Count"
<< std::setw(fields_length[4]) << "Size" << std::endl;
std::locale loc("");
std::locale loc_previous = _ostream.imbue(loc);
_ostream.precision(2);
_ostream << std::fixed;
_ostream
<< std::setw(fields_length[1]) << _this.fTotalAllocCount
<< std::setw(fields_length[2]) << Memstat::dig2bytes(_this.fTotalAllocSize)
<< std::setw(fields_length[3]) << _this.fAllocCount
<< std::setw(fields_length[4]) << Memstat::dig2bytes(_this.fAllocSize);
_ostream.imbue(loc_previous);
return _ostream;
}
TMemStatCodeInfo::TMemStatCodeInfo():
fLastStamp(),
fCurrentStamp(),
fMaxStampSize(),
fMaxStamp(),
fCode(0),
fInfo(0),
fFunction(),
fLib(),
fCodeID(0)
{
fLastStamp.fStampType = TMemStatInfoStamp::kCode;
fCurrentStamp.fStampType = TMemStatInfoStamp::kCode;
fMaxStampSize.fStampType = TMemStatInfoStamp::kCode;
fMaxStamp.fStampType = TMemStatInfoStamp::kCode;
}
void TMemStatCodeInfo::Inc(Int_t memSize)
{
fCurrentStamp.Inc(memSize);
if (fCurrentStamp.fAllocCount > fMaxStamp.fAllocCount)
fMaxStamp = fCurrentStamp;
if (fCurrentStamp.fAllocSize > fMaxStampSize.fAllocSize)
fMaxStampSize = fCurrentStamp;
}
void TMemStatCodeInfo::SetInfo(void *info)
{
char *zero = 0;
fCode = (Long64_t)((char*)info - zero);
TString strLine;
TMemStatDepend::GetSymbols(info, fInfo, fLib, fFunction, strLine);
}
void TMemStatCodeInfo::Print(Option_t * ) const
{
StreemCurrAndMax(cout, *this) << endl;
cout << fCodeID << "\t" << fInfo.Data() << endl;
cout << fCodeID << "\t" << fLib.Data() << '\t' << fFunction.Data() << endl;
}
void TMemStatCodeInfo::MakeStamp(Int_t stampNumber)
{
if (fCurrentStamp.Equal(fLastStamp))
return;
TMemStatInfoStamp &newStamp = TMemStatManager::GetInstance()->AddStamp();
fCurrentStamp.fStampNumber = stampNumber;
newStamp = fCurrentStamp;
fLastStamp = newStamp;
}
std::ostream& operator << (std::ostream &_ostream, const TMemStatCodeInfo &_this)
{
_ostream
<< _this.fFunction.Data()
<< '\t' << _this.fLib.Data();
return _ostream;
}
TMemStatStackInfo::TMemStatStackInfo():
TObject(),
fSize(0),
fLastStamp(),
fCurrentStamp(),
fMaxStampSize(),
fMaxStamp(),
fNextHash(-1),
fStackSymbols(0),
fSymbolIndexes(0),
fStackID(0)
{
fLastStamp.fStampType = TMemStatInfoStamp::kStack;
fCurrentStamp.fStampType = TMemStatInfoStamp::kStack;
fMaxStampSize.fStampType = TMemStatInfoStamp::kStack;
fMaxStamp.fStampType = TMemStatInfoStamp::kStack;
}
void TMemStatStackInfo::Init(int stacksize, void **stackptrs, TMemStatManager *manager, Int_t ID)
{
fStackID = ID;
fSize = stacksize;
fLastStamp.fID = fStackID;
fCurrentStamp.fID = fStackID;
fStackSymbols = new void*[stacksize];
memcpy(fStackSymbols, stackptrs, stacksize * sizeof(void *));
fSymbolIndexes = new UInt_t[stacksize];
for (Int_t i = 0; i < stacksize; ++i) {
TMemStatCodeInfo & cinfo = manager->GetCodeInfo(stackptrs[i]);
if (cinfo.fCode == 0)
cinfo.SetInfo(stackptrs[i]);
fSymbolIndexes[i] = cinfo.fCodeID;
}
}
int TMemStatStackInfo::Equal(unsigned int size, void **ptr)
{
if (size != fSize)
return 0;
for (size_t i = 0; i < size; ++i)
if (ptr[i] != fStackSymbols[i])
return 0;
return 1;
}
Bool_t TMemStatInfoStamp::Equal(TMemStatInfoStamp&stamp)
{
if (fTotalAllocCount != stamp.fTotalAllocCount)
return kFALSE;
if (fAllocCount != stamp.fAllocCount)
return kFALSE;
return kTRUE;
}
void TMemStatStackInfo::MakeStamp(Int_t stampNumber)
{
if (fCurrentStamp.Equal(fLastStamp))
return;
TMemStatInfoStamp &newStamp = TMemStatManager::GetInstance()->AddStamp();
fCurrentStamp.fStampNumber = stampNumber;
newStamp = fCurrentStamp;
fLastStamp = newStamp;
}
void TMemStatStackInfo::Inc(Int_t memSize, TMemStatManager *manager)
{
fCurrentStamp.Inc(memSize);
if (fCurrentStamp.fAllocCount > fMaxStamp.fAllocCount)
fMaxStamp = fCurrentStamp;
if (fCurrentStamp.fAllocSize > fMaxStampSize.fAllocSize)
fMaxStampSize = fCurrentStamp;
for (UInt_t i = 0; i < fSize; ++i)
manager->fCodeInfoArray[fSymbolIndexes[i]].Inc(memSize);
}
void TMemStatStackInfo::Dec(int memSize, TMemStatManager *manager)
{
if (fCurrentStamp.fAllocCount)
fCurrentStamp.fAllocCount -= 1;
fCurrentStamp.fAllocSize -= memSize;
for (UInt_t i = 0; i < fSize; ++i)
manager->fCodeInfoArray[fSymbolIndexes[i]].Dec(memSize);
}
std::ostream& operator << (std::ostream &_ostream, const TMemStatStackInfo &_this)
{
return StreemCurrAndMax(_ostream, _this);
}
Last change: Fri Jul 4 14:51:18 2008
Last generated: 2008-07-04 14:51
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.