Added support for NEWIO, merged cern-hlt tree, updated to latest track candidate...
[u/mrichter/AliRoot.git] / HLT / src / AliL3Benchmark.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
2
b661165c 3// Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
3e87ef69 4//*-- Copyright &copy ALICE HLT Group
0c547964 5
118c26c3 6#include "AliL3StandardIncludes.h"
7
73d9267f 8#ifndef no_root
108615fc 9#include <TFile.h>
73d9267f 10#include <TGraphAsymmErrors.h>
11#include <TString.h>
12#include <TStopwatch.h>
13#include <TMath.h>
14#endif
15
108615fc 16#include "AliL3Logging.h"
118c26c3 17#include "AliL3Benchmark.h"
108615fc 18
3e87ef69 19/** \class AliL3Benchmark
20</pre>
b661165c 21//_____________________________________________________________
22//
73d9267f 23// AliL3Benchmark
24//
b661165c 25// Benchmark class for level3 code
26//
3e87ef69 27//
28</pre>
73d9267f 29*/
b661165c 30
31ClassImp(AliL3Benchmark)
108615fc 32AliL3Benchmark::AliL3Benchmark()
33{
b661165c 34 //Constructor
35
36 fNbench = 0;
73d9267f 37 fNmax = 20;
38 fNames = 0;
39 fTimer = 0;
40 fSum = 0;
41 fMin = 0;
42 fMax = 0;
43 fCount = 0;
44 //fStopwatch = 0;
108615fc 45}
46
47AliL3Benchmark::~AliL3Benchmark()
48{
49 fNbench = 0;
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;}
73d9267f 56 //if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
108615fc 57}
58
59Int_t AliL3Benchmark::GetBench(const char *name)
60{
61 for (Int_t i=0;i<fNbench;i++) {
62 if (!strcmp(name,(const char*)fNames[i])) return i;
63 }
64 return -1;
65}
66
67
68void AliL3Benchmark::Start(const char *name)
69{
70 if (!fNbench) {
73d9267f 71#ifdef no_root
72 fNames=new Char_t*[fNmax];
73 fTimer = new AliL3Stopwatch[fNmax];
74#else
75 fNames = new TString[fNmax];
76 fTimer = new TStopwatch[fNmax];
77#endif
78
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++){
84 fSum[i]=0;
85 fMin[i]=0;
86 fMax[i]=0;
87 fCount[i]=0;
88 }
108615fc 89 }
90 Int_t bench = GetBench(name);
91 if (bench < 0 && fNbench < fNmax ) {
73d9267f 92 // define a new benchmark to Start
93#ifdef no_root
94 fNames[fNbench]=new Char_t[strlen(name)+1];
95 strcpy(fNames[fNbench],name);
96#else
108615fc 97 fNames[fNbench] = name;
73d9267f 98#endif
108615fc 99 bench = fNbench;
100 fNbench++;
101 fTimer[bench].Reset();
102 fTimer[bench].Start();
73d9267f 103 //if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
104 //fStopwatch = new TStopwatch();
105 //fStopwatch->Reset();
106 //fStopwatch->Start();
108615fc 107 } else if (bench >=0) {
73d9267f 108 // Resume the existent benchmark
108615fc 109 fTimer[bench].Reset();
110 fTimer[bench].Start();
73d9267f 111 //if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
112 //fStopwatch = new TStopwatch();
113 //fStopwatch->Reset();
114 //fStopwatch->Start();
108615fc 115 }
116 else
117 LOG(AliL3Log::kWarning,"AliL3Benchmark::Start","Start")
118 <<"too many benches"<<ENDLOG;
119}
120
121void AliL3Benchmark::Stop(const char *name)
122{
123 Int_t bench = GetBench(name);
124 if (bench < 0) return;
125
126 fTimer[bench].Stop();
127 Float_t val = fTimer[bench].CpuTime();
73d9267f 128 //fStopwatch->Stop();
129 //Float_t val = fStopwatch->CpuTime();
108615fc 130
131 fSum[bench] += val;
132 fCount[bench]++;
133 if(fCount[bench]==1){
134 fMin[bench] = val;
135 fMax[bench] = val;
136 }
137 else{
138 if(val<fMin[bench])fMin[bench]=val;
139 if(val>fMax[bench])fMax[bench]=val;
140 }
141}
142
b2a02bce 143void AliL3Benchmark::Analyze(const Char_t* name){
108615fc 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];
148 char filename[256];
149 sprintf(filename,"%s.dat",name);
150 FILE *f= fopen(filename,"w");
151 for (Int_t i=0;i<fNbench;i++) {
152 Float_t av =0;
153 if(fCount[i]) av = fSum[i]/fCount[i];
154 x[i]=i+1;
155 y[i]=av*1000;
156 eyl[i]=(av-fMin[i])*1000;
157 eyh[i]=(fMax[i]-av)*1000;
73d9267f 158#ifdef no_root
159 fprintf(f,"%2d. %s: ",i+1,fNames[i]);
160#else
108615fc 161 fprintf(f,"%2d. %s: ",i+1,fNames[i].Data());
73d9267f 162#endif
b2a02bce 163 fprintf(f,"total %4.0f patch %4.0f -%4.0f +%4.0f ms\n",fSum[i],av*1000,eyl[i],eyh[i]);
108615fc 164 }
165 fclose(f);
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");
173 fclose(f2);
174*/
73d9267f 175#ifndef no_root
108615fc 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);
181 gr->SetMinimum(0);
3e87ef69 182 //gr->Draw("ALP");
108615fc 183 gr->Write();
184 file->Close();
185 delete file;
186 file=0;
73d9267f 187#endif
108615fc 188 delete[] x;
189 delete[] y;
190 delete[] eyl;
191 delete[] eyh;
192}
193
0c547964 194Double_t AliL3Benchmark::GetCpuTime()
195{
196 {return (Double_t)(clock()) / CLOCKS_PER_SEC;}
197}