Profiler.cpp
Go to the documentation of this file.
1 
2 
4 #include <stdio.h>
5 
6 
7 namespace ARToolKitPlus {
8 
9 
10 #ifdef _USE_PROFILING_
11 
12 #pragma message(">>> Building ARToolKitPlus with PROFILING ENABLED")
13 
14 int mulCount = 0;
15 int divCount = 0;
16 int sqrtCount = 0;
17 int invSqrtCount = 0;
18 int trigCount = 0;
19 
20 #endif
21 
22 void
24 {
26  _LABELING.reset();
36  _GETROT.reset();
37  _GETANGLE.reset();
38 }
39 
40 
42 Profiler::getMes(MES nMes) const
43 {
44  switch(nMes)
45  {
47  return &_SINGLEMARKER_OVERALL;
48  case LABELING:
49  return &_LABELING;
50  case DETECTMARKER2:
51  return &_DETECTMARKER2;
52  case GETMARKERINFO:
53  return &_GETMARKERINFO;
54  case GETTRANSMAT:
55  return &_GETTRANSMAT;
56  case GETINITROT:
57  return &_GETINITROT;
58  case GETTRANSMAT3:
59  return &_GETTRANSMAT3;
60  case GETTRANSMATSUB:
61  return &_GETTRANSMATSUB;
62  case MODIFYMATRIX_LOOP:
63  return &_MODIFYMATRIX_LOOP;
64  case MODIFYMATRIX:
65  return &_MODIFYMATRIX;
66  case GETNEWMATRIX:
67  return &_GETNEWMATRIX;
68  case GETROT:
69  return &_GETROT;
70  case GETANGLE:
71  return &_GETANGLE;
72  }
73 
74  return NULL;
75 }
76 
77 
78 #ifdef _ARTKP_IS_WINDOWS_
79 
80 
81 void
83 {
84  sum.QuadPart = 0;
85 }
86 
87 
88 void
90 {
91  QueryPerformanceCounter(&nM.secBegin);
92 }
93 
94 
95 void
97 {
98  QueryPerformanceCounter(&nM.secEnd);
99  nM.sum.QuadPart += nM.secEnd.QuadPart - nM.secBegin.QuadPart;
100 }
101 
102 
103 float
104 Profiler::getFraction(const Measurement& nNom, const Measurement& nDenom) const
105 {
106  long double nom = (long double)nNom.sum.QuadPart,
107  denom = (long double)nDenom.sum.QuadPart;
108 
109  long double fract = nom/denom;
110  return (float)fract;
111 }
112 
113 
114 float
115 Profiler::getFraction(MES nNom, MES nDenom) const
116 {
117  const Measurement* nom = getMes(nNom);
118  const Measurement* denom = getMes(nDenom);
119 
120  if(!nom || !denom)
121  return 0.0f;
122 
123  return getFraction(*nom, *denom);
124 }
125 
126 
127 float
128 Profiler::getTime(MES nMes) const
129 {
130  const Measurement* mes = getMes(nMes);
131  LARGE_INTEGER freq;
132 
133  if(!mes)
134  return 0.0f;
135 
136  QueryPerformanceFrequency(&freq);
137 
138  long double ld_sum = (long double)mes->sum.QuadPart,
139  ld_freq = (long double)freq.QuadPart;
140 
141  long double dt = ld_sum/ld_freq;
142  return (float)dt;
143 }
144 
145 
146 #else // _ARTKP_IS_WINDOWS_
147 
148 
149 // supply only stub methods for non-windows systems
150 //
151 void
153 {
154 }
155 
156 
157 void
159 {
160 }
161 
162 
163 void
165 {
166 }
167 
168 
169 float
170 Profiler::getFraction(MES /*nNom*/, MES /*nDenom*/) const
171 {
172  return 0.0f;
173 }
174 
175 
176 float
177 Profiler::getTime(MES /*nMes*/) const
178 {
179  return 0.0f;
180 }
181 
182 
183 #endif //_ARTKP_IS_WINDOWS_
184 
185 
186 
187 void
188 Profiler::writeReport(const char* nFileName, unsigned int nNumRuns) const
189 {
190  FILE* fp = fopen(nFileName, "w");
191  if(!fp)
192  return;
193 
194 #ifdef _USE_PROFILING_
195 # ifdef _ARTKP_IS_WINDOWS_
196  float overall = getTime(SINGLEMARKER_OVERALL);
197 
198  if(overall==0.0f) // prevent division by 0
199  overall = 1.0f; // on non-windows systems
200 
201  fprintf(fp, "PROFILER REPORT (%d runs)\n\n", nNumRuns);
202  fprintf(fp, " SINGLEMARKER_OVERALL: %.3f msecs\n", 1000.0f*overall/nNumRuns);
203  fprintf(fp, " LABELING: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(LABELING)/nNumRuns, 100.0f*getTime(LABELING)/overall);
204  fprintf(fp, " DETECTMARKER2: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(DETECTMARKER2)/nNumRuns, 100.0f*getTime(DETECTMARKER2)/overall);
205  fprintf(fp, " GETMARKERINFO: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(GETMARKERINFO)/nNumRuns, 100.0f*getTime(GETMARKERINFO)/overall);
206  fprintf(fp, " GETTRANSMAT: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(GETTRANSMAT)/nNumRuns, 100.0f*getTime(GETTRANSMAT)/overall);
207  fprintf(fp, " GETINITROT: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(GETINITROT)/nNumRuns, 100.0f*getTime(GETINITROT)/overall);
208  fprintf(fp, " GETTRANSMAT3: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(GETTRANSMAT3)/nNumRuns, 100.0f*getTime(GETTRANSMAT3)/overall);
209  fprintf(fp, " GETTRANSMATSUB: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(GETTRANSMATSUB)/nNumRuns, 100.0f*getTime(GETTRANSMATSUB)/overall);
210  fprintf(fp, " MODIFYMATRIX: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(MODIFYMATRIX)/nNumRuns, 100.0f*getTime(MODIFYMATRIX)/overall);
211  fprintf(fp, " MODIFYMATRIX_LOOP: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(MODIFYMATRIX_LOOP)/nNumRuns, 100.0f*getTime(MODIFYMATRIX_LOOP)/overall);
212  fprintf(fp, " GETNEWMATRIX: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(GETNEWMATRIX)/nNumRuns, 100.0f*getTime(GETNEWMATRIX)/overall);
213  fprintf(fp, " GETROT: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(GETROT)/nNumRuns, 100.0f*getTime(GETROT)/overall);
214 
215  fprintf(fp, "\n GETANGLE: %.3f msecs (%.2f %%)\n", 1000.0f*getTime(GETANGLE)/nNumRuns, 100.0f*getTime(GETANGLE)/overall);
216 # else // _ARTKP_IS_WINDOWS_
217  fprintf(fp, "PROFILER REPORT (%d runs)\n\n", nNumRuns);
218  fprintf(fp, " ERROR: profiling currently only supported under Windows.\n");
219 # endif // _ARTKP_IS_WINDOWS_
220 #else // _USE_PROFILING_
221  fprintf(fp, "PROFILER REPORT (%d runs)\n\n", nNumRuns);
222  fprintf(fp, " ERROR: profiling was disabled at compiletime.\n");
223 #endif // _USE_PROFILING_
224 
225  fclose(fp);
226 }
227 
228 
229 bool
231 {
232 #ifdef _USE_PROFILING_
233  return true;
234 #else
235  return false;
236 #endif
237 }
238 
239 
240 
241 } // namespace ARToolKitPlus
Measurement _GETANGLE
Definition: Profiler.h:86
f
Measurement _MODIFYMATRIX
Definition: Profiler.h:86
float getFraction(const Measurement &nNom, const Measurement &nDenom) const
void endSection(Measurement &nM)
Definition: Profiler.cpp:164
Measurement _SINGLEMARKER_OVERALL
Definition: Profiler.h:86
float getTime(MES nMes) const
Definition: Profiler.cpp:177
This file should only be compiled when using ARToolKitPlus as a DLL.
Definition: ar.h:60
Measurement _LABELING
Definition: Profiler.h:86
Measurement _GETNEWMATRIX
Definition: Profiler.h:86
static bool isProfilingEnabled()
Definition: Profiler.cpp:230
Measurement _GETROT
Definition: Profiler.h:86
Measurement _MODIFYMATRIX_LOOP
Definition: Profiler.h:86
void beginSection(Measurement &nM)
Definition: Profiler.cpp:158
Measurement _DETECTMARKER2
Definition: Profiler.h:86
Measurement _GETTRANSMAT
Definition: Profiler.h:86
Measurement _GETTRANSMATSUB
Definition: Profiler.h:86
Measurement _GETTRANSMAT3
Definition: Profiler.h:86
#define NULL
Definition: PocketKnife.h:38
Measurement _GETINITROT
Definition: Profiler.h:86
Measurement _GETMARKERINFO
Definition: Profiler.h:86
void writeReport(const char *nFileName, unsigned int nNumRuns=1) const
Definition: Profiler.cpp:188
const Measurement * getMes(MES nMes) const
Definition: Profiler.cpp:42


tuw_artoolkitplus
Author(s): Markus Bader
autogenerated on Sun Sep 4 2016 03:24:33