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