2 #include "TGraphAsymmErrors.h"
4 #include "TStopwatch.h"
5 #include "AliL3Benchmark.h"
6 #include "TStopwatch.h"
8 #include "AliL3Logging.h"
10 ClassImp(AliL3Benchmark)
12 AliL3Benchmark::AliL3Benchmark()
25 AliL3Benchmark::~AliL3Benchmark()
28 if (fNames) {delete [] fNames; fNames = 0;}
29 if (fTimer) {delete [] fTimer; fTimer = 0;}
30 if (fSum) {delete [] fSum; fSum = 0;}
31 if (fMin) {delete [] fMin; fMin = 0;}
32 if (fMax) {delete [] fMax; fMax = 0;}
33 if (fCount) {delete [] fCount; fCount =0;}
34 // if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
37 Int_t AliL3Benchmark::GetBench(const char *name)
39 for (Int_t i=0;i<fNbench;i++) {
40 if (!strcmp(name,(const char*)fNames[i])) return i;
46 void AliL3Benchmark::Start(const char *name)
49 fNames = new TString[fNmax];
50 fTimer = new TStopwatch[fNmax];
51 fSum = new Float_t[fNmax];
52 fMin = new Float_t[fNmax];
53 fMax = new Float_t[fNmax];
54 fCount = new Int_t[fNmax];
55 for(Int_t i =0;i<fNmax;i++){
62 Int_t bench = GetBench(name);
63 if (bench < 0 && fNbench < fNmax ) {
64 // define a new benchmark to Start
65 fNames[fNbench] = name;
68 fTimer[bench].Reset();
69 fTimer[bench].Start();
70 // if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
71 // fStopwatch = new TStopwatch();
72 // fStopwatch->Reset();
73 // fStopwatch->Start();
74 } else if (bench >=0) {
75 // Resume the existen benchmark
76 fTimer[bench].Reset();
77 fTimer[bench].Start();
78 // if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
79 // fStopwatch = new TStopwatch();
80 // fStopwatch->Reset();
81 // fStopwatch->Start();
84 LOG(AliL3Log::kWarning,"AliL3Benchmark::Start","Start")
85 <<"too many benches"<<ENDLOG;
88 void AliL3Benchmark::Stop(const char *name)
90 Int_t bench = GetBench(name);
91 if (bench < 0) return;
94 Float_t val = fTimer[bench].CpuTime();
95 // fStopwatch->Stop();
96 // Float_t val = fStopwatch->CpuTime();
100 if(fCount[bench]==1){
105 if(val<fMin[bench])fMin[bench]=val;
106 if(val>fMax[bench])fMax[bench]=val;
110 void AliL3Benchmark::Analyze(const char* name){
111 Float_t *x = new Float_t[fNbench];
112 Float_t *y = new Float_t[fNbench];
113 Float_t *eyl = new Float_t[fNbench];
114 Float_t *eyh = new Float_t[fNbench];
116 sprintf(filename,"%s.dat",name);
117 FILE *f= fopen(filename,"w");
118 for (Int_t i=0;i<fNbench;i++) {
120 if(fCount[i]) av = fSum[i]/fCount[i];
123 eyl[i]=(av-fMin[i])*1000;
124 eyh[i]=(fMax[i]-av)*1000;
125 fprintf(f,"%2d. %s: ",i+1,fNames[i].Data());
126 fprintf(f,"%4.0f ms\n",av*1000);
129 sprintf(filename,"%s.tmp",name);
130 /* only a workaround!!
131 FILE *f2= fopen(filename,"w");
132 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",x[i]); fprintf(f2,"\n");
133 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",y[i]); fprintf(f2,"\n");
134 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyl[i]); fprintf(f2,"\n");
135 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyh[i]); fprintf(f2,"\n");
138 sprintf(filename,"%s.root",name);
139 TFile *file = new TFile(filename,"RECREATE");
140 TGraphAsymmErrors *gr = new TGraphAsymmErrors(fNbench,x,y,0,0,eyl,eyh);
141 gr->SetTitle("benchmark");
142 gr->SetMarkerStyle(8);