1 // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
2 //*-- Copyright © Uli
7 #include <TGraphAsymmErrors.h>
9 #include <TStopwatch.h>
13 #include "AliL3Benchmark.h"
14 #include "AliL3Logging.h"
18 // \class AliL3Benchmark
19 //_____________________________________________________________
23 // Benchmark class for level3 code
28 ClassImp(AliL3Benchmark)
29 AliL3Benchmark::AliL3Benchmark()
44 AliL3Benchmark::~AliL3Benchmark()
47 if (fNames) {delete [] fNames; fNames = 0;}
48 if (fTimer) {delete [] fTimer; fTimer = 0;}
49 if (fSum) {delete [] fSum; fSum = 0;}
50 if (fMin) {delete [] fMin; fMin = 0;}
51 if (fMax) {delete [] fMax; fMax = 0;}
52 if (fCount) {delete [] fCount; fCount =0;}
53 //if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
56 Int_t AliL3Benchmark::GetBench(const char *name)
58 for (Int_t i=0;i<fNbench;i++) {
59 if (!strcmp(name,(const char*)fNames[i])) return i;
65 void AliL3Benchmark::Start(const char *name)
69 fNames=new Char_t*[fNmax];
70 fTimer = new AliL3Stopwatch[fNmax];
72 fNames = new TString[fNmax];
73 fTimer = new TStopwatch[fNmax];
76 fSum = new Float_t[fNmax];
77 fMin = new Float_t[fNmax];
78 fMax = new Float_t[fNmax];
79 fCount = new Int_t[fNmax];
80 for(Int_t i =0;i<fNmax;i++){
87 Int_t bench = GetBench(name);
88 if (bench < 0 && fNbench < fNmax ) {
89 // define a new benchmark to Start
91 fNames[fNbench]=new Char_t[strlen(name)+1];
92 strcpy(fNames[fNbench],name);
94 fNames[fNbench] = name;
98 fTimer[bench].Reset();
99 fTimer[bench].Start();
100 //if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
101 //fStopwatch = new TStopwatch();
102 //fStopwatch->Reset();
103 //fStopwatch->Start();
104 } else if (bench >=0) {
105 // Resume the existent benchmark
106 fTimer[bench].Reset();
107 fTimer[bench].Start();
108 //if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
109 //fStopwatch = new TStopwatch();
110 //fStopwatch->Reset();
111 //fStopwatch->Start();
114 LOG(AliL3Log::kWarning,"AliL3Benchmark::Start","Start")
115 <<"too many benches"<<ENDLOG;
118 void AliL3Benchmark::Stop(const char *name)
120 Int_t bench = GetBench(name);
121 if (bench < 0) return;
123 fTimer[bench].Stop();
124 Float_t val = fTimer[bench].CpuTime();
125 //fStopwatch->Stop();
126 //Float_t val = fStopwatch->CpuTime();
130 if(fCount[bench]==1){
135 if(val<fMin[bench])fMin[bench]=val;
136 if(val>fMax[bench])fMax[bench]=val;
140 void AliL3Benchmark::Analyze(const char* name){
141 Float_t *x = new Float_t[fNbench];
142 Float_t *y = new Float_t[fNbench];
143 Float_t *eyl = new Float_t[fNbench];
144 Float_t *eyh = new Float_t[fNbench];
146 sprintf(filename,"%s.dat",name);
147 FILE *f= fopen(filename,"w");
148 for (Int_t i=0;i<fNbench;i++) {
150 if(fCount[i]) av = fSum[i]/fCount[i];
153 eyl[i]=(av-fMin[i])*1000;
154 eyh[i]=(fMax[i]-av)*1000;
156 fprintf(f,"%2d. %s: ",i+1,fNames[i]);
158 fprintf(f,"%2d. %s: ",i+1,fNames[i].Data());
160 fprintf(f,"%4.0f ms\n",av*1000);
163 sprintf(filename,"%s.tmp",name);
164 /* only a workaround!!
165 FILE *f2= fopen(filename,"w");
166 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",x[i]); fprintf(f2,"\n");
167 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",y[i]); fprintf(f2,"\n");
168 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyl[i]); fprintf(f2,"\n");
169 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyh[i]); fprintf(f2,"\n");
173 sprintf(filename,"%s.root",name);
174 TFile *file = new TFile(filename,"RECREATE");
175 TGraphAsymmErrors *gr = new TGraphAsymmErrors(fNbench,x,y,0,0,eyl,eyh);
176 gr->SetTitle("benchmark");
177 gr->SetMarkerStyle(8);
191 Double_t AliL3Benchmark::GetCpuTime()
193 {return (Double_t)(clock()) / CLOCKS_PER_SEC;}