85void memstatExample(
double update=0.01,
const char* fname=
"*") {
95 if (!fname || strlen(fname) <5 || strstr(fname,
"*")) {
99 fname = strstr(
s.Data()+
ns-25,
"memstat");
101 printf(
"Analyzing file: %s\n",fname);
104 printf(
"Cannot open file %s\n",fname);
109 printf(
"cannot find the TMemStat TTree named T in file %s\n",fname);
113 printf(
"Illegal update value %g, changed to 0.01\n",
update);
116 if (
update < 0.001) printf(
"Warning update parameter is very small, processing may be slow\n");
121 Long64_t nsel =
T->Draw(
"pos:nbytes:time:btid",
"",
"goff");
134 imean = imean - imean%bw;
135 irms = irms -irms%bw;
139 if (ivmax > 2000000000 && ivmin <2000000000) {
143 printf(
"memory locations above 2GBytes will be ignored\n");
144 nsel =
T->Draw(
"pos:nbytes:time:btid",
"pos <2e9",
"goff");
152 imean = imean - imean%bw;
153 irms = irms -irms%bw;
154 nbins =
Int_t(4*irms/bw);
155 ivmin = imean -bw*nbins/2;
156 ivmax = ivmin+bw*nbins;
158 update *= 0.0001*V3[nsel-1];
162 memset(nbold,0,nvm*8);
164 h =
new TH1D(
"h",
Form(
"%s;pos;per cent of pages used",fname),nbins,ivmin,ivmax);
165 TAxis *axis =
h->GetXaxis();
167 h->SetFillColor(
kRed);
170 halloc =
new TH1D(
"halloc",
Form(
"%s;pos;number of mallocs",fname),nbins,ivmin,ivmax);
171 hfree =
new TH1D(
"hfree",
Form(
"%s;pos;number of frees",fname),nbins,ivmin,ivmax);
186 TNamed *named = (
TNamed*)
T->GetUserInfo()->FindObject(
"SysInfo");
199 for (i=0;i<nsel;i++) {
202 nbytes = (
Int_t)V2[i];
205 if (bin<1 || bin>nbins)
continue;
209 if (dbin > nbytes) dbin = nbytes;
211 h->AddBinContent(bin,100*dbin/dv);
213 nb =
Int_t((nbytes-dbin)/dv);
214 if (bin+nb >nbins) nb = nbins-bin;
215 for (j=1;j<=nb;j++)
h->AddBinContent(bin+j,100);
217 rest = nbytes-nb*dv-dbin;
218 if (rest > 0)
h->AddBinContent(bin+nb+1,100*rest/dv);
220 if (nbold[ipos] > 0) printf(
"reallocating %d bytes (was %lld) at %lld, entry=%d\n",nbytes,nbold[ipos],ipos,i);
221 if (nbold[ipos] == 0) {
226 nbold[ipos] = nbytes;
229 nbytes = nbold[ipos];
230 if (bin+nb >nbins) nb = nbins-bin;
231 nbold[ipos] = 0; nleaks--;
232 if (nbytes <= 0)
continue;
234 if (dbin > nbytes) dbin = nbytes;
235 h->AddBinContent(bin,-100*dbin/dv);
237 nb =
Int_t((nbytes-dbin)/dv);
238 if (bin+nb >nbins) nb = nbins-bin;
239 for (j=1;j<=nb;j++)
h->AddBinContent(bin+j,-100);
241 rest = nbytes-nb*dv-dbin;
242 if (rest > 0)
h->AddBinContent(bin+nb+1,-100*rest/dv);
245 if (time -updateLast >
update) {
254 for (
Int_t k=1;k<nbins;k++) {
255 w =
h->GetBinContent(k);
261 Double_t occupancy = mbytes/(nonEmpty*0.01*dv);
262 pvt->
AddText(
Form(
"memory used = %g Mbytes",mbytes*1
e-6));
263 pvt->
AddText(
Form(
"page occupancy = %f per cent",occupancy));
264 pvt->
AddText(
"(for non empty pages only)");
272 Int_t nlmax = nleaks;
279 for (
Int_t ii=0;ii<nvm;ii++) {
281 ileaks[nleaks] = (
Int_t)nbold[ii];
282 entry[nleaks] = ientry[ii];
284 if (nleaks > nlmax)
break;
289 hentry =
new TH1I(
"hentry",
"leak entry index",nleaks,0,nleaks);
290 hleaks =
new TH1I(
"hleaks",
"leaks;leak number;nbytes in leak",nleaks,0,nleaks);
291 for (
Int_t k=0;k<nleaks;k++) {
292 Int_t kk = lindex[k];
302 c2->SetFrameFillColor(
kCyan-6);
317 c2->Connect(
"ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
318 0, 0,
"EventInfo(Int_t, Int_t, Int_t, TObject*)");
337 TH1I *hbtids = (
TH1I*)
T->GetUserInfo()->FindObject(
"btids");
339 if (!btidlist) btidlist = (
TObjArray*)
T->GetUserInfo()->FindObject(
"FAddrsList");
340 if (!btidlist) btidlist = (
TObjArray*)
f->Get(
"FAddrsList");
341 if (!btidlist)
return;
344 for (
Int_t i=0;i<nbt;i++) {
348 char *title = (
char*)
nm->GetTitle();
349 Int_t nch = strlen(title);
350 if (nch < 20)
continue;
351 if (nch > 100) title[100] =0;
352 const char *
bar = strstr(title,
"| ");
354 if (strstr(
bar,
"operator new"))
continue;
355 if (strstr(
bar,
"libMemStat"))
continue;
356 if (strstr(
bar,
"G__Exception"))
continue;
361 TString form1 =
TString::Format(
" Leak number=%d, leaking %d bytes at entry=%d time=%gseconds\n\n",bin,nbytes,entry,time);
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Class to manage histogram axis.
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis from bin first to last.
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
1-D histogram with a double per channel (see TH1 documentation)}
1-D histogram with an int per channel (see TH1 documentation)}
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
virtual void Draw(Option_t *option="")
Draw this histogram with options.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void SetEntries(Double_t n)
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
The TNamed class is the base class for all named ROOT classes.
virtual const char * GetTitle() const
Returns title of object.
TObject * At(Int_t idx) const
Mother of all ROOT objects.
A Pave (see TPave) with a text centered in the Pave.
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
virtual void SetLabel(const char *label)
A Pave (see TPave) with text, lines or/and boxes inside.
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
virtual TList * GetListOfLines() const
const char * Data() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
virtual TString GetFromPipe(const char *command)
Execute command and return output in TString.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Base class for several text objects.
virtual TText * DrawText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
A TTree represents a columnar dataset.
static constexpr double bar
static constexpr double nm
static constexpr double s
static constexpr double ns
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
Return the weighted mean of an array a with length n.
Double_t RMS(Long64_t n, const T *a, const Double_t *w=0)
Return the Standard Deviation of an array a with length n.
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)