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