ROOT logo
ROOT » MISC » MEMSTAT » TMemStat

class TMemStat: public TObject

 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.

 -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.
 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


Function Members (Methods)

public:
TMemStat(const TMemStat&)
TMemStat(Option_t* option = "read", Int_t buffersize = 10000, Int_t maxcalls = 5000000)
virtual~TMemStat()
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
static voidClose()
virtual Int_tTObject::Compare(const TObject* obj) const
virtual voidTObject::Copy(TObject& object) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual voidDisable()
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 voidEnable()
virtual voidTObject::Error(const char* method, const char* msgfmt) const
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
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
static voidTObject::operator delete(void* ptr)
static voidTObject::operator delete(void* ptr, void* vp)
static voidTObject::operator delete[](void* ptr)
static 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)
TMemStat&operator=(const TMemStat&)
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 = "")
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 voidTObject::SetObjectStat(Bool_t stat)
virtual voidTObject::SetUniqueID(UInt_t uid)
static voidShow(Double_t update = 0.1, Int_t nbigleaks = 20, const char* fname = "*")
virtual voidShowMembers(TMemberInspector&)
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
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

private:
Bool_tfIsActiveis object attached to MemStat

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TMemStat(Option_t* option = "read", Int_t buffersize = 10000, Int_t maxcalls = 5000000)
 Supported options:
    "gnubuiltin" - if declared, then MemStat will use gcc build-in function,
                      otherwise glibc backtrace will be used

 Note: Currently MemStat uses a hard-coded output file name (for writing) = "memstat.root";
~TMemStat()
destructor
void Close()
close the TMemStat manager
void Disable()
Disable memory statistics
void Enable()
Enable memory statistics
void Show(Double_t update = 0.1, Int_t nbigleaks = 20, const char* fname = "*")
Show results
TMemStat(Option_t* option = "read", Int_t buffersize = 10000, Int_t maxcalls = 5000000)