1 enum {kCtr =1,kClear = 2,kMake = 3,
2 startClear=2,contClear=12,endClear=22,
3 startMake =3,contMake =13,endMake =23,
4 kMaxMake=100,kMaxMakeSQ = kMaxMake*kMaxMake,
16 ReadLog(
const char *file) {inp = fopen(file,
"r");fNMakers=0;}
17 const char *Name(
int idx) {
18 if (!idx)
return "__ALL__";
19 TObject *tn = mArray.At(idx);
return (tn)? tn->GetName():0;}
21 const char *Next(
int &kind,
int &idx,
double &exe,
double &heap,
double &free,
double &inc) {
23 kind=0;idx=0;exe=0;heap=0;free=0,inc=0;
25 char *endMaker,*clear,*ctr,*doPs,*fr,*to,*and;
26 while(fgets(line,500,inp)) {
27 doPs = strstr(line,
"doPs for");
29 endMaker = strstr(line,
"EndMaker");
30 clear = strstr(line,
"Clear");
31 ctr = strstr(line,
"constructor");
35 if (endMaker) kind = 3;
37 fr = doPs+8 +strspn(doPs+8,
" \t");
39 ts =
""; ts.Append(fr,to-fr);
40 if (!ts.Length())
continue;
41 fr = strstr(fr,
"total");
if (!fr)
continue;
42 fr = strstr(fr,
"=" );
if (!fr)
continue;
44 fr = strstr(fr,
"heap" );
if (!fr)
continue;
45 fr = strstr(fr,
"=" );
if (!fr)
continue;
47 and = strstr(fr,
"and");
48 if (and) free = atof(and+3);
49 fr = strstr(fr,
"(" );
if (!fr)
continue;
51 if (kind==1)
continue;
52 TNamed *tn = (TNamed*)hash.FindObject(ts.Data());
54 tn =
new TNamed(ts.Data(),
"");
57 tn->SetUniqueID((UInt_t)fNMakers);
58 mArray.AddAtAndExpand(tn,fNMakers);
60 idx = tn->GetUniqueID();
76 double *GetDat(
int evt) {
return fDat.GetArray()+evt*(kMaxData);}
77 double *GetEvt(
int evt) {
return GetDat(evt)+2;}
78 double &GetEvtRes(
int evt) {
return GetEvt(evt)[-1];}
79 double &GetEvtSiz(
int evt) {
return GetEvt(evt)[-2];}
85 memset(QQ,0,
sizeof(
double)*kMaxData);
88 int kind,idx;
double exe,heap,free,inc;
90 int nkind[4] = {0,0,0,0};
91 int kase = 0,oldKind=0,num = 0,nmk=0,narr;
93 while ((name = rr.Next(kind,idx,exe,heap,free,inc))) {
95 if (kind<kClear)
continue;
99 if (!oldKind) { kase = kind; }
100 else if (kind==oldKind) { kase = kind +10;}
101 else { kase = oldKind+20;}
103 SWIT:
switch (kase) {
116 narr = fDat.GetSize();
117 if (narr< (fNEvts+1)*kMaxData) fDat.Set((fNEvts+10)*kMaxData*2);
120 memcpy(GetDat(fNEvts),QQ,kMaxData*
sizeof(
double));
125 memset(QQ,0,
sizeof(
double)*kMaxData);
146 void LeakGraph(
char *file);
147 void LeakFit (
char *file);
149 void LeakFinder(
char *file,
int kase=1,
const char *par1=0)
152 case 0: LeakGraph(file);
break;
153 case 1:
if (!TClassTable::GetDict(
"TCL")) {gSystem->Load(
"libTable");}
154 LeakFit (file);
break;
155 case 2: LeakCount(file,par1);
break;
160 void LeakGraph(
char *file)
166 int kind,idx;
double exe,heap,free,inc;
168 float yMax =0, yMin = 1000000.,xMax;
169 while ((name = rr.Next(kind,idx,exe,heap,free,inc))) {
171 if (kind==kCtr)
continue;
173 int n = X[0].GetSize();
174 if (num>=n) {
for (
int i=0;i<4;i++){X[i].Set(n*2+10);}}
176 if (yMax < exe ) yMax = exe;
177 if (yMax < heap) yMax = heap;
178 if (yMax < free) yMax = free;
179 if (yMin > exe ) yMin = exe;
180 if (yMin > heap) yMin = heap;
181 if (yMin > free) yMin = free;
188 if (kind!=kClear)
continue;
189 if (strcmp(
"bfc",name))
continue;
191 if (nXX>=n) {
for (
int i=0;i<2;i++){XX[i].Set(n*2+10);}}
200 float fact = float(nXX)/nPoints;
202 for (
int i=0;i<num;i++) {X [0][i] = X [0][i]*fact;}
203 for (
int i=0;i<nXX;i++) {XX[0][i] = XX[0][i]*fact;}
205 TCanvas *C1 =
new TCanvas(
"LEAK",
"Memory grow",1);
207 for (
int i=0;i<3;i++){pl[i] =
new TGraph(nPoints, X[0].GetArray(), X[i+1].GetArray());}
208 pl[3] =
new TGraph(nXX ,XX[0].GetArray(),XX[1 ].GetArray());
209 pl[0]->SetLineColor(kBlack);
210 pl[1]->SetLineColor(kBlue );
211 pl[2]->SetLineColor(kGreen);
212 pl[3]->SetLineColor(kRed );
214 pl[0]->SetName(
"Exe");
215 pl[1]->SetName(
"Heap");
216 pl[2]->SetName(
"Free");
217 pl[3]->SetName(
"Clear");
219 C1->DrawFrame(0.,yMin,xMax,yMax);
222 for (
int i=0;i<3;i++) {
if (pl[i]) pl[i]->Draw(
"LP");}
229 void LeakFit(
char *file)
232 int ignore[kMaxMake];
233 memset(ignore,0,kMaxMake*
sizeof(
int));
234 double A[kMaxMake][kMaxMake],B[kMaxMake],Q[kMaxMake],V[kMaxMake];
235 TCL::vzero(A[0],(kMaxMake)*(kMaxMake));
236 TCL::vzero(B ,kMaxMake);
237 TCL::vzero(V ,kMaxMake);
239 double Corr[5][kMaxMake];
240 TCL::vzero(Corr[0],5*(kMaxMake));
243 TCanvas *C1 =
new TCanvas(
"LeakPlot",
"Leak vs Size",1);
246 TH2F *H1 =
new TH2F(
"LeakPlot",
"Leak vs Size", 100, 0, 50., 100, -0.1, 3.);
247 TH2F *H2 =
new TH2F(
"LeagPlot",
"Leag vs Size", 100, 0, 50., 100, -0.1, 3.);
249 C1->cd(1); H1->Draw();
250 C1->cd(2); H2->Draw();
255 int num = 0,nEvents=0,nMk=0,nFill=0,iWeight=0;
257 double emptySize = 10;
262 for (
int ievt=0;ievt<nEvents;ievt++) {
263 double diff = FF.GetEvtRes(ievt);
264 double eSize = FF.GetEvtSiz(ievt);
265 if (ievt<=skipEvents)
continue;
266 H1->Fill(eSize,diff);
267 if (eSize < emptySize+0.1)
continue;
269 TCL::ucopy(FF.GetEvt(ievt),Q,nMk+1);
271 TCL::vadd(V,Q,V,nMk+1);
273 for (
int i=1;i<=nMk;i++){
274 if (fabs(Q[i])>Qmax) Qmax=fabs(Q[i]);
275 if (Q[i]< 0.1*diff) Q[i]=0.;
279 if (iWeight==1) wt =1./pow(diff,2);
280 if (iWeight==2) wt =1./pow(eSize-emptySize,2);
281 if (iWeight==3) wt =1./pow(Qmax,2);
283 for (
int i1=0;i1<=nMk;i1++){
284 B[i1]+= diff*Q[i1]*wt;
286 for (
int i2=0;i2<=nMk;i2++){ A[i1][i2] += Q[i1]*Q[i2]*wt;}
290 for (
int i=1;i<=nMk;i++) {
293 Corr[2][i] += Q[i]*Q[i];
294 Corr[3][i] += diff*diff;
295 Corr[4][i] += diff*Q[i];
301 double scale = 1./nFill;
302 TCL::vscale(B,scale,B,nX);
303 TCL::vscale(A[0],scale,A[0],(kMaxMake)*(kMaxMake));
309 printf(
"%d makers %d events filled %d times\n\n",nMk,nEvents,nFill);
311 for (
int ign=0;ign<nX;ign++) {
312 if(!ignore[ign])
continue;
314 for (
int i=0;i<nX;i++) B[i]-=A[i][ign];
315 for (
int i=0;i<nX;i++) {A[i][ign]=0;A[ign][i]=0;}
316 A[ign][ign]=1; B[ign]=1;
318 for (
int i=0;i<nX;i++) {A[i][ign]=0;A[ign][i]=0;}
319 A[ign][ign]=1; B[ign]=0;
323 for (
int i=0;i<nX;i++) {
324 if (ignore[i])
continue;
325 if (A[i][i]>reg) reg = A[i][i];
329 TArrayD AA(nX*nX),BB(nX);
330 for (
int i1=0;i1<nX;i1++) {
333 for (
int i2=0;i2<nX;i2++) {
335 AA[i1+nX*i2] = A[i1][i2];
336 if(i1==i2) AA[i1+nX*i2]+=reg;
341 for (
int i=1;i<nX;i++) {
342 if (ignore[i])
continue;
344 if (bj < 0.01) {nneg++; ignore[i]=-1;}
345 if (bj > 1.00) {nneg++; ignore[i]= 1;}
349 for (
int i=1;i<nX;i++) {
350 if (ignore[i]<0)
continue;
352 double est = bj*V[i];
353 if (fabs(bj ) <= 0.0)
continue;
354 if (fabs(est) <= 0.0)
continue;
357 printf (
"Maker(%d) %s \tCorr =%g \tLeak =%g\n",i,RR.Name(i),bj,est);
362 for (
int ievt=0;ievt<nEvents;ievt++) {
363 double diff = FF.GetEvtRes(ievt);
364 double eSize = FF.GetEvtSiz(ievt);
365 if (ievt<=skipEvents)
continue;
366 double dot = TCL::vdot(FF.GetEvt(ievt),BB.GetArray(),nX);
367 H2->Fill(eSize,diff-dot);
374 for (
int i=1;i<=nMk;i++) {
375 for (
int j=0;j<5;j++) {Corr[j][i]/=nCorr;}
376 double x = Corr[0][i];
377 double r = Corr[1][i];
378 double xx = Corr[2][i];
379 double rr = Corr[3][i];
380 double xr = Corr[4][i];
383 double Dxx = xx - x*x;
384 if (Dxx< 1.e-10)
continue;
385 double Drr = rr - r*r;
386 double Dxr = xr - x*r;
387 double chisq = 1.e+10;
390 double chisq = a*a+b*b*xx+rr+2.*a*b*x-2*a*r-2*b*xr;
393 if (b<0. || b> 1.2) chisq+=1.e+6;
396 int *Idx= (
int*)Corr[5];
397 double *bb = Corr[1];
398 double *sq = Corr[2];
399 TMath::Sort(nMk,sq+1,Idx+1,0);
401 for (
int i=1;i<=nMk;i++) {
403 assert(j>0 && j<=nMk);
404 if (sq[j]>=1.e+10)
break;
405 leak = V[j]*bb[j]/nFill;
406 printf(
"%4d - %12s(%d) Chisq =%g Corr = %g Leak=%g\n",i,RR.Name(j),j,sq[j],bb[j],leak);
408 printf(
"===================End Of LeakFit========================");
412 void LeakCount(
char *file,
const char *sele)
417 int kind,idx;
double exe,heap,free,inc;
422 while ((name = rr.Next(kind,idx,exe,heap,free,inc))) {
423 if (kind<2)
continue;
424 if (sele && *sele && strcmp(name,sele))
continue;
427 printf(
"%4d - %20s \t%d %d \t %12.6f %12.6f %+12.6f\t%12.6f\n",num,name,kind,idx,exe,heap,inc,summ);
430 printf(
"%s = %d %g\n",sele,num,summ);
static float * trsequ(float *smx, int m=3, float *b=0, int n=1)