ROOT » TREE » TREEVIEWER » TMemStatShow

class TMemStatShow: public TObject

 Utility class post-processing the file generated by TMemStat (default memstat.root)

 TMemStat records all the calls to malloc and free and write a TTree
 with the position where the memory is allocated/freed , as well as
 the number of bytes.

 To use the class TMemStat, add the following statement at the beginning
 of your script or program
     TMemStat mm("gnubuiltin");
 or in an interactive session do something like:
    root > TMemStat mm("gnubuiltin");
    root > .x somescript.C
    root > .q

 another (may be more practical way) is to modify $ROOTSYS/etc/system.rootrc
 and activate the variable
    Root.TMemStat:           1

 The file collected by TMemStat is named memstat_ProcessID and can be analyzed and results shown
 by executing the static function Show.
 When TMemStat is active it recors every call to malloc/free in a ROOT Tree.
 You must be careful when running jobs with many millions (or more) of calls
 to malloc/free because the generated Tree may become very large.
 The TMemStat constructor TMemStat(const char* system, Int_t buffersize, Int_t maxcalls)
 has its 3 arguments optional:
   -system refers to the internal algorithm to compute the back traces.
    the recommended value is "gnubuiltin"
   -buffersize is the number of calls to malloc or free that can be stored in one memory buffer.
    when the buffer is full, the calls to malloc/free pointing to the same location
    are eliminated and not written to the final Tree. The default value 100000
    is such that between 50 and 90% of the calls are eliminated depending on the application.
    You can set buffersize <=1 to keep every single call to malloc/free.
   -maxcalls can set a limit for the maximum number of calls to be registered in the Tree.
    The default value is 5000000.
 The 3 arguments can be set  in $ROOTSYS/etc/system.rootrc
    Root.TMemStat.system      gnubuiltin
    Root.TMemStat.buffersize  100000
    Root.TMemStat.maxcalls    5000000

 TMemStat::Show creates 3 canvases.
 -In canvas1 it displays a dynamic histogram showing for pages (10 kbytes by default)
  the percentage of the page used.
  A summary pave shows the total memory still in use when the TMemStat object
  goes out of scope and the average occupancy of the pages.
  The average occupancy gives a good indication of the memory fragmentation.
  When moving the mouse on this canvas, a tooltip shows the backtrace for the allocations
  at the address at the mouse position.

 -In canvas2 it displays the histogram of memory leaks in decreasing order.
  when moving the mouse on this canvas, a tooltip shows the backtrace for the leak
  in the bin below the mouse.

 -In canvas3 it displays the histogram of the nbigleaks largest leaks (default is 20)
    for each leak, the number of allocs and average alloc size is shown.


 Simply do:
   root > TMemStat::Show()
 or specifying arguments
   root > TMemStat::Show(0.1,20,"mydir/mymemstat.root");

 The first argument to Show is the percentage of the time of the original job
 that produced the file after which the display is updated. By default update=0.1,
 ie 10 time intervals will be shown.
 The second argument is nbigleaks. if <=0 canvas2 and canvas3 are not shown
 The third argument is the imput file name (result of TMemStat).
 If this argument is omitted, Show will take the most recent file
 generated by TMemStat.

 You can restrict the address range to be analyzed via TMemStatShow::SetAddressRange
 You can restrict the entry range to be analyzed via TMemStatShow::SetEntryRange

Author: Rene Brun 7 July 2010

Function Members (Methods)

public:
virtual~TMemStatShow()
voidTObject::AbstractMethod(const char* method) const
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTObject::Clear(Option_t* = "")
virtual TObject*TObject::Clone(const char* newname = "") const
virtual Int_tTObject::Compare(const TObject* obj) const
virtual voidTObject::Copy(TObject& object) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
static voidEventInfo1(Int_t event, Int_t px, Int_t py, TObject* selected)
static voidEventInfo2(Int_t event, Int_t px, Int_t py, TObject* selected)
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
static voidFillBTString(Int_t bin, Int_t mode, TString& btstring)
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual const char*TObject::GetIconName() const
virtual const char*TObject::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
virtual const char*TObject::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTObject::Hash() const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTObject::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTObject::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
voidTObject::operator delete(void* ptr)
voidTObject::operator delete(void* ptr, void* vp)
voidTObject::operator delete[](void* ptr)
voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
TMemStatShow&operator=(const TMemStatShow&)
virtual voidTObject::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTObject::Print(Option_t* option = "") const
virtual Int_tTObject::Read(const char* name)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(ostream& out, Option_t* option = "")
static voidSetAddressRange(Long64_t nbytes = 0, Long64_t first = 0)
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
static voidSetEntryRange(Long64_t nentries = 0, Long64_t first = 0)
static voidTObject::SetObjectStat(Bool_t stat)
virtual voidTObject::SetUniqueID(UInt_t uid)
static voidShow(Double_t update = 0.10000000000000001, Int_t nbigleaks = 20, const char* fname = "*")
virtual voidShowMembers(TMemberInspector& insp) const
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
TMemStatShow()
TMemStatShow(const TMemStatShow&)
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()

