TMemStatInfo.cxx

Go to the documentation of this file.
00001 // @(#)root/new:$Name$:$Id: TMemStatInfo.cxx 24658 2008-07-04 09:06:58Z anar $
00002 // Author: D.Bertini and M.Ivanov   10/08/2000 -- Anar Manafov (A.Manafov@gsi.de) 28/04/2008
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //****************************************************************************//
00013 /*
00014       Mem Stat information -
00015 .     TMemStatInfoStamp - counter
00016                    fTotalAllocCount;  //total number of allocation for stack sequence
00017                    fTotalAllocSize;   //total size of allocated memory
00018                    fAllocCount;       //current number of allocation-deallocation
00019                    fAllocSize;        //current allocated size
00020      TMemStatCodeInfo
00021      base code information - strings - fFunction and fLib (function description)
00022                           - stamps  -
00023      TMemStatInfoStamp  fLastStamp;     // last time stamp info
00024      TMemStatInfoStamp  fCurrentStamp;  // current  time stamp info
00025      TMemStatInfoStamp  fMaxStampSize;  // max current size stamp
00026      TMemStatInfoStamp  fMaxStamp;      // max current size stamp
00027      TMemStatStackInfo
00028      base stack information - array of pointers to Code informations
00029                           - stamps  -
00030      TMemStatInfoStamp  fLastStamp;     // last time stamp info
00031      TMemStatInfoStamp  fCurrentStamp;  // current  time stamp info
00032      TMemStatInfoStamp  fMaxStampSize;  // max current size stamp
00033      TMemStatInfoStamp  fMaxStamp;      // max current size stamp
00034 */
00035 //****************************************************************************//
00036 
00037 // ROOT
00038 #include "Riostream.h"
00039 #include "TObject.h"
00040 // Memstat
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 //                                 TMemStatInfoStamp
00052 //****************************************************************************//
00053 
00054 //______________________________________________________________________________
00055 TMemStatInfoStamp::TMemStatInfoStamp():
00056       fTotalAllocCount(0),  //total number of allocation for stack sequence
00057       fTotalAllocSize(0),   //total size of allocated memory
00058       fAllocCount(0),       //current number of allocation-deallocation
00059       fAllocSize(0),        //current allocated size
00060       fStampNumber(0),      //index of previous
00061       fID(0),               //code ID
00062       fStampType(0)
00063 {
00064 }
00065 
00066 //______________________________________________________________________________
00067 TMemStatInfoStamp::~TMemStatInfoStamp()
00068 {
00069 }
00070 
00071 //______________________________________________________________________________
00072 void TMemStatInfoStamp::Print(Option_t* /*option*/) const
00073 {
00074    // TODO: Comment me
00075 
00076    cout << *this << endl;
00077 }
00078 
00079 //______________________________________________________________________________
00080 std::ostream& operator << (std::ostream &_ostream, const TMemStatInfoStamp &_this)
00081 {
00082    // TODO: Comment me
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    // Setting a bit nicer formating
00091    // example: instead of 20600000 print 20,600,000
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 //                                 TMemStatCodeInfo
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    // a ctor
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    // TODO: Comment me
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    //  Get function's real name from info descriptor
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 * /*option*/) const
00157 {
00158    // TODO: Comment me
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    // make time stamp - only if change
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    // TODO: Comment me
00184    _ostream
00185    << _this.fFunction.Data()
00186    << '\t' << _this.fLib.Data();
00187 
00188    return _ostream;
00189 }
00190 
00191 
00192 //****************************************************************************//
00193 //                                 Storage of Stack information
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    // default ctor
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    //Initialize the stack
00221    fStackID = ID;
00222    fSize = stacksize;
00223    fLastStamp.fID   = fStackID;     // last time stamp info
00224    fCurrentStamp.fID = fStackID;    // current  time stamp info
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    // Return 0 if stack information not equal otherwise return 1.
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    // TODO: Comment me
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    // make time stamp - only if change
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    // TODO: Comment me
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    // TODO: Comment me
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    // TODO: Comment me
00305    return StreemCurrAndMax(_ostream, _this);
00306 }

Generated on Tue Jul 5 14:43:52 2011 for ROOT_528-00b_version by  doxygen 1.5.1