3 // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
10 #include <TGraphAsymmErrors.h>
12 #include <TStopwatch.h>
16 #include "AliL3Logging.h"
17 #include "AliL3Benchmark.h"
19 /** \class AliL3Benchmark
21 //_____________________________________________________________
25 // Benchmark class for level3 code
31 ClassImp(AliL3Benchmark)
32 AliL3Benchmark::AliL3Benchmark()
47 AliL3Benchmark::~AliL3Benchmark()
50 if (fNames) {delete [] fNames; fNames = 0;}
51 if (fTimer) {delete [] fTimer; fTimer = 0;}
52 if (fSum) {delete [] fSum; fSum = 0;}
53 if (fMin) {delete [] fMin; fMin = 0;}
54 if (fMax) {delete [] fMax; fMax = 0;}
55 if (fCount) {delete [] fCount; fCount =0;}
56 //if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
59 Int_t AliL3Benchmark::GetBench(const char *name)
61 for (Int_t i=0;i<fNbench;i++) {
62 if (!strcmp(name,(const char*)fNames[i])) return i;
68 void AliL3Benchmark::Start(const char *name)
72 fNames=new Char_t*[fNmax];
73 fTimer = new AliL3Stopwatch[fNmax];
75 fNames = new TString[fNmax];
76 fTimer = new TStopwatch[fNmax];
79 fSum = new Float_t[fNmax];
80 fMin = new Float_t[fNmax];
81 fMax = new Float_t[fNmax];
82 fCount = new Int_t[fNmax];
83 for(Int_t i =0;i<fNmax;i++){
90 Int_t bench = GetBench(name);
91 if (bench < 0 && fNbench < fNmax ) {
92 // define a new benchmark to Start
94 fNames[fNbench]=new Char_t[strlen(name)+1];
95 strcpy(fNames[fNbench],name);
97 fNames[fNbench] = name;
101 fTimer[bench].Reset();
102 fTimer[bench].Start();
103 //if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
104 //fStopwatch = new TStopwatch();
105 //fStopwatch->Reset();
106 //fStopwatch->Start();
107 } else if (bench >=0) {
108 // Resume the existent benchmark
109 fTimer[bench].Reset();
110 fTimer[bench].Start();
111 //if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
112 //fStopwatch = new TStopwatch();
113 //fStopwatch->Reset();
114 //fStopwatch->Start();
117 LOG(AliL3Log::kWarning,"AliL3Benchmark::Start","Start")
118 <<"too many benches"<<ENDLOG;
121 void AliL3Benchmark::Stop(const char *name)
123 Int_t bench = GetBench(name);
124 if (bench < 0) return;
126 fTimer[bench].Stop();
127 Float_t val = fTimer[bench].CpuTime();
128 //fStopwatch->Stop();
129 //Float_t val = fStopwatch->CpuTime();
133 if(fCount[bench]==1){
138 if(val<fMin[bench])fMin[bench]=val;
139 if(val>fMax[bench])fMax[bench]=val;
143 void AliL3Benchmark::Analyze(const Char_t* name){
144 Float_t *x = new Float_t[fNbench];
145 Float_t *y = new Float_t[fNbench];
146 Float_t *eyl = new Float_t[fNbench];
147 Float_t *eyh = new Float_t[fNbench];
149 sprintf(filename,"%s.dat",name);
150 FILE *f= fopen(filename,"w");
151 for (Int_t i=0;i<fNbench;i++) {
153 if(fCount[i]) av = fSum[i]/fCount[i];
156 eyl[i]=(av-fMin[i])*1000;
157 eyh[i]=(fMax[i]-av)*1000;
159 fprintf(f,"%2d. %s: ",i+1,fNames[i]);
161 fprintf(f,"%2d. %s: ",i+1,fNames[i].Data());
163 fprintf(f,"total %4.0f patch %4.0f -%4.0f +%4.0f ms\n",fSum[i],av*1000,eyl[i],eyh[i]);
166 sprintf(filename,"%s.tmp",name);
167 /* only a workaround!!
168 FILE *f2= fopen(filename,"w");
169 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",x[i]); fprintf(f2,"\n");
170 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",y[i]); fprintf(f2,"\n");
171 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyl[i]); fprintf(f2,"\n");
172 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyh[i]); fprintf(f2,"\n");
176 sprintf(filename,"%s.root",name);
177 TFile *file = new TFile(filename,"RECREATE");
178 TGraphAsymmErrors *gr = new TGraphAsymmErrors(fNbench,x,y,0,0,eyl,eyh);
179 gr->SetTitle("benchmark");
180 gr->SetMarkerStyle(8);
194 Double_t AliL3Benchmark::GetCpuTime()
196 {return (Double_t)(clock()) / CLOCKS_PER_SEC;}