Data Members

public:
static TObject::(anonymous)TObject::kBitMask
static TObject::EStatusBitsTObject::kCanDelete
static TObject::EStatusBitsTObject::kCannotPick
static TObject::EStatusBitsTObject::kHasUUID
static TObject::EStatusBitsTObject::kInvalidObject
static TObject::(anonymous)TObject::kIsOnHeap
static TObject::EStatusBitsTObject::kIsReferenced
static TObject::EStatusBitsTObject::kMustCleanup
static TObject::EStatusBitsTObject::kNoContextMenu
static TObject::(anonymous)TObject::kNotDeleted
static TObject::EStatusBitsTObject::kObjInCanvas
static TObject::(anonymous)TObject::kOverwrite
static TObject::(anonymous)TObject::kSingleKey
static TObject::(anonymous)TObject::kWriteDelete
static TObject::(anonymous)TObject::kZombie
protected:
static Long64_tfgAddressFirstfirst address to process
static Long64_tfgAddressNnumber of addresses in bytes to process
static TObjArray*fgBtidlistlist of back trace ids
static TCanvas*fgC1pointer to canvas showing allocs/deallocs vs time
static TCanvas*fgC2pointer to canvas with leaks in decreasing order
static TCanvas*fgC3pointer to canvas showing the main leaks
static Long64_tfgEntryFirstfirst entry to process
static Long64_tfgEntryNnumber of entries to process
static TH1D*fgHhistogram with allocations - frees
static TH1D*fgHallochistogram with allocations
static TH1I*fgHdiffhistogram with diff of entry number between alloc/free
static TH1I*fgHentryhistogram with entry numbers in the TObjArray
static TH1D*fgHfreehistogram with frees
static TH1I*fgHleakshistogram with leaks
static TTree*fgTTMemStat Tree
static TGToolTip*fgTip1pointer to tool tip for canvas 1
static TGToolTip*fgTip2pointer to tool tip for canvas 2
static Double_t*fgV1pointer to V1 array of TTree::Draw (pos)
static Double_t*fgV2pointer to V2 array of TTree::Draw (nbytes)
static Double_t*fgV3pointer to V3 array of TTree::Draw (time)
static Double_t*fgV4pointer to V4 array of TTree::Draw (btid)

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

void SetAddressRange(Long64_t nbytes = 0, Long64_t first = 0)
specify a memory address range to process (static function).
 This function can be used to restrict the range of memory addresses
 to be analyzed. For example whem TmemStat is run on a 64 bits machine and
 the results visualized on a 32 bits machine, it might be necessary to
 restrict the analysis range to the addresses below 2 Gigabytes, eg
   TMemStatShow::SetMemoryRange(500000000,0); //analyse only the first 500 MBytes
 -first : first address to process (default is 0)
 -nbytes : number of addresses in bytes to process starting at first
             if 0 (default), then all addresses are processed
void SetEntryRange(Long64_t nentries = 0, Long64_t first = 0)
specify a range of entries to process (static function)
 -first : first entry to process (default is 0)
 -nentries : number of entries to process starting at first
             if 0 (default), then all entries are processed
 call this function when the amount of data collected in the Tree is large
 and therefore making the analysis slow.
void Show(Double_t update = 0.10000000000000001, Int_t nbigleaks = 20, const char* fname = "*")
 function called by TMemStat::Show
 Open the memstat data file, then call TTree::Draw to precompute
 the arrays of positions and nbytes per entry.
 update is the time interval in the data file  in seconds after which
 the display is updated. For example is the job producing the memstat.root file
 took 100s to execute, an update of 0.1s will generate 1000 time views of
 the memory use.
 the histogram hbigleaks will contain the nbigleaks largest leaks
 if fname=="*" (default), the most recent file memstat*.root will be taken.
void EventInfo1(Int_t event, Int_t px, Int_t py, TObject* selected)
 static: draw the tooltip showing the backtrace for the allocatios histogram
void EventInfo2(Int_t event, Int_t px, Int_t py, TObject* selected)
 static: draw the tooltip showing the backtrace for the histogram of leaks
void FillBTString(Int_t bin, Int_t mode, TString& btstring)
 static: fill btstring with the traceback corresponding to entry in T
          btstring must be initialized in calling function
TMemStatShow()
{;}
virtual ~TMemStatShow()
{;}