This script creates 2 canvases.
The first argument to the script is the percentage of the time of the original job that produced the file after which the display is updated. By default update=0.01, ie 100 time intervals will be shown. The second argument is the input file name (result of TMemStat). If this argument is omitted, the script will take the most recent file generated by TMemStat.
void memstatExample(
double update=0.01,
const char* fname=
"*") {
if (!fname || strlen(fname) <5 || strstr(fname,"*")) {
fname = strstr(
s.Data()+
ns-25,
"memstat");
}
printf("Analyzing file: %s\n",fname);
printf("Cannot open file %s\n",fname);
return;
}
printf("cannot find the TMemStat TTree named T in file %s\n",fname);
return;
}
printf(
"Illegal update value %g, changed to 0.01\n",
update);
}
if (
update < 0.001) printf(
"Warning update parameter is very small, processing may be slow\n");
Long64_t nsel =
T->Draw(
"pos:nbytes:time:btid",
"",
"goff");
imean = imean - imean%bw;
irms = irms -irms%bw;
if (ivmax > 2000000000 && ivmin <2000000000) {
printf("memory locations above 2GBytes will be ignored\n");
nsel =
T->Draw(
"pos:nbytes:time:btid",
"pos <2e9",
"goff");
bw = 10000;
imean = imean - imean%bw;
irms = irms -irms%bw;
nbins =
Int_t(4*irms/bw);
ivmin = imean -bw*nbins/2;
ivmax = ivmin+bw*nbins;
}
memset(nbold,0,nvm*8);
h =
new TH1D(
"h",
Form(
"%s;pos;per cent of pages used",fname),nbins,ivmin,ivmax);
halloc =
new TH1D(
"halloc",
Form(
"%s;pos;number of mallocs",fname),nbins,ivmin,ivmax);
hfree =
new TH1D(
"hfree",
Form(
"%s;pos;number of frees",fname),nbins,ivmin,ivmax);
TNamed *named = (
TNamed*)
T->GetUserInfo()->FindObject(
"SysInfo");
for (i=0;i<nsel;i++) {
pos = V1[i];
time = 0.0001*V3[i];
if (bin<1 || bin>nbins) continue;
if (nbytes > 0) {
if (dbin > nbytes) dbin = nbytes;
h->AddBinContent(bin,100*dbin/dv);
nb =
Int_t((nbytes-dbin)/dv);
if (bin+nb >nbins) nb = nbins-bin;
for (j=1;j<=nb;j++)
h->AddBinContent(bin+j,100);
rest = nbytes-nb*dv-dbin;
if (rest > 0)
h->AddBinContent(bin+nb+1,100*rest/dv);
if (nbold[ipos] > 0) printf("reallocating %d bytes (was %lld) at %lld, entry=%d\n",nbytes,nbold[ipos],ipos,i);
if (nbold[ipos] == 0) {
nleaks++;
ientry[ipos] = i;
}
nbold[ipos] = nbytes;
} else {
nbytes = nbold[ipos];
if (bin+nb >nbins) nb = nbins-bin;
nbold[ipos] = 0; nleaks--;
if (nbytes <= 0) continue;
if (dbin > nbytes) dbin = nbytes;
h->AddBinContent(bin,-100*dbin/dv);
nb =
Int_t((nbytes-dbin)/dv);
if (bin+nb >nbins) nb = nbins-bin;
for (j=1;j<=nb;j++)
h->AddBinContent(bin+j,-100);
rest = nbytes-nb*dv-dbin;
if (rest > 0)
h->AddBinContent(bin+nb+1,-100*rest/dv);
}
if (time -updateLast >
update) {
updateLast = time;
for (
Int_t k=1;k<nbins;k++) {
if (w > 0) {
nonEmpty++;
mbytes += 0.01*w*dv;
}
}
Double_t occupancy = mbytes/(nonEmpty*0.01*dv);
pvt->
AddText(
Form(
"page occupancy = %f per cent",occupancy));
pvt->
AddText(
"(for non empty pages only)");
}
}
nleaks += 1000;
nleaks =0;
for (
Int_t ii=0;ii<nvm;ii++) {
if (nbold[ii] > 0) {
ileaks[nleaks] = (
Int_t)nbold[ii];
entry[nleaks] = ientry[ii];
nleaks++;
if (nleaks > nlmax) break;
}
}
hentry =
new TH1I(
"hentry",
"leak entry index",nleaks,0,nleaks);
hleaks =
new TH1I(
"hleaks",
"leaks;leak number;nbytes in leak",nleaks,0,nleaks);
for (
Int_t k=0;k<nleaks;k++) {
i = entry[kk];
}
c2->Connect(
"ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
0, 0, "EventInfo(Int_t, Int_t, Int_t, TObject*)");
}
{
if (!gTip) return;
return;
TH1I *hbtids = (
TH1I*)
T->GetUserInfo()->FindObject(
"btids");
if (!hbtids) return;
if (!btidlist) btidlist = (
TObjArray*)
T->GetUserInfo()->FindObject(
"FAddrsList");
if (!btidlist) btidlist = (
TObjArray*)
f->Get(
"FAddrsList");
if (!btidlist) return;
for (
Int_t i=0;i<nbt;i++) {
char *title = (
char*)
nm->GetTitle();
Int_t nch = strlen(title);
if (nch < 20) continue;
if (nch > 100) title[100] =0;
const char *
bar = strstr(title,
"| ");
if (strstr(
bar,
"operator new"))
continue;
if (strstr(
bar,
"libMemStat"))
continue;
if (strstr(
bar,
"G__Exception"))
continue;
}
if (selected) {
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)