]>
Commit | Line | Data |
---|---|---|
a6c02c85 | 1 | // @(#) $Id$ |
2 | ||
3 | // Author: Uli Frankenfeld <mailto:franken@fi.uib.no> | |
4 | //*-- Copyright © ALICE HLT Group | |
5 | ||
6 | /** \class AliHLTTPCBenchmark | |
600e6a1b | 7 | <pre> |
a6c02c85 | 8 | //_____________________________________________________________ |
9 | // | |
10 | // AliHLTTPCBenchmark | |
11 | // | |
12 | // Benchmark class for level3 code | |
13 | // | |
14 | // | |
15 | </pre> | |
16 | */ | |
17 | ||
18 | #ifndef no_root | |
19 | #include <TFile.h> | |
20 | #include <TGraphAsymmErrors.h> | |
21 | #include <TString.h> | |
22 | #include <TStopwatch.h> | |
23 | #include <TMath.h> | |
24 | #endif | |
a6c02c85 | 25 | #include "AliHLTTPCRootTypes.h" |
26 | #include "AliHLTTPCLogging.h" | |
27 | #include "AliHLTTPCBenchmark.h" | |
28 | ||
29 | #if __GNUC__ >= 3 | |
30 | using namespace std; | |
31 | #endif | |
32 | ||
33 | ClassImp(AliHLTTPCBenchmark) | |
34 | ||
35 | AliHLTTPCBenchmark::AliHLTTPCBenchmark() | |
600e6a1b | 36 | : |
37 | fNbench(0), | |
38 | fNmax(20), | |
39 | fNames(NULL), | |
40 | fTimer(NULL), | |
41 | fSum(NULL), | |
42 | fMin(NULL), | |
43 | fMax(NULL), | |
44 | fCount(NULL) | |
a6c02c85 | 45 | { |
46 | //Constructor | |
600e6a1b | 47 | } |
48 | ||
49 | AliHLTTPCBenchmark::AliHLTTPCBenchmark(const AliHLTTPCBenchmark&) | |
50 | : | |
51 | fNbench(0), | |
52 | fNmax(20), | |
53 | fNames(NULL), | |
54 | fTimer(NULL), | |
55 | fSum(NULL), | |
56 | fMin(NULL), | |
57 | fMax(NULL), | |
58 | fCount(NULL) | |
59 | { | |
60 | HLTFatal("copy constructor untested"); | |
61 | } | |
62 | ||
63 | AliHLTTPCBenchmark& AliHLTTPCBenchmark::operator=(const AliHLTTPCBenchmark&) | |
64 | { | |
65 | HLTFatal("assignment operator untested"); | |
66 | return *this; | |
a6c02c85 | 67 | } |
68 | ||
69 | AliHLTTPCBenchmark::~AliHLTTPCBenchmark() | |
70 | { | |
71 | //deconstructor | |
72 | fNbench = 0; | |
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;} | |
79 | } | |
80 | ||
81 | Int_t AliHLTTPCBenchmark::GetBench(const Char_t *name) | |
82 | { | |
83 | //get bench with name | |
84 | for (Int_t i=0;i<fNbench;i++) { | |
85 | if (!strcmp(name,(const Char_t*)fNames[i])) return i; | |
86 | } | |
87 | return -1; | |
88 | } | |
89 | ||
90 | ||
91 | void AliHLTTPCBenchmark::Start(const Char_t *name) | |
92 | { | |
93 | //start the benchmark with name | |
94 | if (!fNbench) { | |
95 | #ifdef no_root | |
96 | fNames=new Char_t*[fNmax]; | |
97 | fTimer = new AliHLTTPCStopwatch[fNmax]; | |
98 | #else | |
99 | fNames = new TString[fNmax]; | |
100 | fTimer = new TStopwatch[fNmax]; | |
101 | #endif | |
102 | ||
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++){ | |
108 | fSum[i]=0; | |
109 | fMin[i]=0; | |
110 | fMax[i]=0; | |
111 | fCount[i]=0; | |
112 | } | |
113 | } | |
114 | Int_t bench = GetBench(name); | |
115 | if (bench < 0 && fNbench < fNmax ) { | |
116 | // define a new benchmark to Start | |
117 | #ifdef no_root | |
118 | fNames[fNbench]=new Char_t[strlen(name)+1]; | |
119 | strcpy(fNames[fNbench],name); | |
120 | #else | |
121 | fNames[fNbench] = name; | |
122 | #endif | |
123 | bench = fNbench; | |
124 | fNbench++; | |
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(); | |
131 | } | |
132 | else | |
133 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCBenchmark::Start","Start") | |
134 | <<"too many benches"<<ENDLOG; | |
135 | } | |
136 | ||
137 | void AliHLTTPCBenchmark::Stop(const char *name) | |
138 | { | |
139 | //stop the benchmark with name | |
140 | Int_t bench = GetBench(name); | |
141 | if (bench < 0) return; | |
142 | ||
143 | fTimer[bench].Stop(); | |
144 | Float_t val = fTimer[bench].CpuTime(); | |
145 | ||
146 | fSum[bench] += val; | |
147 | fCount[bench]++; | |
148 | if(fCount[bench]==1){ | |
149 | fMin[bench] = val; | |
150 | fMax[bench] = val; | |
151 | } | |
152 | else{ | |
153 | if(val<fMin[bench])fMin[bench]=val; | |
154 | if(val>fMax[bench])fMax[bench]=val; | |
155 | } | |
156 | } | |
157 | ||
158 | void AliHLTTPCBenchmark::Analyze(const Char_t* name) | |
159 | { | |
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++) { | |
169 | Float_t av =0; | |
170 | if(fCount[i]) av = fSum[i]/fCount[i]; | |
171 | x[i]=i+1; | |
172 | y[i]=av*1000; | |
173 | eyl[i]=(av-fMin[i])*1000; | |
174 | eyh[i]=(fMax[i]-av)*1000; | |
175 | #ifdef no_root | |
176 | fprintf(f,"%2d. %s: ",i+1,fNames[i]); | |
177 | #else | |
178 | fprintf(f,"%2d. %s: ",i+1,fNames[i].Data()); | |
179 | #endif | |
180 | fprintf(f,"total %4.0f patch %4.0f -%4.0f +%4.0f ms\n",fSum[i],av*1000,eyl[i],eyh[i]); | |
181 | } | |
182 | fclose(f); | |
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"); | |
190 | fclose(f2); | |
191 | */ | |
192 | #ifndef no_root | |
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); | |
198 | gr->SetMinimum(0); | |
199 | //gr->Draw("ALP"); | |
200 | gr->Write(); | |
201 | file->Close(); | |
202 | delete file; | |
203 | file=0; | |
204 | #endif | |
205 | delete[] x; | |
206 | delete[] y; | |
207 | delete[] eyl; | |
208 | delete[] eyh; | |
209 | } | |
210 | ||
211 | Double_t AliHLTTPCBenchmark::GetCpuTime() | |
212 | { | |
213 | //get cpu time | |
214 | {return (Double_t)(clock()) / CLOCKS_PER_SEC;} | |
215 | } |