]>
Commit | Line | Data |
---|---|---|
b661165c | 1 | // Author: Uli Frankenfeld <mailto:franken@fi.uib.no> |
2 | //*-- Copyright © Uli | |
0c547964 | 3 | |
4 | #include <time.h> | |
108615fc | 5 | #include <TFile.h> |
6 | #include "TGraphAsymmErrors.h" | |
7 | #include "TString.h" | |
8 | #include "TStopwatch.h" | |
9 | #include "AliL3Benchmark.h" | |
10 | #include "TStopwatch.h" | |
11 | #include "TMath.h" | |
12 | #include "AliL3Logging.h" | |
13 | ||
108615fc | 14 | |
b661165c | 15 | //_____________________________________________________________ |
16 | // | |
17 | // Benchmark class for level3 code | |
18 | // | |
19 | // | |
20 | // | |
21 | ||
22 | ClassImp(AliL3Benchmark) | |
108615fc | 23 | AliL3Benchmark::AliL3Benchmark() |
24 | { | |
b661165c | 25 | //Constructor |
26 | ||
27 | fNbench = 0; | |
108615fc | 28 | fNmax = 20; |
29 | fNames = 0; | |
30 | fTimer = 0; | |
31 | fSum = 0; | |
32 | fMin = 0; | |
33 | fMax = 0; | |
34 | fCount = 0; | |
35 | // fStopwatch = 0; | |
36 | } | |
37 | ||
38 | AliL3Benchmark::~AliL3Benchmark() | |
39 | { | |
40 | fNbench = 0; | |
41 | if (fNames) {delete [] fNames; fNames = 0;} | |
42 | if (fTimer) {delete [] fTimer; fTimer = 0;} | |
43 | if (fSum) {delete [] fSum; fSum = 0;} | |
44 | if (fMin) {delete [] fMin; fMin = 0;} | |
45 | if (fMax) {delete [] fMax; fMax = 0;} | |
46 | if (fCount) {delete [] fCount; fCount =0;} | |
47 | // if(fStopwatch) {delete fStopwatch; fStopwatch =0;} | |
48 | } | |
49 | ||
50 | Int_t AliL3Benchmark::GetBench(const char *name) | |
51 | { | |
52 | for (Int_t i=0;i<fNbench;i++) { | |
53 | if (!strcmp(name,(const char*)fNames[i])) return i; | |
54 | } | |
55 | return -1; | |
56 | } | |
57 | ||
58 | ||
59 | void AliL3Benchmark::Start(const char *name) | |
60 | { | |
61 | if (!fNbench) { | |
62 | fNames = new TString[fNmax]; | |
63 | fTimer = new TStopwatch[fNmax]; | |
64 | fSum = new Float_t[fNmax]; | |
65 | fMin = new Float_t[fNmax]; | |
66 | fMax = new Float_t[fNmax]; | |
67 | fCount = new Int_t[fNmax]; | |
68 | for(Int_t i =0;i<fNmax;i++){ | |
69 | fSum[i]=0; | |
70 | fMin[i]=0; | |
71 | fMax[i]=0; | |
72 | fCount[i]=0; | |
73 | } | |
74 | } | |
75 | Int_t bench = GetBench(name); | |
76 | if (bench < 0 && fNbench < fNmax ) { | |
77 | // define a new benchmark to Start | |
78 | fNames[fNbench] = name; | |
79 | bench = fNbench; | |
80 | fNbench++; | |
81 | fTimer[bench].Reset(); | |
82 | fTimer[bench].Start(); | |
83 | // if(fStopwatch) {delete fStopwatch; fStopwatch =0;} | |
84 | // fStopwatch = new TStopwatch(); | |
85 | // fStopwatch->Reset(); | |
86 | // fStopwatch->Start(); | |
87 | } else if (bench >=0) { | |
88 | // Resume the existen benchmark | |
89 | fTimer[bench].Reset(); | |
90 | fTimer[bench].Start(); | |
91 | // if(fStopwatch) {delete fStopwatch; fStopwatch =0;} | |
92 | // fStopwatch = new TStopwatch(); | |
93 | // fStopwatch->Reset(); | |
94 | // fStopwatch->Start(); | |
95 | } | |
96 | else | |
97 | LOG(AliL3Log::kWarning,"AliL3Benchmark::Start","Start") | |
98 | <<"too many benches"<<ENDLOG; | |
99 | } | |
100 | ||
101 | void AliL3Benchmark::Stop(const char *name) | |
102 | { | |
103 | Int_t bench = GetBench(name); | |
104 | if (bench < 0) return; | |
105 | ||
106 | fTimer[bench].Stop(); | |
107 | Float_t val = fTimer[bench].CpuTime(); | |
108 | // fStopwatch->Stop(); | |
109 | // Float_t val = fStopwatch->CpuTime(); | |
110 | ||
111 | fSum[bench] += val; | |
112 | fCount[bench]++; | |
113 | if(fCount[bench]==1){ | |
114 | fMin[bench] = val; | |
115 | fMax[bench] = val; | |
116 | } | |
117 | else{ | |
118 | if(val<fMin[bench])fMin[bench]=val; | |
119 | if(val>fMax[bench])fMax[bench]=val; | |
120 | } | |
121 | } | |
122 | ||
123 | void AliL3Benchmark::Analyze(const char* name){ | |
124 | Float_t *x = new Float_t[fNbench]; | |
125 | Float_t *y = new Float_t[fNbench]; | |
126 | Float_t *eyl = new Float_t[fNbench]; | |
127 | Float_t *eyh = new Float_t[fNbench]; | |
128 | char filename[256]; | |
129 | sprintf(filename,"%s.dat",name); | |
130 | FILE *f= fopen(filename,"w"); | |
131 | for (Int_t i=0;i<fNbench;i++) { | |
132 | Float_t av =0; | |
133 | if(fCount[i]) av = fSum[i]/fCount[i]; | |
134 | x[i]=i+1; | |
135 | y[i]=av*1000; | |
136 | eyl[i]=(av-fMin[i])*1000; | |
137 | eyh[i]=(fMax[i]-av)*1000; | |
138 | fprintf(f,"%2d. %s: ",i+1,fNames[i].Data()); | |
139 | fprintf(f,"%4.0f ms\n",av*1000); | |
140 | } | |
141 | fclose(f); | |
142 | sprintf(filename,"%s.tmp",name); | |
143 | /* only a workaround!! | |
144 | FILE *f2= fopen(filename,"w"); | |
145 | for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",x[i]); fprintf(f2,"\n"); | |
146 | for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",y[i]); fprintf(f2,"\n"); | |
147 | for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyl[i]); fprintf(f2,"\n"); | |
148 | for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyh[i]); fprintf(f2,"\n"); | |
149 | fclose(f2); | |
150 | */ | |
151 | sprintf(filename,"%s.root",name); | |
152 | TFile *file = new TFile(filename,"RECREATE"); | |
153 | TGraphAsymmErrors *gr = new TGraphAsymmErrors(fNbench,x,y,0,0,eyl,eyh); | |
154 | gr->SetTitle("benchmark"); | |
155 | gr->SetMarkerStyle(8); | |
156 | gr->SetMinimum(0); | |
157 | gr->Draw("ALP"); | |
158 | gr->Write(); | |
159 | file->Close(); | |
160 | delete file; | |
161 | file=0; | |
162 | delete[] x; | |
163 | delete[] y; | |
164 | delete[] eyl; | |
165 | delete[] eyh; | |
166 | } | |
167 | ||
0c547964 | 168 | Double_t AliL3Benchmark::GetCpuTime() |
169 | { | |
170 | {return (Double_t)(clock()) / CLOCKS_PER_SEC;} | |
171 | } |