27 #include "RConfigure.h"
60 ClassImp(TProofBench);
64 TF1 *TProofBench::fgFp1 = 0;
65 TF1 *TProofBench::fgFp1n = 0;
66 TF1 *TProofBench::fgFp2 = 0;
67 TF1 *TProofBench::fgFp2n = 0;
68 TF1 *TProofBench::fgFp3 = 0;
69 TF1 *TProofBench::fgFp3n = 0;
70 TF1 *TProofBench::fgFio = 0;
71 TF1 *TProofBench::fgFioV = 0;
72 static Int_t gFioVn0 = -1;
73 static Int_t gFioVn1 = -1;
75 TList *TProofBench::fgGraphs =
new TList;
80 Double_t funp1(Double_t *xx, Double_t *par)
82 Double_t res = par[0] + par[1] * xx[0];
89 Double_t funp2(Double_t *xx, Double_t *par)
91 Double_t res = par[0] + par[1] * xx[0] + par[2] * xx[0] * xx[0];
98 Double_t funp1n(Double_t *xx, Double_t *par)
100 Double_t res = par[0] / xx[0] + par[1];
107 Double_t funp2n(Double_t *xx, Double_t *par)
109 Double_t res = par[0] / xx[0] + par[1] + par[2] * xx[0];
116 Double_t funio(Double_t *xx, Double_t *par)
118 Double_t sat = par[0] / par[1] * (xx[0] * par[1] / par[2] - 1.);
119 if (xx[0] < par[2] / par[1]) sat = 0.;
120 Double_t res = par[0] * xx[0] / (1. + sat);
127 Double_t funiov(Double_t *xx, Double_t *par)
135 Double_t rio = par[0] / par[3] * xx[0];
136 if (xx[0] > par[3]) rio = par[0];
138 Double_t rcpu = par[1] * xx[0];
139 if (xx[0] > gFioVn0) rcpu = par[1]*gFioVn0 + par[2]*(xx[0] - gFioVn0);
140 if (xx[0] > gFioVn1) rcpu = par[1]*gFioVn0 + par[2]*(gFioVn1 - gFioVn0);
142 Double_t res = 1. / (1./par[4] + 1./rio + 1./rcpu);
150 Double_t funcpuv(Double_t *xx, Double_t *par)
156 Double_t n = (xx[0] - par[0]);
157 Double_t rcpu = par[1] * n;
158 if (xx[0] > gFioVn0) rcpu = par[1]*gFioVn0 + par[2]*(n - gFioVn0);
159 if (xx[0] > gFioVn1) rcpu = par[1]*gFioVn0 + par[2]*(gFioVn1 - gFioVn0);
167 Double_t funcpuvn(Double_t *xx, Double_t *par)
173 Double_t n = (xx[0] - par[0]);
174 Double_t rcpu = par[1] * n;
175 if (xx[0] > gFioVn0) rcpu = par[1]*gFioVn0 + par[2]*(n - gFioVn0);
176 if (xx[0] > gFioVn1) rcpu = par[1]*gFioVn0 + par[2]*(gFioVn1 - gFioVn0);
184 TProofBench::TProofBench(
const char *url,
const char *outfile,
const char *proofopt)
185 : fUnlinkOutfile(kFALSE), fProofDS(0), fOutFile(0),
186 fNtries(4), fHistType(0), fNHist(16), fReadType(0),
187 fDataSet(
"BenchDataSet"), fNFilesWrk(2), fReleaseCache(kTRUE),
188 fDataGenSel(kPROOF_BenchSelDataGenDef),
189 fRunCPU(0), fRunDS(0), fDS(0), fDebug(kFALSE), fDescription(0)
191 SetBit(kInvalidObject);
193 Error(
"TProofBench",
"specifying a PROOF master url is mandatory - cannot continue");
196 if (!(fProof = TProof::Open(url, proofopt)) || (fProof && !fProof->IsValid())) {
197 Error(
"TProofBench",
"could not open a valid PROOF session - cannot continue");
201 fNumWrkMax = fProof->GetParallel();
202 if (fProof->UseDynamicStartup() && TProof::GetEnvVars()) {
204 TNamed *n = (TNamed *) TProof::GetEnvVars()->FindObject(
"PROOF_NWORKERS");
206 Error(
"TProofBench",
"dynamic mode: you must specify the max number of workers");
211 TString sn(n->GetTitle());
212 if (sn.IsDigit()) fNumWrkMax = sn.Atoi();
214 Error(
"TProofBench",
"dynamic mode: wrong specification of the max number of"
215 " workers ('%s')", n->GetTitle());
221 if (fNumWrkMax <= 0) {
222 Error(
"TProofBench",
"wrong max number of workers ('%d')", fNumWrkMax);
230 ResetBit(kInvalidObject);
233 TString host(TString::Format(
"PROOF at %s", u.GetHost()));
234 if (!strcmp(u.GetProtocol(),
"lite")) host.Form(
"PROOF-Lite on %s", gSystem->HostName());
235 fDescription =
new TNamed(
"PB_description",
236 TString::Format(
"%s, %d workers", host.Data(), fNumWrkMax).Data());
237 Printf(
" Run description: %s", fDescription->GetTitle());
239 if (SetOutFile(outfile, kFALSE) != 0)
240 Warning(
"TProofBench",
"problems opening '%s' - ignoring: use SetOutFile to try"
241 " again or with another file", outfile);
247 TProofBench::~TProofBench()
250 if (fUnlinkOutfile) gSystem->Unlink(fOutFileName);
251 SafeDelete(fReadType);
254 SafeDelete(fDescription);
261 Int_t TProofBench::OpenOutFile(Bool_t wrt, Bool_t verbose)
264 if (fOutFile && fOutFile->IsZombie()) SafeDelete(fOutFile);
267 if (!fOutFile && fOutFileName.Length() > 0) {
268 const char *mode = 0;
270 mode = gSystem->AccessPathName(fOutFileName) ?
"RECREATE" :
"UPDATE";
273 if (!(fOutFile = TFile::Open(fOutFileName, mode)) || (fOutFile && fOutFile->IsZombie())) {
275 Warning(
"OpenOutFile",
"problems opening '%s' - ignoring: use SetOutFile to try"
276 " again or with another file", fOutFileName.Data());
280 gROOT->GetListOfFiles()->Remove(fOutFile);
281 if (!strcmp(mode,
"RECREATE")) {
284 fDescription->Write();
295 Int_t TProofBench::SetOutFile(
const char *outfile, Bool_t verbose)
300 if (!fOutFile->IsZombie()) fOutFile->Close();
301 SafeDelete(fOutFile);
304 fOutFileName = outfile;
305 if (fOutFileName ==
"<default>") {
308 const char *lite = (fProof->IsLite()) ?
"-lite" :
"";
309 fOutFileName.Form(
"proofbench-%s%s-%dw-%d-%.2d%.2d.root",
310 fProof->GetMaster(), lite, fNumWrkMax,
311 dat.GetDate(), dat.GetHour(), dat.GetMinute());
312 Info(
"SetOutFile",
"using default output file: '%s'", fOutFileName.Data());
313 fUnlinkOutfile = kTRUE;
315 if (!fOutFileName.IsNull()) {
316 if ((rc = OpenOutFile(kTRUE, kFALSE)) != 0 && verbose)
317 Warning(
"SetOutFile",
"problems opening '%s' - ignoring: use SetOutFile to try"
318 " again or with another file", outfile);
326 void TProofBench::CloseOutFile()
328 if (SetOutFile(0) != 0)
329 Warning(
"CloseOutFile",
"problems closing '%s'", fOutFileName.Data());
336 Int_t TProofBench::RunCPU(Long64_t nevents, Int_t start, Int_t stop, Int_t step)
339 if (OpenOutFile(kTRUE) != 0) {
340 Error(
"RunCPU",
"problems opening '%s' to save the result", fOutFileName.Data());
343 fUnlinkOutfile = kFALSE;
346 TPBHistType *htype =
new TPBHistType(TPBHistType::kHist1D);
347 fRunCPU =
new TProofBenchRunCPU(htype, fNHist, fOutFile);
348 if (!fCPUSel.IsNull()) fRunCPU->SetSelName(fCPUSel);
349 if (!fSelOption.IsNull()) fRunDS->SetSelOption(fSelOption);
350 if (!fCPUPar.IsNull()) fRunCPU->SetParList(fCPUPar);
351 fRunCPU->Run(nevents, start, stop, step, fNtries, fDebug, -1);
354 if (SetOutFile(0) != 0)
355 Warning(
"RunCPU",
"problems closing '%s'", fOutFileName.Data());
365 Int_t TProofBench::RunCPUx(Long64_t nevents, Int_t start, Int_t stop)
368 if (OpenOutFile(kTRUE) != 0) {
369 Error(
"RunCPUx",
"problems opening '%s' to save the result", fOutFileName.Data());
372 fUnlinkOutfile = kFALSE;
375 TPBHistType *htype =
new TPBHistType(TPBHistType::kHist1D);
376 fRunCPU =
new TProofBenchRunCPU(htype, fNHist, fOutFile);
377 if (!fCPUSel.IsNull()) fRunCPU->SetSelName(fCPUSel);
378 if (!fSelOption.IsNull()) fRunDS->SetSelOption(fSelOption);
379 if (!fCPUPar.IsNull()) fRunCPU->SetParList(fCPUPar);
380 fRunCPU->Run(nevents, start, stop, -2, fNtries, fDebug, -1);
383 if (SetOutFile(0) != 0)
384 Warning(
"RunCPUx",
"problems closing '%s'", fOutFileName.Data());
408 void TProofBench::DrawCPU(
const char *outfile,
const char *opt, Bool_t verbose,
409 Int_t dofit, Int_t n0, Int_t n1)
412 TFile *fout = TFile::Open(outfile,
"READ");
413 if (!fout || (fout && fout->IsZombie())) {
414 ::Error(
"DrawCPU",
"could not open file '%s' ...", outfile);
419 TString description(
"<not available>");
420 TNamed *nmdesc = (TNamed *) fout->Get(
"PB_description");
421 if (nmdesc) description = nmdesc->GetTitle();
425 Bool_t isNorm = (oo.Contains(
"norm")) ? kTRUE : kFALSE;
426 Bool_t isX = (oo.Contains(
"stdx:") || oo.Contains(
"normx:")) ? kTRUE : kFALSE;
427 Bool_t doAvg = kTRUE, doMax = kTRUE;
428 if (oo.Contains(
"avg:")) doMax = kFALSE;
429 if (oo.Contains(
"max:")) doAvg = kFALSE;
431 const char *dirn = (isX) ?
"RunCPUx" :
"RunCPU";
432 TDirectory *d = (TDirectory *) fout->Get(dirn);
434 ::Error(
"DrawCPU",
"could not find directory '%s' ...", dirn);
441 TString hprofn, hmaxn;
442 const char *lx = (isX) ?
"_x" :
"";
443 const char *ln = (isNorm) ?
"Norm" :
"Prof";
444 hprofn.Form(
"%s%s_CPU_QR_Evts", ln, lx);
445 hmaxn.Form(
"%s%s_CPU_PS_MaxEvts", ln, lx);
447 Double_t xmin = -1., xmax = -1.;
448 Double_t ami = -1., amx = -1., mmi = -1., mmx = -1.;
449 Int_t kamx = -1, kmmx = -1, nbins = -1;
450 Double_t ymx = -1., ymi = -1.;
456 TGraphErrors *grav = 0;
458 if (!(grav = GetGraph(d, hprofn, nbins, xmin, xmax, ami, amx, kamx, pfav))) {
459 ::Error(
"DrawCPU",
"could not find '%s' ...", hprofn.Data());
470 TGraphErrors *grmx = 0;
472 if (!(grmx = GetGraph(d, hmaxn, nbins, xmin, xmax, mmi, mmx, kmmx, pfmx))) {
473 ::Warning(
"DrawCPU",
"could not find '%s': feature added in 5.34/11", hmaxn.Data());
482 if (mmx > ymx) ymx = mmx;
483 if ((ymi > 0 && mmi < ymi) || (ymi < 0.)) ymi = mmi;
489 TCanvas *cpu =
new TCanvas(
"cpu",
"Rate vs wrks",204,69,1050,502);
490 cpu->Range(-3.106332,0.7490716,28.1362,1.249867);
492 TH1F *hgr =
new TH1F(
"Graph-CPU",
" CPU speed-up", nbins*4, xmin, xmax);
493 hgr->SetMaximum(ymx + (ymx-ymi)*0.2);
495 if (isNorm) hgr->SetMaximum(ymx*1.2);
496 hgr->SetDirectory(0);
498 hgr->GetXaxis()->SetTitle(pf->GetXaxis()->GetTitle());
499 hgr->GetXaxis()->CenterTitle(
true);
500 hgr->GetXaxis()->SetLabelSize(0.05);
501 hgr->GetXaxis()->SetTitleSize(0.06);
502 hgr->GetXaxis()->SetTitleOffset(0.62);
503 hgr->GetYaxis()->SetTitleSize(0.08);
504 hgr->GetYaxis()->SetTitleOffset(0.52);
505 hgr->GetYaxis()->SetTitle(
"Rate (events/s)");
509 leg =
new TLegend(0.7, 0.8, 0.9, 0.9);
511 leg =
new TLegend(0.1, 0.8, 0.3, 0.9);
514 gStyle->SetOptTitle(0);
515 TGraphErrors *gr = 0;
517 grav->SetFillColor(1);
518 grav->SetLineColor(13);
519 grav->SetMarkerColor(4);
520 grav->SetMarkerStyle(21);
521 grav->SetMarkerSize(1.2);
522 grav->SetHistogram(hgr);
524 if (verbose) grav->Print();
526 leg->AddEntry(grav,
"Average",
"P");
530 grmx->SetFillColor(1);
531 grmx->SetLineColor(13);
532 grmx->SetMarkerColor(2);
533 grmx->SetMarkerStyle(29);
534 grmx->SetMarkerSize(1.8);
535 grmx->SetHistogram(hgr);
537 if (verbose) grmx->Print();
539 grmx->Draw(
"lpSAME");
543 leg->AddEntry(grmx,
"Maximum",
"P");
552 if (nbins > 5) xmi = 1.5;
553 AssertFittingFun(xmi, nbins + .1);
556 Double_t normrate = -1.;
559 fgFp1n->SetParameter(0, pf->GetBinContent(1));
560 fgFp1n->SetParameter(1, pf->GetBinContent(nbins-1));
562 if (verbose) fgFp1n->Print();
563 normrate = fgFp1n->GetParameter(1);
565 fgFp1->SetParameter(0, 0.);
566 fgFp1->SetParameter(1, pf->GetBinContent(1));
568 if (verbose) fgFp1->Print();
569 normrate = fgFp1->Derivative(1.);
571 }
else if (dofit == 2) {
573 fgFp2n->SetParameter(0, pf->GetBinContent(1));
574 fgFp2n->SetParameter(1, pf->GetBinContent(nbins-1));
575 fgFp2n->SetParameter(2, 0.);
577 if (verbose) fgFp2n->Print();
578 normrate = fgFp2n->GetParameter(1);
580 fgFp2->SetParameter(0, 0.);
581 fgFp2->SetParameter(1, pf->GetBinContent(1));
582 fgFp2->SetParameter(2, 0.);
584 if (verbose) fgFp2->Print();
585 normrate = fgFp2->Derivative(1.);
589 gFioVn0 = (n0 > 0) ? n0 : (Int_t) (nbins + .1)/2.;
590 gFioVn1 = (n1 > 0) ? n1 : (Int_t) (nbins + .1);
592 fgFp3n->SetParameter(0, 0.);
593 fgFp3n->SetParameter(1, pf->GetBinContent(1));
594 fgFp3n->SetParameter(2, pf->GetBinContent(nbins-1));
596 if (verbose) fgFp3n->Print();
597 normrate = pf->GetBinContent(1);
599 fgFp3->SetParameter(0, 0.);
600 fgFp3->SetParameter(1, 0.);
601 fgFp3->SetParameter(2, pf->GetBinContent(1));
603 if (verbose) fgFp3->Print();
604 normrate = fgFp3->Derivative(1.);
610 printf(
"* ************************************************************ *\n");
612 printf(
"* Cluster: %s\n", description.Data());
613 printf(
"* Performance measurement from scalability plot: *\n");
615 printf(
"* rate max: %.3f\tmegaRNGPS (@ %d workers)\n", ymx/1000000, kmx);
617 printf(
"* per-worker rate: %.3f\tmegaRNGPS \n", normrate/1000000);
618 printf(
"* ************************************************************ *\n");
620 printf(
"* ************************************************************ *\n");
622 printf(
"* Cluster: %s\n", description.Data());
624 printf(
"* Per-worker rate from normalized plot: %.3f\tmegaRNGPS\n", normrate/1000000);
625 printf(
"* ************************************************************ *\n");
630 if (grav) fgGraphs->Add(grav);
631 if (grmx) fgGraphs->Add(grmx);
638 TGraphErrors *TProofBench::GetGraph(TDirectory *d,
const char *pfn, Int_t &nb,
639 Double_t &xmi, Double_t &xmx,
640 Double_t &ymi, Double_t &ymx, Int_t &kmx, TProfile *&pf)
643 if (!d || !pfn || (pfn && strlen(pfn) <= 0)) {
644 ::Error(
"TProofBench::GetGraph",
"directory or name not defined!");
645 return (TGraphErrors *)0;
648 TList *keylist = d->GetListOfKeys();
651 while ((key = (TKey *) nxk())) {
652 if (TString(key->GetName()).BeginsWith(pfn)) {
653 pf = (TProfile *) d->Get(key->GetName());
659 ::Error(
"TProofBench::GetGraph",
"TProfile for '%s' not found in directory '%s'", pfn, d->GetName());
660 return (TGraphErrors *)0;
663 nb = pf->GetNbinsX();
664 TGraphErrors *gr =
new TGraphErrors(nb);
665 gr->SetName(TString::Format(
"Graph_%s", pfn));
666 Double_t xx, ex, yy, ey;
667 ymi = pf->GetBinContent(1);
669 xmi = pf->GetBinCenter(1) - pf->GetBinWidth(1)/2. ;
670 xmx = pf->GetBinCenter(nb) + pf->GetBinWidth(nb)/2. ;
672 for (Int_t k = 1;k <= nb; k++) {
673 xx = pf->GetBinCenter(k);
674 ex = pf->GetBinWidth(k) * .001;
675 yy = pf->GetBinContent(k);
676 ey = pf->GetBinError(k);
682 if (yy < ymi) ymi = yy;
683 if (yy > ymx) { ymx = yy; kmx = k; }
685 gr->SetPoint(k-1, xx, yy);
686 gr->SetPointError(k-1, ex, ey);
696 void TProofBench::AssertFittingFun(Double_t mi, Double_t mx)
699 fgFp1 =
new TF1(
"funp1", funp1, mi, mx, 2);
700 fgFp1->SetParNames(
"offset",
"slope");
704 fgFp1n =
new TF1(
"funp1n", funp1n, mi, mx, 2);
705 fgFp1n->SetParNames(
"decay",
"norm rate");
709 fgFp2 =
new TF1(
"funp2", funp2, mi, mx, 3);
710 fgFp2->SetParNames(
"offset",
"slope",
"deviation");
714 fgFp2n =
new TF1(
"funp2n", funp2n, mi, mx, 3);
715 fgFp2n->SetParNames(
"decay",
"norm rate",
"deviation");
719 fgFp3 =
new TF1(
"funcpuv", funcpuv, mi, mx, 3);
720 fgFp3->SetParNames(
"offset",
"slope real",
"slope hyper");
724 fgFp3n =
new TF1(
"funcpuvn", funcpuvn, mi, mx, 3);
725 fgFp3n->SetParNames(
"offset",
"slope real",
"slope hyper");
729 fgFio =
new TF1(
"funio", funio, mi, mx, 3);
730 fgFio->SetParNames(
"R1",
"RIO",
"TotIO");
733 fgFioV =
new TF1(
"funiov", funiov, mi, mx, 5);
734 fgFioV->SetParNames(
"rio",
"b1",
"b2",
"nc",
"ri");
741 class fileDesc :
public TNamed {
745 fileDesc(
const char *n,
const char *o,
746 Long_t t,
const char *d) : TNamed(n, o), fMtime(t), fDesc(d) { }
747 Int_t Compare(
const TObject *o)
const {
748 const fileDesc *fd =
static_cast<const fileDesc *
>(o);
749 if (!fd || (fd && fd->fMtime == fMtime))
return 0;
750 if (fMtime < fd->fMtime)
return -1;
760 void TProofBench::GetPerfSpecs(
const char *path, Int_t degfit)
763 TString pp(path), fn, oo;
764 if (pp.IsNull()) pp = gSystem->WorkingDirectory();
766 if (gSystem->GetPathInfo(pp.Data(), st) != 0) {
767 ::Error(
"TProofBench::GetPerfSpecs",
"path '%s' could not be stat'ed - abort", pp.Data());
771 if (R_ISDIR(st.fMode)) {
773 void *dirp = gSystem->OpenDirectory(pp.Data());
775 ::Error(
"TProofBench::GetPerfSpecs",
"directory path '%s' could nto be open - abort", pp.Data());
779 while ((ent = gSystem->GetDirEntry(dirp))) {
780 if (!strcmp(ent,
".") || !strcmp(ent,
".."))
continue;
781 fn.Form(
"%s/%s", pp.Data(), ent);
782 if (gSystem->GetPathInfo(fn.Data(), st) != 0)
continue;
783 if (!R_ISREG(st.fMode))
continue;
784 fn +=
"?filetype=raw";
785 TFile *f = TFile::Open(fn);
788 if (!f->ReadBuffer(rr, 4)) {
789 if (!strncmp(rr,
"root", 4)) {
791 fn.ReplaceAll(
"?filetype=raw",
"");
792 if ((f = TFile::Open(fn))) {
793 TString desc(
"<no decription>");
794 TNamed *nmdesc = (TNamed *) f->Get(
"PB_description");
795 if (nmdesc) desc = nmdesc->GetTitle();
796 if (f->GetListOfKeys()->FindObject(
"RunCPU"))
797 filels.Add(
new fileDesc(fn,
"std:", st.fMtime, desc.Data()));
798 if (f->GetListOfKeys()->FindObject(
"RunCPUx"))
799 filels.Add(
new fileDesc(fn,
"stdx:", st.fMtime, desc.Data()));
801 ::Warning(
"TProofBench::GetPerfSpecs",
"problems opening '%s'", fn.Data());
807 }
else if (!R_ISREG(st.fMode)) {
808 ::Error(
"TProofBench::GetPerfSpecs",
809 "path '%s' not a regular file nor a directory - abort", pp.Data());
816 Bool_t isOk = kFALSE;
817 if (gSystem->GetPathInfo(fn.Data(), st) == 0) {
818 fn +=
"?filetype=raw";
819 TFile *f = TFile::Open(fn);
822 if (!(f->ReadBuffer(rr, 4))) {
823 if (!strncmp(rr,
"root", 4)) {
824 fn.ReplaceAll(
"?filetype=raw",
"");
825 if ((f = TFile::Open(fn))) {
826 if (f->GetListOfKeys()->FindObject(
"RunCPU")) oo =
"std:";
827 if (f->GetListOfKeys()->FindObject(
"RunCPUx")) oo =
"stdx:";
832 emsg.Form(
"path '%s' does not contain the relevant dirs - abort", fn.Data());
835 emsg.Form(
"path '%s' cannot be open - abort", fn.Data());
838 emsg.Form(
"'%s' is not a ROOT file - abort", fn.Data());
841 emsg.Form(
"could not read first 4 bytes from '%s' - abort", fn.Data());
845 emsg.Form(
"path '%s' cannot be open in raw mode - abort", fn.Data());
848 emsg.Form(
"path '%s' cannot be stated - abort", fn.Data());
851 ::Error(
"TProofBench::GetPerfSpecs",
"%s", emsg.Data());
858 if (filels.GetSize() == 1) {
859 nm = (fileDesc *) filels.First();
862 }
else if (filels.GetSize() > 1) {
865 Printf(
"Several possible files found:");
866 while ((nm = (fileDesc *) nxf())) {
867 Printf(
" %d\t%s\t%s\t%s (file: %s)", idx++, nm->GetTitle(),
868 TTimeStamp(nm->fMtime).AsString(
"s"), nm->fDesc.Data(), nm->GetName());
870 TString a(Getline(TString::Format(
"Make your choice [%d] ", idx-1)));
871 if (a.IsNull() || a[0] ==
'\n') a.Form(
"%d", idx-1);
873 if ((nm = (fileDesc *) filels.At(idx))) {
877 ::Error(
"TProofBench::GetPerfSpecs",
"chosen index '%d' does not exist - abort", idx);
882 ::Error(
"TProofBench::GetPerfSpecs",
883 "path '%s' is a directory but no ROOT file found in it - abort", pp.Data());
889 TProofBench::DrawCPU(fn.Data(), oo.Data(), kFALSE, degfit);
897 Int_t TProofBench::RunDataSet(
const char *dset,
898 Int_t start, Int_t stop, Int_t step)
900 if (OpenOutFile(kTRUE) != 0) {
901 Error(
"RunDataSet",
"problems opening '%s' to save the result", fOutFileName.Data());
904 fUnlinkOutfile = kFALSE;
906 if (fReleaseCache) ReleaseCache(dset);
908 TPBReadType *readType = fReadType;
909 if (!readType) readType =
new TPBReadType(TPBReadType::kReadOpt);
910 fRunDS =
new TProofBenchRunDataRead(fDS, readType, fOutFile);
911 if (!fDataSel.IsNull()) fRunDS->SetSelName(fDataSel);
912 if (!fSelOption.IsNull()) fRunDS->SetSelOption(fSelOption);
913 if (!fDataPar.IsNull()) fRunDS->SetParList(fDataPar);
914 fRunDS->SetReleaseCache(fReleaseCache);
915 fRunDS->Run(dset, start, stop, step, fNtries, fDebug, -1);
916 SafeDelete(readType);
919 if (SetOutFile(0) != 0)
920 Warning(
"RunDataSet",
"problems closing '%s'", fOutFileName.Data());
932 Int_t TProofBench::RunDataSetx(
const char *dset, Int_t start, Int_t stop)
934 if (OpenOutFile(kTRUE) != 0) {
935 Error(
"RunDataSetx",
"problems opening '%s' to save the result", fOutFileName.Data());
938 fUnlinkOutfile = kFALSE;
942 TPBReadType *readType = fReadType;
943 if (!readType) readType =
new TPBReadType(TPBReadType::kReadOpt);
944 fRunDS =
new TProofBenchRunDataRead(fDS, readType, fOutFile);
945 if (!fDataSel.IsNull()) fRunDS->SetSelName(fDataSel);
946 if (!fSelOption.IsNull()) fRunDS->SetSelOption(fSelOption);
947 if (!fDataPar.IsNull()) fRunDS->SetParList(fDataPar);
948 fRunDS->Run(dset, start, stop, -2, fNtries, fDebug, -1);
949 SafeDelete(readType);
952 if (SetOutFile(0) != 0)
953 Warning(
"RunDataSetx",
"problems closing '%s'", fOutFileName.Data());
978 void TProofBench::DrawDataSet(
const char *outfile,
979 const char *opt,
const char *type, Bool_t verbose,
980 Int_t dofit, Int_t n0, Int_t n1)
983 TFile *fout = TFile::Open(outfile,
"READ");
984 if (!fout || (fout && fout->IsZombie())) {
985 ::Error(
"DrawDataSet",
"could not open file '%s' ...", outfile);
990 TString description(
"<not available>");
991 TNamed *nmdesc = (TNamed *) fout->Get(
"PB_description");
992 if (nmdesc) description = nmdesc->GetTitle();
996 Bool_t isNorm = (oo.Contains(
"norm")) ? kTRUE : kFALSE;
997 Bool_t isX = (oo.Contains(
"stdx:") || oo.Contains(
"normx:")) ? kTRUE : kFALSE;
998 Bool_t doAvg = (oo.Contains(
"all:") || oo.Contains(
"avg:")) ? kTRUE : kFALSE;
999 Bool_t doMax = (oo.Contains(
"all:") || oo.Contains(
"max:")) ? kTRUE : kFALSE;
1001 const char *dirn = (isX) ?
"RunDataReadx" :
"RunDataRead";
1002 TDirectory *d = (TDirectory *) fout->Get(dirn);
1004 ::Error(
"DrawCPU",
"could not find directory '%s' ...", dirn);
1011 TString hprofn, hmaxn;
1012 const char *lx = (isX) ?
"_x" :
"";
1013 const char *ln = (isNorm) ?
"Norm" :
"Prof";
1014 Bool_t isIO = kTRUE;
1015 if (type && !strcmp(type,
"evts")) {
1016 hprofn.Form(
"%s%s_DataRead_QR_Evts", ln, lx);
1017 hmaxn.Form(
"%s%s_DataRead_PS_MaxEvts", ln, lx);
1020 hprofn.Form(
"%s%s_DataRead_QR_IO", ln, lx);
1021 hmaxn.Form(
"%s%s_DataRead_PS_MaxIO", ln, lx);
1024 Double_t xmin = -1., xmax = -1.;
1025 Double_t ami = -1., amx = -1., mmi = -1., mmx = -1.;
1026 Int_t kamx = -1, kmmx = -1, nbins = -1;
1027 Double_t ymx = -1., ymi = -1.;
1033 TGraphErrors *grav = 0;
1035 if (!(grav = GetGraph(d, hprofn, nbins, xmin, xmax, ami, amx, kamx, pfav))) {
1036 ::Error(
"DrawCPU",
"could not find '%s' ...", hprofn.Data());
1048 TGraphErrors *grmx = 0;
1050 if (!(grmx = GetGraph(d, hmaxn, nbins, xmin, xmax, mmi, mmx, kmmx, pfmx))) {
1051 ::Warning(
"DrawCPU",
"could not find '%s': feature added in 5.34/11", hmaxn.Data());
1060 if (mmx > ymx) ymx = mmx;
1061 if ((ymi > 0 && mmi < ymi) || (ymi < 0.)) ymi = mmi;
1067 TCanvas *cpu =
new TCanvas(
"dataset",
"Rate vs wrks",204,69,1050,502);
1068 cpu->Range(-3.106332,0.7490716,28.1362,1.249867);
1070 TH1F *hgr =
new TH1F(
"Graph-DataSet",
" Data Read speed-up", nbins*4, xmin, xmax);
1071 hgr->SetMaximum(ymx + (ymx-ymi)*0.2);
1073 if (isNorm) hgr->SetMaximum(ymx*1.2);
1074 hgr->SetDirectory(0);
1076 hgr->GetXaxis()->SetTitle(pf->GetXaxis()->GetTitle());
1077 hgr->GetXaxis()->CenterTitle(
true);
1078 hgr->GetXaxis()->SetLabelSize(0.05);
1079 hgr->GetXaxis()->SetTitleSize(0.06);
1080 hgr->GetXaxis()->SetTitleOffset(0.62);
1081 hgr->GetYaxis()->SetLabelSize(0.06);
1082 hgr->GetYaxis()->SetTitleSize(0.08);
1083 hgr->GetYaxis()->SetTitleOffset(0.52);
1085 hgr->GetYaxis()->SetTitle(
"Rate (MB/s)");
1087 hgr->GetYaxis()->SetTitle(
"Rate (events/s)");
1092 leg =
new TLegend(0.7, 0.8, 0.9, 0.9);
1094 leg =
new TLegend(0.1, 0.8, 0.3, 0.9);
1097 TGraphErrors *gr = 0;
1099 grav->SetFillColor(1);
1100 grav->SetLineColor(13);
1101 grav->SetMarkerColor(4);
1102 grav->SetMarkerStyle(21);
1103 grav->SetMarkerSize(1.2);
1104 grav->SetHistogram(hgr);
1106 if (verbose) grav->Print();
1108 leg->AddEntry(grav,
"Average",
"P");
1112 grmx->SetFillColor(1);
1113 grmx->SetLineColor(13);
1114 grmx->SetMarkerColor(2);
1115 grmx->SetMarkerStyle(29);
1116 grmx->SetMarkerSize(1.8);
1117 grmx->SetHistogram(hgr);
1119 if (verbose) grmx->Print();
1121 grmx->Draw(
"lpSAME");
1125 leg->AddEntry(grmx,
"Maximum",
"P");
1131 Double_t normrate = -1.;
1135 if (nbins > 5) xmi = 1.5;
1136 AssertFittingFun(xmi, nbins + .1);
1140 fgFio->SetParameter(0, pf->GetBinContent(1));
1141 fgFio->SetParameter(1, pf->GetBinContent(nbins-1));
1142 fgFio->SetParameter(2, pf->GetBinContent(nbins-1));
1144 if (verbose) fgFio->Print();
1145 normrate = fgFio->Derivative(1.);
1146 }
else if (dofit > 1) {
1148 gFioVn0 = (n0 > 0) ? n0 : (Int_t) (nbins + .1)/2.;
1149 gFioVn1 = (n1 > 0) ? n1 : (Int_t) (nbins + .1);
1150 fgFioV->SetParameter(0, 20.);
1151 fgFioV->SetParameter(1, pf->GetBinContent(1));
1152 fgFioV->SetParameter(2, pf->GetBinContent(1));
1153 fgFioV->SetParameter(3, 4.);
1154 fgFioV->SetParameter(4, 1000.);
1157 if (verbose) fgFio->Print();
1158 normrate = fgFioV->Derivative(1.);
1164 printf(
"* ************************************************************ *\n");
1166 printf(
"* Cluster: %s\n", description.Data());
1167 printf(
"* Performance measurement from scalability plot: *\n");
1170 printf(
"* rate max: %.3f\tMB/s (@ %d workers)\n", ymx, kmx);
1172 printf(
"* per-worker rate: %.3f\tMB/s \n", normrate);
1174 printf(
"* rate max: %.3f\tevts/s (@ %d workers)\n", ymx, kmx);
1176 printf(
"* ************************************************************ *\n");
1180 if (grav) fgGraphs->Add(grav);
1181 if (grmx) fgGraphs->Add(grmx);
1189 void TProofBench::DrawEfficiency(
const char *outfile,
1190 const char *opt, Bool_t verbose)
1193 TFile *fout = TFile::Open(outfile,
"READ");
1194 if (!fout || (fout && fout->IsZombie())) {
1195 ::Error(
"DrawEfficiency",
"could not open file '%s' ...", outfile);
1200 TString description(
"<not available>");
1201 TNamed *nmdesc = (TNamed *) fout->Get(
"PB_description");
1202 if (nmdesc) description = nmdesc->GetTitle();
1205 TString oo(opt), ln(
"CPU");
1206 const char *dirs[4] = {
"RunCPU",
"RunCPUx",
"RunDataRead",
"RunDataReadx"};
1207 const char *labs[4] = {
"CPU",
"CPU",
"DataRead",
"DataRead"};
1208 Int_t fst = 0, lst = 3;
1211 }
else if (oo ==
"cpux") {
1214 }
else if (oo.BeginsWith(
"data")) {
1215 if (oo.EndsWith(
"x")) {
1223 const char *dirn = 0;
1225 for (Int_t i = fst; i <= lst; i++) {
1226 if ((d = (TDirectory *) fout->Get(dirs[i]))) {
1233 ::Error(
"DrawEfficiency",
"could not find directory ...");
1241 hprof.Form(
"Prof_%s_CPU_eff", ln.Data());
1243 Double_t xmin = -1., xmax = -1.;
1244 Int_t kmx = -1, nbins = -1;
1245 Double_t ymx = -1., ymi = -1.;
1248 TGraphErrors *gr = 0;
1249 if (!(gr = GetGraph(d, hprof, nbins, xmin, xmax, ymi, ymx, kmx, pf))) {
1250 ::Error(
"DrawEfficiency",
"could not find '%s' ...", hprof.Data());
1257 TCanvas *cpu =
new TCanvas(
"efficiency",
"efficiency vs wrks",204,69,1050,502);
1258 cpu->Range(-3.106332,0.7490716,28.1362,1.249867);
1260 TH1F *hgr =
new TH1F(
"Graph-Efficiency",
"CPU effectiveness", nbins*4, xmin, xmax);
1261 hgr->SetMaximum(1.2);
1263 hgr->SetDirectory(0);
1265 hgr->GetXaxis()->SetTitle(pf->GetXaxis()->GetTitle());
1266 hgr->GetXaxis()->CenterTitle(
true);
1267 hgr->GetXaxis()->SetLabelSize(0.05);
1268 hgr->GetXaxis()->SetTitleSize(0.06);
1269 hgr->GetXaxis()->SetTitleOffset(0.62);
1270 hgr->GetYaxis()->SetLabelSize(0.06);
1271 hgr->GetYaxis()->SetTitleSize(0.08);
1272 hgr->GetYaxis()->SetTitleOffset(0.52);
1273 hgr->GetYaxis()->SetTitle(
"CPU effectiveness");
1275 gr->SetFillColor(1);
1276 gr->SetLineColor(13);
1277 gr->SetMarkerColor(4);
1278 gr->SetMarkerStyle(21);
1279 gr->SetMarkerSize(1.2);
1280 gr->SetHistogram(hgr);
1282 if (verbose) gr->Print();
1286 printf(
"* ************************************************************ *\n");
1288 printf(
"* Cluster: %s\n", description.Data());
1289 printf(
"* CPU effectiveness measurement: *\n");
1291 printf(
"* effectiveness max: %.3f (@ %d workers)\n", ymx, kmx);
1293 printf(
"* ************************************************************ *\n");
1296 if (gr) fgGraphs->Add(gr);
1303 Int_t TProofBench::ReleaseCache(
const char *dset)
1306 if (!fDS) fDS =
new TProofBenchDataSet(fProofDS);
1307 return fDS ? fDS->ReleaseCache(dset) : -1;
1315 Int_t TProofBench::RemoveDataSet(
const char *dset)
1318 if (!fDS) fDS =
new TProofBenchDataSet(fProofDS);
1319 return fDS ? fDS->RemoveFiles(dset) : -1;
1343 Int_t TProofBench::MakeDataSet(
const char *dset, Long64_t nevt,
const char *fnroot,
1346 if (dset && strlen(dset) > 0) fDataSet = dset;
1349 if (!TClass::GetClass(fDataGenSel)) {
1351 if (fDataGenSel == kPROOF_BenchSelDataGenDef) {
1353 TString par = TString::Format(
"%s/%s%s.par", TROOT::GetEtcDir().Data(), kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
1354 Info(
"MakeDataSet",
"uploading '%s' ...", par.Data());
1355 if (fProof->UploadPackage(par) != 0) {
1356 Error(
"MakeDataSet",
"problems uploading '%s' - cannot continue", par.Data());
1359 Info(
"MakeDataSet",
"enabling '%s' ...", kPROOF_BenchDataSelPar);
1360 if (fProof->EnablePackage(kPROOF_BenchDataSelPar) != 0) {
1361 Error(
"MakeDataSet",
"problems enabling '%s' - cannot continue", kPROOF_BenchDataSelPar);
1365 if (fDataGenPar.IsNull()) {
1366 Error(
"MakeDataSet",
"you should load the class '%s' before running the benchmark", fDataGenSel.Data());
1373 while (fDataGenPar.Tokenize(par, from,
",")) {
1374 Info(
"MakeDataSet",
"Uploading '%s' ...", par.Data());
1375 if (fProof->UploadPackage(par) != 0) {
1376 Error(
"MakeDataSet",
"problems uploading '%s' - cannot continue", par.Data());
1379 Info(
"MakeDataSet",
"Enabling '%s' ...", par.Data());
1380 if (fProof->EnablePackage(par) != 0) {
1381 Error(
"MakeDataSet",
"problems enabling '%s' - cannot continue", par.Data());
1386 if (!TClass::GetClass(fDataGenSel)) {
1387 Error(
"MakeDataSet",
"failed to load '%s'", fDataGenSel.Data());
1393 TString fn, fnr(
"event");
1394 Bool_t remote = kFALSE;
1395 if (fnroot && strlen(fnroot) > 0) {
1396 TUrl ur(fnroot, kTRUE);
1397 if (!strcmp(ur.GetProtocol(),
"file") &&
1398 !gSystem->IsAbsoluteFileName(ur.GetFile())) {
1401 fnr = gSystem->BaseName(ur.GetFile());
1403 TString bdir(gSystem->DirName(fnroot));
1405 fProof->SetParameter(
"PROOF_BenchmarkBaseDir", bdir.Data());
1407 if (strcmp(ur.GetProtocol(),
"file")) remote = kTRUE;
1410 TProofNodes pn(fProof);
1411 TMap *filesmap =
new TMap;
1412 TMap *nodesmap = pn.GetMapOfNodes();
1413 TIter nxnd(nodesmap);
1417 while ((obj = nxnd()) != 0) {
1418 if ((wli = dynamic_cast<TList *>(nodesmap->GetValue(obj)))) {
1419 THashList *fli =
new THashList;
1420 Int_t nf = wli->GetSize() * fNFilesWrk;
1421 TSlaveInfo *wi = (TSlaveInfo *) wli->First();
1423 fn.Form(
"%s-%s-%d.root", fnr.Data(), wi->GetName(), kf++);
1425 fli->Add(
new TObjString(fn));
1427 filesmap->Add(
new TObjString(obj->GetName()), fli);
1432 filesmap->SetName(
"PROOF_FilesToProcess");
1433 fProof->AddInput(filesmap);
1437 if (TProof::GetParameter(fProof->GetInputList(),
"PROOF_Packetizer", oldpack) != 0) oldpack =
"";
1438 fProof->SetParameter(
"PROOF_Packetizer",
"TPacketizerFile");
1439 Int_t oldnotass = -1;
1440 if (TProof::GetParameter(fProof->GetInputList(),
"PROOF_ProcessNotAssigned", oldnotass) != 0) oldnotass = -1;
1441 fProof->SetParameter(
"PROOF_ProcessNotAssigned", (Int_t)0);
1444 Long64_t ne = (nevt > 0) ? nevt : 30000;
1445 fProof->SetParameter(
"PROOF_BenchmarkNEvents", ne);
1446 fProof->SetParameter(
"PROOF_BenchmarkRegenerate", Int_t(regenerate));
1447 fProof->Process(fDataGenSel, (Long64_t) 1);
1448 fProof->DeleteParameters(
"PROOF_BenchmarkNEvents");
1449 fProof->DeleteParameters(
"PROOF_BenchmarkRegenerate");
1450 fProof->DeleteParameters(
"PROOF_BenchmarkBaseDir");
1453 if (!oldpack.IsNull())
1454 fProof->SetParameter(
"PROOF_Packetizer", oldpack);
1456 fProof->DeleteParameters(
"PROOF_Packetizer");
1457 if (oldnotass != -1)
1458 fProof->SetParameter(
"PROOF_ProcessNotAssigned", oldnotass);
1460 fProof->DeleteParameters(
"PROOF_ProcessNotAssigned");
1463 if (fProof->GetInputList()) fProof->GetInputList()->Remove(filesmap);
1464 filesmap->SetOwner(kTRUE);
1468 TFileCollection *fc =
new TFileCollection(
"dum",
"dum");
1470 if (fProof->GetOutputList()) {
1471 fProof->GetOutputList()->Print();
1472 TIter nxout(fProof->GetOutputList());
1473 while ((obj = nxout())) {
1474 TList *fli =
dynamic_cast<TList *
>(obj);
1475 if (fli && TString(fli->GetName()).BeginsWith(
"PROOF_FilesGenerated_")) {
1478 while ((fi = (TFileInfo *) nxfg()))
1480 fli->SetOwner(kFALSE);
1486 if (fc->GetNFiles() > 0) {
1487 if (remote) fc->SetBit(TFileCollection::kRemoteCollection);
1488 if (!(fProof->RegisterDataSet(fDataSet, fc,
"OT")))
1489 Warning(
"MakeDataSet",
"problems registering '%s'", dset);
1491 Warning(
"MakeDataSet",
"dataset '%s' is empty!", dset);
1494 Warning(
"MakeDataSet",
"PROOF output list is empty!");
1500 fc = fProof->GetDataSet(fDataSet);
1504 Warning(
"MakeDataSet",
"dataset '%s' was not generated!", fDataSet.Data());
1518 Int_t TProofBench::CopyDataSet(
const char *dset,
const char *dsetdst,
const char *destdir)
1522 Error(
"CopyDataSet",
"no PROOF found - cannot continue");
1525 if (!dset || (dset && !fProof->ExistsDataSet(dset))) {
1526 Error(
"CopyDataSet",
"dataset '%s' does not exist", dset);
1529 if (!dsetdst || (dsetdst && fProof->ExistsDataSet(dsetdst))) {
1530 if (isatty(0) != 0 && isatty(1) != 0) {
1531 Printf(
"Target dataset '%s' exists already:"
1532 " do you want to remove it first?", dsetdst);
1533 const char *a = Getline(
"[Y,n] ");
1535 if (a[0] ==
'Y' || a[0] ==
'y' || a[0] ==
'\n') {
1536 Info(
"CopyDataSet",
"removing dataset '%s' ...", dsetdst);
1537 RemoveDataSet(dsetdst);
1542 Error(
"CopyDataSet",
"destination dataset '%s' does already exist: remove it first", dsetdst);
1548 TFileCollection *fc = fProof->GetDataSet(dset);
1550 Error(
"CopyDataSet",
"problems retrieving TFileCollection for dataset '%s'", dset);
1553 TFileCollection *fcn =
new TFileCollection(dsetdst,
"");
1556 TIter nxfi(fc->GetList());
1557 while ((fi = (TFileInfo *) nxfi())) {
1558 fn.Form(
"%s/%s", destdir, gSystem->BaseName(fi->GetCurrentUrl()->GetFile()));
1559 Info(
"CopyDataSet",
"adding info for file '%s'", fn.Data());
1560 fcn->Add(
new TFileInfo(fn));
1565 if (!fDS) fDS =
new TProofBenchDataSet(fProofDS);
1566 if (fDS->CopyFiles(dset, destdir) != 0) {
1567 Error(
"CopyDataSet",
"problems copying files of dataset '%s' to dest dir '%s'", dset, destdir);
1575 if (!(fProof->RegisterDataSet(dsetdst, fcn,
"OT"))) {
1576 Error(
"CopyDataSet",
"problems registering and verifying '%s'", dsetdst);
1590 void TProofBench::SetProofDS(TProof *pds)
1592 if (pds && !pds->IsValid()) {
1593 Error(
"SetProofDS",
"trying to set an invalid PROOF instance");
1596 fProofDS = pds ? pds : fProof;
1599 fDS =
new TProofBenchDataSet(fProofDS);