ROOT logo
// @(#)root/memstat:$Name$:$Id: TMemStat.h 30815 2009-10-20 13:49:22Z rdm $
// Author: D.Bertini and M.Ivanov   18/06/2007 -- Anar Manafov (A.Manafov@gsi.de) 28/04/2008

/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TMemStat
#define ROOT_TMemStat

// STD
#include <memory>
#include <vector>
#include <set>
// ROOT
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TObjArray
#include "TObjArray.h"
#endif
#ifndef ROOT_TFile
#include "TFile.h"
#endif
#ifndef ROOT_TObjString
#include "TObjString.h"
#endif

class TArrayI;
class TBits;
class TTree;
class TMemStatManager;
class TGraph;
class TMemStatCodeInfo;
class TMemStatInfoStamp;

typedef std::vector<UInt_t> UIntVector_t;
typedef std::vector<Int_t> IntVector_t;
typedef std::auto_ptr<TFile> TFilePtr;

class TMemStat: public TObject
{
public:
   typedef std::set<std::string> Selection_t;

   enum ESelection { kFunction, kLibrary };
   enum StatType  { kTotalAllocCount = 0, kAllocCount = 2, kTotalAllocSize = 1, kAllocSize = 3, kUndef = 4};
   enum StampType { kCurrent = 0, kMaxSize = 1, kMaxCount = 2};
   enum OperType { kAND = 0, kOR = 1, kNOT = 2};

private:
   StatType           fSortStat;              // sorting statistic type
   StampType          fSortStamp;             // sorting stamp type
   Double_t           fMaximum;               // maximum value of all graphs
   UInt_t             fSortDeep;              // Deepness of the information to be print - draw
   UInt_t             fStackDeep;             // Deepness of the stack information
   UInt_t             fMaxStringLength;       // max length of information string
   Int_t              fSelected;              // index of selected object
   Bool_t             fIsActive;              // is object attached to MemStat
   Bool_t             fOrder;                 // sorting order
   UIntVector_t       fSelectedCodeIndex;     // vector of indexes of selected items - code
   UIntVector_t       fSelectedStackIndex;    // vector of indexes of selected items - stack
   IntVector_t        fArrayIndexes;          // indexes of selected objects
   TBits*             fSelectedCodeBitmap;    // bitmask   of selected items        - code
   TBits*             fSelectedStackBitmap;   // bitmask   of selected items - stack
   TFilePtr           fFile;                  // current file with information  - stamps
   TObjArray*         fStampArray;            // array of stamp names
   TObjArray*         fArray;                 // array of objects to draw
   TObjArray*         fArrayGraphics;         // array of graphic objects
   TObjArray          fDisablePrintLib;       // disable printing for libraries
   TObjArray          fDisablePrintCode;      // disable printing for libraries
   TString            fOption;                // current options
   TTree*             fTree;                  // current tree with information  - stamps
   TTree*             fTreeSys;               // tree with system information
   TMemStatInfoStamp* fStackSummary;          // summary information for selected stack
   TMemStatManager*   fManager;               // current MemStatManager

private :
   Int_t      DistancetoPrimitive(Int_t px, Int_t py);
   Bool_t     GetMemStat(const char * fname, Int_t entry);
   Bool_t     EnabledCode(const TMemStatCodeInfo &info) const;
   void       ExecuteEvent(Int_t event, Int_t px, Int_t py);
   void       MakeCodeArray();
   TGraph*    MakeGraph(StatType statType, Int_t id, Int_t type, Double_t &xmax, Double_t &ymax);
   TObjArray* MakeGraphCode(StatType statType, Int_t nentries);
   TObjArray* MakeGraphStack(StatType statType, Int_t nentries);
   void       MakeStampsText();
   void       MakeStackArray();
   void       ProcessOption(Option_t *option);
   void       RefreshSelect();

public:
   TMemStat(Option_t* option = "read");
   virtual ~TMemStat();

public:
   void             AddStamp(const char*stampName);
   void             Draw(Option_t *option = "");
   void             GetFillSelection(Selection_t *_Container, ESelection _Selection) const;
   const Option_t*  GetOption() const {
      return fOption.Data();
   }
   TObjArray*       GetStampList();
   UInt_t           GetStackDeep() const
   {
      return fStackDeep;
   }
   UInt_t           GetSortDeep() const
   {
      return fSortDeep;
   }
   UInt_t           GetMaxStringLength() const
   {
      return fMaxStringLength;
   }
   virtual char    *GetObjectInfo(Int_t px, Int_t py) const;
   void             MakeReport(const char * lib = "", const char *fun = "",
                               Option_t* option = NULL, const char *fileName = "");
   void             MakeHisMemoryStamp(Int_t topDiff);
   void             MakeHisMemoryTime();
   void             Paint(Option_t *option = "");
   void             PrintCode(Int_t nentries = 10) const;
   void             PrintCodeWithID(UInt_t index) const;
   void             PrintStack(Int_t nentries = 10, UInt_t deep = 1) const;
   void             PrintStackWithID(UInt_t _id, UInt_t _deep = 0) const;
   void             Report(Option_t* option = "");
   void             ResetSelection();
   void             SetAutoStamp(Int_t autoStampSize = 2000000, Int_t autoStampAlloc = 200000);
   void             SetCurrentStamp(const char *stampName);
   void             SetCurrentStamp(const TObjString &stampName);
   void             SetSortStat(StatType NewVal)
   {
      fSortStat = NewVal;
   }
   void             SetSortStamp(StampType NewVal)
   {
      fSortStamp= NewVal;
   }
   void             SetStackDeep(UInt_t NewVal)
   {
      fStackDeep = NewVal;
   }
   void             SetSortDeep(UInt_t NewVal)
   {
      fSortDeep = NewVal;
   }
   void             SelectCode(const char *contlib = "",
                               const char *contfunction = "", OperType oType = kOR);
   void             SelectStack(OperType oType = kOR);
   void             SortCode(StatType sortType, StampType stampType);
   void             SortStack(StatType sortType, StampType stampType);

