3 // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 /** \class AliHLTTPCBenchmark
8 //_____________________________________________________________
12 // Benchmark class for level3 code
20 #include <TGraphAsymmErrors.h>
22 #include <TStopwatch.h>
25 #include "AliHLTTPCRootTypes.h"
26 #include "AliHLTTPCLogging.h"
27 #include "AliHLTTPCBenchmark.h"
33 ClassImp(AliHLTTPCBenchmark)
35 AliHLTTPCBenchmark::AliHLTTPCBenchmark()
49 AliHLTTPCBenchmark::AliHLTTPCBenchmark(const AliHLTTPCBenchmark&)
60 HLTFatal("copy constructor untested");
63 AliHLTTPCBenchmark& AliHLTTPCBenchmark::operator=(const AliHLTTPCBenchmark&)
65 HLTFatal("assignment operator untested");
69 AliHLTTPCBenchmark::~AliHLTTPCBenchmark()
73 if (fNames) {delete [] fNames; fNames = 0;}
74 if (fTimer) {delete [] fTimer; fTimer = 0;}
75 if (fSum) {delete [] fSum; fSum = 0;}
76 if (fMin) {delete [] fMin; fMin = 0;}
77 if (fMax) {delete [] fMax; fMax = 0;}
78 if (fCount) {delete [] fCount; fCount =0;}
81 Int_t AliHLTTPCBenchmark::GetBench(const Char_t *name)
84 for (Int_t i=0;i<fNbench;i++) {
85 if (!strcmp(name,(const Char_t*)fNames[i])) return i;
91 void AliHLTTPCBenchmark::Start(const Char_t *name)
93 //start the benchmark with name
96 fNames=new Char_t*[fNmax];
97 fTimer = new AliHLTTPCStopwatch[fNmax];
99 fNames = new TString[fNmax];
100 fTimer = new TStopwatch[fNmax];
103 fSum = new Float_t[fNmax];
104 fMin = new Float_t[fNmax];
105 fMax = new Float_t[fNmax];
106 fCount = new Int_t[fNmax];
107 for(Int_t i =0;i<fNmax;i++){
114 Int_t bench = GetBench(name);
115 if (bench < 0 && fNbench < fNmax ) {
116 // define a new benchmark to Start
118 fNames[fNbench]=new Char_t[strlen(name)+1];
119 strcpy(fNames[fNbench],name);
121 fNames[fNbench] = name;
125 fTimer[bench].Reset();
126 fTimer[bench].Start();
127 } else if (bench >=0) {
128 // Resume the existent benchmark
129 fTimer[bench].Reset();
130 fTimer[bench].Start();
133 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCBenchmark::Start","Start")
134 <<"too many benches"<<ENDLOG;
137 void AliHLTTPCBenchmark::Stop(const char *name)
139 //stop the benchmark with name
140 Int_t bench = GetBench(name);
141 if (bench < 0) return;
143 fTimer[bench].Stop();
144 Float_t val = fTimer[bench].CpuTime();
148 if(fCount[bench]==1){
153 if(val<fMin[bench])fMin[bench]=val;
154 if(val>fMax[bench])fMax[bench]=val;
158 void AliHLTTPCBenchmark::Analyze(const Char_t* name)
160 //get results of benchmark
161 Float_t *x = new Float_t[fNbench];
162 Float_t *y = new Float_t[fNbench];
163 Float_t *eyl = new Float_t[fNbench];
164 Float_t *eyh = new Float_t[fNbench];
165 Char_t filename[256];
166 sprintf(filename,"%s.dat",name);
167 FILE *f= fopen(filename,"w");
168 for (Int_t i=0;i<fNbench;i++) {
170 if(fCount[i]) av = fSum[i]/fCount[i];
173 eyl[i]=(av-fMin[i])*1000;
174 eyh[i]=(fMax[i]-av)*1000;
176 fprintf(f,"%2d. %s: ",i+1,fNames[i]);
178 fprintf(f,"%2d. %s: ",i+1,fNames[i].Data());
180 fprintf(f,"total %4.0f patch %4.0f -%4.0f +%4.0f ms\n",fSum[i],av*1000,eyl[i],eyh[i]);
183 sprintf(filename,"%s.tmp",name);
184 /* only a workaround!!
185 FILE *f2= fopen(filename,"w");
186 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",x[i]); fprintf(f2,"\n");
187 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",y[i]); fprintf(f2,"\n");
188 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyl[i]); fprintf(f2,"\n");
189 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyh[i]); fprintf(f2,"\n");
193 sprintf(filename,"%s.root",name);
194 TFile *file = new TFile(filename,"RECREATE");
195 TGraphAsymmErrors *gr = new TGraphAsymmErrors(fNbench,x,y,0,0,eyl,eyh);
196 gr->SetTitle("benchmark");
197 gr->SetMarkerStyle(8);
211 Double_t AliHLTTPCBenchmark::GetCpuTime()
214 {return (Double_t)(clock()) / CLOCKS_PER_SEC;}