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()
53 if (fNames) {delete [] fNames; fNames = 0;}
54 if (fTimer) {delete [] fTimer; fTimer = 0;}
55 if (fSum) {delete [] fSum; fSum = 0;}
56 if (fMin) {delete [] fMin; fMin = 0;}
57 if (fMax) {delete [] fMax; fMax = 0;}
58 if (fCount) {delete [] fCount; fCount =0;}
61 Int_t AliHLTTPCBenchmark::GetBench(const Char_t *name)
64 for (Int_t i=0;i<fNbench;i++) {
65 if (!strcmp(name,(const Char_t*)fNames[i])) return i;
71 void AliHLTTPCBenchmark::Start(const Char_t *name)
73 //start the benchmark with name
76 fNames=new Char_t*[fNmax];
77 fTimer = new AliHLTTPCStopwatch[fNmax];
79 fNames = new TString[fNmax];
80 fTimer = new TStopwatch[fNmax];
83 fSum = new Float_t[fNmax];
84 fMin = new Float_t[fNmax];
85 fMax = new Float_t[fNmax];
86 fCount = new Int_t[fNmax];
87 for(Int_t i =0;i<fNmax;i++){
94 Int_t bench = GetBench(name);
95 if (bench < 0 && fNbench < fNmax ) {
96 // define a new benchmark to Start
98 fNames[fNbench]=new Char_t[strlen(name)+1];
99 strcpy(fNames[fNbench],name);
101 fNames[fNbench] = name;
105 fTimer[bench].Reset();
106 fTimer[bench].Start();
107 } else if (bench >=0) {
108 // Resume the existent benchmark
109 fTimer[bench].Reset();
110 fTimer[bench].Start();
113 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCBenchmark::Start","Start")
114 <<"too many benches"<<ENDLOG;
117 void AliHLTTPCBenchmark::Stop(const char *name)
119 //stop the benchmark with name
120 Int_t bench = GetBench(name);
121 if (bench < 0) return;
123 fTimer[bench].Stop();
124 Float_t val = fTimer[bench].CpuTime();
128 if(fCount[bench]==1){
133 if(val<fMin[bench])fMin[bench]=val;
134 if(val>fMax[bench])fMax[bench]=val;
138 void AliHLTTPCBenchmark::Analyze(const Char_t* name)
140 //get results of benchmark
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];
145 Char_t filename[256];
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,"total %4.0f patch %4.0f -%4.0f +%4.0f ms\n",fSum[i],av*1000,eyl[i],eyh[i]);
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 AliHLTTPCBenchmark::GetCpuTime()
194 {return (Double_t)(clock()) / CLOCKS_PER_SEC;}