]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCBenchmark.cxx
- made package indepentend of src
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCBenchmark.cxx
CommitLineData
a6c02c85 1// @(#) $Id$
2
3// Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
4//*-- Copyright &copy ALICE HLT Group
5
6/** \class AliHLTTPCBenchmark
7</pre>
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
30using namespace std;
31#endif
32
33ClassImp(AliHLTTPCBenchmark)
34
35AliHLTTPCBenchmark::AliHLTTPCBenchmark()
36{
37 //Constructor
38 fNbench = 0;
39 fNmax = 20;
40 fNames = 0;
41 fTimer = 0;
42 fSum = 0;
43 fMin = 0;
44 fMax = 0;
45 fCount = 0;
46}
47
48AliHLTTPCBenchmark::~AliHLTTPCBenchmark()
49{
50 //deconstructor
51 fNbench = 0;
52 if (fNames) {delete [] fNames; fNames = 0;}
53 if (fTimer) {delete [] fTimer; fTimer = 0;}
54 if (fSum) {delete [] fSum; fSum = 0;}
55 if (fMin) {delete [] fMin; fMin = 0;}
56 if (fMax) {delete [] fMax; fMax = 0;}
57 if (fCount) {delete [] fCount; fCount =0;}
58}
59
60Int_t AliHLTTPCBenchmark::GetBench(const Char_t *name)
61{
62 //get bench with name
63 for (Int_t i=0;i<fNbench;i++) {
64 if (!strcmp(name,(const Char_t*)fNames[i])) return i;
65 }
66 return -1;
67}
68
69
70void AliHLTTPCBenchmark::Start(const Char_t *name)
71{
72 //start the benchmark with name
73 if (!fNbench) {
74#ifdef no_root
75 fNames=new Char_t*[fNmax];
76 fTimer = new AliHLTTPCStopwatch[fNmax];
77#else
78 fNames = new TString[fNmax];
79 fTimer = new TStopwatch[fNmax];
80#endif
81
82 fSum = new Float_t[fNmax];
83 fMin = new Float_t[fNmax];
84 fMax = new Float_t[fNmax];
85 fCount = new Int_t[fNmax];
86 for(Int_t i =0;i<fNmax;i++){
87 fSum[i]=0;
88 fMin[i]=0;
89 fMax[i]=0;
90 fCount[i]=0;
91 }
92 }
93 Int_t bench = GetBench(name);
94 if (bench < 0 && fNbench < fNmax ) {
95 // define a new benchmark to Start
96#ifdef no_root
97 fNames[fNbench]=new Char_t[strlen(name)+1];
98 strcpy(fNames[fNbench],name);
99#else
100 fNames[fNbench] = name;
101#endif
102 bench = fNbench;
103 fNbench++;
104 fTimer[bench].Reset();
105 fTimer[bench].Start();
106 } else if (bench >=0) {
107 // Resume the existent benchmark
108 fTimer[bench].Reset();
109 fTimer[bench].Start();
110 }
111 else
112 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCBenchmark::Start","Start")
113 <<"too many benches"<<ENDLOG;
114}
115
116void AliHLTTPCBenchmark::Stop(const char *name)
117{
118 //stop the benchmark with name
119 Int_t bench = GetBench(name);
120 if (bench < 0) return;
121
122 fTimer[bench].Stop();
123 Float_t val = fTimer[bench].CpuTime();
124
125 fSum[bench] += val;
126 fCount[bench]++;
127 if(fCount[bench]==1){
128 fMin[bench] = val;
129 fMax[bench] = val;
130 }
131 else{
132 if(val<fMin[bench])fMin[bench]=val;
133 if(val>fMax[bench])fMax[bench]=val;
134 }
135}
136
137void AliHLTTPCBenchmark::Analyze(const Char_t* name)
138{
139 //get results of benchmark
140 Float_t *x = new Float_t[fNbench];
141 Float_t *y = new Float_t[fNbench];
142 Float_t *eyl = new Float_t[fNbench];
143 Float_t *eyh = new Float_t[fNbench];
144 Char_t filename[256];
145 sprintf(filename,"%s.dat",name);
146 FILE *f= fopen(filename,"w");
147 for (Int_t i=0;i<fNbench;i++) {
148 Float_t av =0;
149 if(fCount[i]) av = fSum[i]/fCount[i];
150 x[i]=i+1;
151 y[i]=av*1000;
152 eyl[i]=(av-fMin[i])*1000;
153 eyh[i]=(fMax[i]-av)*1000;
154#ifdef no_root
155 fprintf(f,"%2d. %s: ",i+1,fNames[i]);
156#else
157 fprintf(f,"%2d. %s: ",i+1,fNames[i].Data());
158#endif
159 fprintf(f,"total %4.0f patch %4.0f -%4.0f +%4.0f ms\n",fSum[i],av*1000,eyl[i],eyh[i]);
160 }
161 fclose(f);
162 sprintf(filename,"%s.tmp",name);
163/* only a workaround!!
164 FILE *f2= fopen(filename,"w");
165 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",x[i]); fprintf(f2,"\n");
166 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",y[i]); fprintf(f2,"\n");
167 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyl[i]); fprintf(f2,"\n");
168 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyh[i]); fprintf(f2,"\n");
169 fclose(f2);
170*/
171#ifndef no_root
172 sprintf(filename,"%s.root",name);
173 TFile *file = new TFile(filename,"RECREATE");
174 TGraphAsymmErrors *gr = new TGraphAsymmErrors(fNbench,x,y,0,0,eyl,eyh);
175 gr->SetTitle("benchmark");
176 gr->SetMarkerStyle(8);
177 gr->SetMinimum(0);
178 //gr->Draw("ALP");
179 gr->Write();
180 file->Close();
181 delete file;
182 file=0;
183#endif
184 delete[] x;
185 delete[] y;
186 delete[] eyl;
187 delete[] eyh;
188}
189
190Double_t AliHLTTPCBenchmark::GetCpuTime()
191{
192 //get cpu time
193 {return (Double_t)(clock()) / CLOCKS_PER_SEC;}
194}