TMemStatInfo.h

Go to the documentation of this file.
00001 // @(#)root/memstat:$Name$:$Id: TMemStatInfo.h 30815 2009-10-20 13:49:22Z rdm $
00002 // Author: D.Bertini and M.Ivanov   18/06/2007 -- 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 #ifndef ROOT_TMemStatInfo
00013 #define ROOT_TMemStatInfo
00014 
00015 
00016 //****************************************************************************//
00017 //
00018 //
00019 //  Memory statistic information
00020 //                   TMemStatInfoStamp
00021 //                   TMemStatCodeInfo
00022 //                   TMemStatStackInfo
00023 //****************************************************************************//
00024 
00025 // STD
00026 #include <iosfwd>
00027 #include <iomanip>
00028 #include <sstream>
00029 //ROOT
00030 #ifndef ROOT_TROOT
00031 #include "TROOT.h"
00032 #endif
00033 // Memstat
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();              //stamp of memory usage information
00051    virtual ~TMemStatInfoStamp();
00052    void        Print(Option_t* option = "") const;
00053    Bool_t      Equal(TMemStatInfoStamp&stamp);
00054    void     Inc(Int_t memSize);  //increment counters -when memory allocated
00055    void     Dec(Int_t memSize);  //decrement counters -when memory deallocated
00056    friend std::ostream& operator<< (std::ostream &_ostream, const TMemStatInfoStamp &_this);
00057 
00058    Long64_t    fTotalAllocCount;  //total number of allocation for stack sequence
00059    Long64_t    fTotalAllocSize;   //total size of allocated memory
00060    Int_t       fAllocCount;       //current number of allocation-deallocation
00061    Int_t       fAllocSize;        //current allocated size
00062    Int_t       fStampNumber;      //stamp number
00063    Int_t       fID;               //code ID number
00064    Short_t     fStampType;        //stamp Type
00065 
00066    ClassDef(TMemStatInfoStamp, 1) // information about stamps
00067 };
00068 
00069 
00070 class TMemStatCodeInfo: public TObject
00071 {
00072 public:
00073    TMemStatCodeInfo();              // store information about line of code
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);  //increment counters -when memory allocated
00080    void Dec(Int_t memSize);  //decrement counters -when memory deallocated
00081    friend std::ostream& operator<< (std::ostream &_ostream, const TMemStatCodeInfo &_this);
00082 
00083    TMemStatInfoStamp  fLastStamp;     // last time stamp info
00084    TMemStatInfoStamp  fCurrentStamp;  // current  time stamp info
00085    TMemStatInfoStamp  fMaxStampSize;  // max current size stamp
00086    TMemStatInfoStamp  fMaxStamp;      // max current size stamp
00087    Long64_t    fCode;          //pointer to the code
00088    TString     fInfo;          //pointer description
00089    TString     fFunction;      //function
00090    TString     fLib;           //library
00091    UInt_t      fCodeID;        //ID number
00092 
00093    ClassDef(TMemStatCodeInfo, 1) // a code information structure
00094 };
00095 
00096 
00097 class TMemStatStackInfo: public TObject
00098 {
00099 public:
00100    enum {kStackHistorySize = 50};
00101    UInt_t      fSize;               // size of the stack
00102    TMemStatInfoStamp  fLastStamp;          // last time stamp info
00103    TMemStatInfoStamp  fCurrentStamp;       // current  time stamp info
00104    TMemStatInfoStamp  fMaxStampSize;       // max current size stamp
00105    TMemStatInfoStamp  fMaxStamp;           // max current size stamp
00106    Int_t       fNextHash;           // index  to the next info for given hash value
00107    void      **fStackSymbols;       //!Stack Symbols
00108    UInt_t     *fSymbolIndexes;      //[fSize]symbol indexes
00109    UInt_t      fStackID;            //ID number
00110 
00111    TMemStatStackInfo();
00112    virtual ~TMemStatStackInfo() {}
00113    void     Init(Int_t stacksize, void **stackptrs,  TMemStatManager *manager, Int_t ID); //initialization
00114    void     Inc(Int_t memSize, TMemStatManager *manager);  //increment counters -when memory allocated
00115    void     Dec(Int_t memSize, TMemStatManager *manager);  //decrement counters -when memory deallocated
00116    ULong_t  Hash() const;
00117    Int_t    Equal(UInt_t size, void **ptr);
00118    void    *StackAt(UInt_t i);
00119    //   TMemStatStackInfo *Next();    //index of the next entries
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) // a stack information structure
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    // Setting a bit nicer formating
00172    // example: instead of 20600000 print 20,600,000
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

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