   ClassDef(TMemStat, 0) // a user interface class of memstat
};

#endif
 TMemStat.h:1
 TMemStat.h:2
 TMemStat.h:3
 TMemStat.h:4
 TMemStat.h:5
 TMemStat.h:6
 TMemStat.h:7
 TMemStat.h:8
 TMemStat.h:9
 TMemStat.h:10
 TMemStat.h:11
 TMemStat.h:12
 TMemStat.h:13
 TMemStat.h:14
 TMemStat.h:15
 TMemStat.h:16
 TMemStat.h:17
 TMemStat.h:18
 TMemStat.h:19
 TMemStat.h:20
 TMemStat.h:21
 TMemStat.h:22
 TMemStat.h:23
 TMemStat.h:24
 TMemStat.h:25
 TMemStat.h:26
 TMemStat.h:27
 TMemStat.h:28
 TMemStat.h:29
 TMemStat.h:30
 TMemStat.h:31
 TMemStat.h:32
 TMemStat.h:33
 TMemStat.h:34
 TMemStat.h:35
 TMemStat.h:36
 TMemStat.h:37
 TMemStat.h:38
 TMemStat.h:39
 TMemStat.h:40
 TMemStat.h:41
 TMemStat.h:42
 TMemStat.h:43
 TMemStat.h:44
 TMemStat.h:45
 TMemStat.h:46
 TMemStat.h:47
 TMemStat.h:48
 TMemStat.h:49
 TMemStat.h:50
 TMemStat.h:51
 TMemStat.h:52
 TMemStat.h:53
 TMemStat.h:54
 TMemStat.h:55
 TMemStat.h:56
 TMemStat.h:57
 TMemStat.h:58
 TMemStat.h:59
 TMemStat.h:60
 TMemStat.h:61
 TMemStat.h:62
 TMemStat.h:63
 TMemStat.h:64
 TMemStat.h:65
 TMemStat.h:66
 TMemStat.h:67
 TMemStat.h:68
 TMemStat.h:69
 TMemStat.h:70
 TMemStat.h:71
 TMemStat.h:72
 TMemStat.h:73
 TMemStat.h:74
 TMemStat.h:75
 TMemStat.h:76
 TMemStat.h:77
 TMemStat.h:78
 TMemStat.h:79
 TMemStat.h:80
 TMemStat.h:81
 TMemStat.h:82
 TMemStat.h:83
 TMemStat.h:84
 TMemStat.h:85
 TMemStat.h:86
 TMemStat.h:87
 TMemStat.h:88
 TMemStat.h:89
 TMemStat.h:90
 TMemStat.h:91
 TMemStat.h:92
 TMemStat.h:93
 TMemStat.h:94
 TMemStat.h:95
 TMemStat.h:96
 TMemStat.h:97
 TMemStat.h:98
 TMemStat.h:99
 TMemStat.h:100
 TMemStat.h:101
 TMemStat.h:102
 TMemStat.h:103
 TMemStat.h:104
 TMemStat.h:105
 TMemStat.h:106
 TMemStat.h:107
 TMemStat.h:108
 TMemStat.h:109
 TMemStat.h:110
 TMemStat.h:111
 TMemStat.h:112
 TMemStat.h:113
 TMemStat.h:114
 TMemStat.h:115
 TMemStat.h:116
 TMemStat.h:117
 TMemStat.h:118
 TMemStat.h:119
 TMemStat.h:120
 TMemStat.h:121
 TMemStat.h:122
 TMemStat.h:123
 TMemStat.h:124
 TMemStat.h:125
 TMemStat.h:126
 TMemStat.h:127
 TMemStat.h:128
 TMemStat.h:129
 TMemStat.h:130
 TMemStat.h:131
 TMemStat.h:132
 TMemStat.h:133
 TMemStat.h:134
 TMemStat.h:135
 TMemStat.h:136
 TMemStat.h:137
 TMemStat.h:138
 TMemStat.h:139
 TMemStat.h:140
 TMemStat.h:141
 TMemStat.h:142
 TMemStat.h:143
 TMemStat.h:144
 TMemStat.h:145
 TMemStat.h:146
 TMemStat.h:147
 TMemStat.h:148
 TMemStat.h:149
 TMemStat.h:150
 TMemStat.h:151
 TMemStat.h:152
 TMemStat.h:153
 TMemStat.h:154
 TMemStat.h:155
 TMemStat.h:156
 TMemStat.h:157
 TMemStat.h:158
 TMemStat.h:159
 TMemStat.h:160