1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,574 @@ |
1 |
+// ========================================================================== |
|
2 |
+// SeqAn - The Library for Sequence Analysis |
|
3 |
+// ========================================================================== |
|
4 |
+// Copyright (c) 2006-2018, Knut Reinert, FU Berlin |
|
5 |
+// All rights reserved. |
|
6 |
+// |
|
7 |
+// Redistribution and use in source and binary forms, with or without |
|
8 |
+// modification, are permitted provided that the following conditions are met: |
|
9 |
+// |
|
10 |
+// * Redistributions of source code must retain the above copyright |
|
11 |
+// notice, this list of conditions and the following disclaimer. |
|
12 |
+// * Redistributions in binary form must reproduce the above copyright |
|
13 |
+// notice, this list of conditions and the following disclaimer in the |
|
14 |
+// documentation and/or other materials provided with the distribution. |
|
15 |
+// * Neither the name of Knut Reinert or the FU Berlin nor the names of |
|
16 |
+// its contributors may be used to endorse or promote products derived |
|
17 |
+// from this software without specific prior written permission. |
|
18 |
+// |
|
19 |
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
20 |
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
21 |
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
22 |
+// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE |
|
23 |
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
24 |
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
25 |
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
26 |
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
27 |
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
28 |
+// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
|
29 |
+// DAMAGE. |
|
30 |
+// |
|
31 |
+// ========================================================================== |
|
32 |
+// Author: David Weese <david.weese@fu-berlin.de> |
|
33 |
+// ========================================================================== |
|
34 |
+// Code for profiling. |
|
35 |
+// ========================================================================== |
|
36 |
+ |
|
37 |
+// TODO(holtgrew): This could use some cleanup. |
|
38 |
+ |
|
39 |
+#include <ctime> |
|
40 |
+#include <chrono> |
|
41 |
+ |
|
42 |
+//SEQAN_NO_GENERATED_FORWARDS: no forwards are generated for this file |
|
43 |
+ |
|
44 |
+#ifndef SEQAN_INCLUDE_SEQAN_BASIC_PROFILING_H_ |
|
45 |
+#define SEQAN_INCLUDE_SEQAN_BASIC_PROFILING_H_ |
|
46 |
+ |
|
47 |
+namespace seqan |
|
48 |
+{ |
|
49 |
+ |
|
50 |
+// todo: substitute defines with inlines |
|
51 |
+#ifndef SEQAN_PROFILE |
|
52 |
+ |
|
53 |
+ #define SEQAN_PROSET(i,v) do {} while (false) |
|
54 |
+ #define SEQAN_PROADD(i,v) do {} while (false) |
|
55 |
+ #define SEQAN_PROSUB(i,v) do {} while (false) |
|
56 |
+ #define SEQAN_PROVAL(i) 0 |
|
57 |
+ #define SEQAN_PROEXTRAS(i) do {} while (false) |
|
58 |
+ #define SEQAN_PROMARK(m) do {} while (false) |
|
59 |
+ #define SEQAN_PROENDMARK(m) do {} while (false) |
|
60 |
+ #define SEQAN_PRORESET do {} while (false) |
|
61 |
+ #define SEQAN_PROGETTIME 0 |
|
62 |
+ #define SEQAN_PROTIMESTART(a) do {} while (false) |
|
63 |
+ #define SEQAN_PROTIMEDIFF(a) 0 |
|
64 |
+ #define SEQAN_PROTIMEUPDATE(a) 0 |
|
65 |
+ // replace malloc and free in external tools |
|
66 |
+ // with SEQAN_PROMALLOC and SEQAN_PROFREE to profile |
|
67 |
+ // their memory usage |
|
68 |
+ #define SEQAN_PROMALLOC(s) malloc(s) |
|
69 |
+ #define SEQAN_PROFREE(p) free(p) |
|
70 |
+ |
|
71 |
+#else |
|
72 |
+ |
|
73 |
+ #define SEQAN_PROSET(i,v) _profileSet(i,v) |
|
74 |
+ #define SEQAN_PROADD(i,v) _profileAdd(i,v) |
|
75 |
+ #define SEQAN_PROSUB(i,v) _profileSub(i,v) |
|
76 |
+ #define SEQAN_PROVAL(i) (ProfileData_<>::_proValue[i]) |
|
77 |
+ #define SEQAN_PROEXTRAS(i) {ProfileData_<>::_proExtraCount = i;} |
|
78 |
+ #define SEQAN_PROMARK(m) _profileMark(m) |
|
79 |
+ #define SEQAN_PROENDMARK(m) _profileEndMark(m) |
|
80 |
+ #define SEQAN_PRORESET _profileReset() |
|
81 |
+ #define SEQAN_PROGETTIME sysTime() |
|
82 |
+ #define SEQAN_PROTIMESTART(a) _proFloat a = sysTime() |
|
83 |
+ #define SEQAN_PROTIMEDIFF(a) (sysTime() - a) |
|
84 |
+ #define SEQAN_PROTIMEUPDATE(a) (_profileUpdate(a)) |
|
85 |
+ #define SEQAN_PROMALLOC(s) _profileMalloc(s) |
|
86 |
+ #define SEQAN_PROFREE(p) _profileFree(p) |
|
87 |
+ |
|
88 |
+#endif |
|
89 |
+ |
|
90 |
+#ifdef STDLIB_VS |
|
91 |
+ typedef int64_t ProfileInt_; //IOREV _notio_ |
|
92 |
+#else |
|
93 |
+ typedef int64_t ProfileInt_; //IOREV _notio_ |
|
94 |
+#endif |
|
95 |
+ |
|
96 |
+ typedef double _proFloat; |
|
97 |
+ |
|
98 |
+ |
|
99 |
+ typedef _proFloat ProfileTimeValue_; //IOREV _notio_ |
|
100 |
+ |
|
101 |
+ enum ProfileConstants_ { |
|
102 |
+ SEQAN_PROPAGESIZE = 4096, // B in byte |
|
103 |
+ SEQAN_PROFLOAT = 0, |
|
104 |
+ SEQAN_PROINT = 1, |
|
105 |
+ SEQAN_PROTIME = 2, |
|
106 |
+ SEQAN_PROTYPEMASK = 3, |
|
107 |
+ SEQAN_PROSTATE = 4 |
|
108 |
+ }; |
|
109 |
+ |
|
110 |
+ enum ProfileValueIndex_ { |
|
111 |
+ SEQAN_PROSYSTIME = 0, |
|
112 |
+ SEQAN_PROCPUTIME = 1, |
|
113 |
+ SEQAN_PROMEMORY = 2, // current memory usage (state value) |
|
114 |
+ SEQAN_PROIO = 3, // IOs done (measured in Blocks of size B) |
|
115 |
+ SEQAN_PROIORANDOM = 4, // IOs calls done (read/write calls done) |
|
116 |
+ SEQAN_PROIOVOLUME = 5, // current disk usage (state value) |
|
117 |
+ SEQAN_PRODEPTH = 6, // algorithmic rec. depth or loop count |
|
118 |
+ SEQAN_PROOPENFILES = 7, // currently opened files |
|
119 |
+ SEQAN_PROIWAIT = 8, // waiting time (initiating) |
|
120 |
+ SEQAN_PROCWAIT = 9, // waiting time (completing) |
|
121 |
+ SEQAN_PROEXTRA1 = 10, |
|
122 |
+ SEQAN_PROEXTRA2 = 11, |
|
123 |
+ SEQAN_PROEXTRA3 = 12, |
|
124 |
+ SEQAN_PROINDEXCOUNT = 13, |
|
125 |
+ SEQAN_PROEXTRACOUNT = 3 |
|
126 |
+ }; |
|
127 |
+ |
|
128 |
+ const char ProfileValueType_[] = { |
|
129 |
+ SEQAN_PROTIME, |
|
130 |
+ SEQAN_PROTIME, |
|
131 |
+ SEQAN_PROINT + SEQAN_PROSTATE, |
|
132 |
+ SEQAN_PROINT, |
|
133 |
+ SEQAN_PROINT, |
|
134 |
+ SEQAN_PROINT + SEQAN_PROSTATE, |
|
135 |
+ SEQAN_PROINT + SEQAN_PROSTATE, |
|
136 |
+ SEQAN_PROINT + SEQAN_PROSTATE, |
|
137 |
+ SEQAN_PROFLOAT, |
|
138 |
+ SEQAN_PROFLOAT, |
|
139 |
+ SEQAN_PROFLOAT + SEQAN_PROSTATE, |
|
140 |
+ SEQAN_PROFLOAT + SEQAN_PROSTATE, |
|
141 |
+ SEQAN_PROFLOAT + SEQAN_PROSTATE |
|
142 |
+ }; |
|
143 |
+ |
|
144 |
+ typedef ProfileTimeValue_ ProfileTStates_[SEQAN_PROINDEXCOUNT]; //IOREV _notio_ |
|
145 |
+ typedef _proFloat ProfileTTimes[SEQAN_PROINDEXCOUNT]; //IOREV _notio_ |
|
146 |
+ |
|
147 |
+ |
|
148 |
+ |
|
149 |
+ struct ProfileFile_; |
|
150 |
+//IOREV |
|
151 |
+ |
|
152 |
+ template <typename T = void> |
|
153 |
+ struct ProfileData_ |
|
154 |
+ { |
|
155 |
+//IOREV _notio_ |
|
156 |
+ static ProfileTStates_ _proValue; |
|
157 |
+ static ProfileTTimes _proLastUpdate; |
|
158 |
+ static int _proExtraCount; |
|
159 |
+ |
|
160 |
+ static clock_t _proCpuTimeLast; // clock_t wraps around every 72mins |
|
161 |
+ static ProfileInt_ _proCpuTimeOffset; // we have to work around this |
|
162 |
+ |
|
163 |
+ static ProfileFile_* _proPFile; |
|
164 |
+ static ProfileFile_* _proPFileStream; |
|
165 |
+ }; |
|
166 |
+ |
|
167 |
+ template <typename T> ProfileTStates_ ProfileData_<T>::_proValue = {}; |
|
168 |
+ template <typename T> ProfileTStates_ ProfileData_<T>::_proLastUpdate = {}; |
|
169 |
+ template <typename T> int ProfileData_<T>::_proExtraCount = 0; |
|
170 |
+ template <typename T> clock_t ProfileData_<T>::_proCpuTimeLast = 0; |
|
171 |
+ template <typename T> ProfileInt_ ProfileData_<T>::_proCpuTimeOffset = 0; |
|
172 |
+ template <typename T> ProfileFile_* ProfileData_<T>::_proPFile = NULL; |
|
173 |
+ template <typename T> ProfileFile_* ProfileData_<T>::_proPFileStream = NULL; |
|
174 |
+ |
|
175 |
+ |
|
176 |
+ inline ProfileFile_* & _proPFile() { return ProfileData_<>::_proPFile; } |
|
177 |
+//IOREV |
|
178 |
+ inline ProfileFile_* & _proPFileStream() { return ProfileData_<>::_proPFileStream; } |
|
179 |
+//IOREV |
|
180 |
+ |
|
181 |
+/*! |
|
182 |
+ * @fn cpuTime |
|
183 |
+ * @headerfile <seqan/basic.h> |
|
184 |
+ * @brief Returns the cpu time in seconds. |
|
185 |
+ * |
|
186 |
+ * @signature double cpuTime(); |
|
187 |
+ * |
|
188 |
+ * @return double CPU time stamp in seconds. |
|
189 |
+ * |
|
190 |
+ * Calls <tt>clock</tt> to retrieve the processor time used by the running thread. This implies that the thread's |
|
191 |
+ * processor time does not tick if the thread is suspended. While this has its advantages, benchmarks should generally |
|
192 |
+ * focus on wall clock time, not processor time. Wall clock time is returned by sysTime. |
|
193 |
+ * |
|
194 |
+ * @see sysTime |
|
195 |
+ */ |
|
196 |
+ |
|
197 |
+ |
|
198 |
+// HINT: The unit of all time functions is second. |
|
199 |
+ inline _proFloat cpuTime() { |
|
200 |
+ clock_t now = clock(); |
|
201 |
+ if (ProfileData_<>::_proCpuTimeLast > now) { // test for time wrap |
|
202 |
+ ProfileData_<>::_proCpuTimeOffset += (~0u); // got one |
|
203 |
+ ProfileData_<>::_proCpuTimeOffset ++; |
|
204 |
+// printf("\n!!WRAP!! old:%d, now:%d ofs:%d\n",ProfileData_<>::_proCpuTimeLast,now,ProfileData_<>::_proCpuTimeOffset); |
|
205 |
+ } |
|
206 |
+ ProfileData_<>::_proCpuTimeLast = now; |
|
207 |
+ return (ProfileData_<>::_proCpuTimeOffset + now) / (_proFloat)CLOCKS_PER_SEC; |
|
208 |
+ } |
|
209 |
+ |
|
210 |
+/*! |
|
211 |
+ * @fn sysTime |
|
212 |
+ * @headerfile <seqan/basic.h> |
|
213 |
+ * @brief Returns the system time in seconds. |
|
214 |
+ * |
|
215 |
+ * @signature double sysTime(); |
|
216 |
+ * |
|
217 |
+ * @return double A <tt>double</tt>, system time stamp in seconds. Types: nolink:double |
|
218 |
+ * |
|
219 |
+ * In contrast to @link cpuTime @endlink, the system time corresponds to the wall clock time under Linux and Mac OS X. |
|
220 |
+ * Under Windows sysTime returns the result of cpuTime. |
|
221 |
+ * |
|
222 |
+ * Use this for benchmarking uner Linux and Mac Os X. |
|
223 |
+ * |
|
224 |
+ * Calls <tt>clock_gettime</tt> under Linux and <tt>gettimeofday</tt> under Mac OS X. |
|
225 |
+ * |
|
226 |
+ * @section Examples |
|
227 |
+ * |
|
228 |
+ * We can use sysTime to instrument our code for profiling/timing information quite robustly. The following demonstrates |
|
229 |
+ * how the Function.sysTime is used in many SeqAn apps for collecting timing information. |
|
230 |
+ * |
|
231 |
+ * @code{.cpp} |
|
232 |
+ * bool printTiming = true; |
|
233 |
+ * |
|
234 |
+ * // ... |
|
235 |
+ * |
|
236 |
+ * double startTime = sysTime(); |
|
237 |
+ * // Do some complex calculation. |
|
238 |
+ * if (printTiming) |
|
239 |
+ * std::cerr << "Some complex calculation too " << sysTime() - startTime << " s." << std::endl; |
|
240 |
+ * @endcode |
|
241 |
+ * |
|
242 |
+ * @see cpuTime |
|
243 |
+ */ |
|
244 |
+ inline _proFloat sysTime() |
|
245 |
+ { |
|
246 |
+ return static_cast<_proFloat>(std::chrono::system_clock::now().time_since_epoch() / |
|
247 |
+ std::chrono::duration<_proFloat>(1)); |
|
248 |
+ } |
|
249 |
+ |
|
250 |
+ struct ProfileFile_ { |
|
251 |
+//IOREV not generic, uses FILE* instead of File() and custom IO |
|
252 |
+ |
|
253 |
+ FILE *out; |
|
254 |
+ bool running; |
|
255 |
+ |
|
256 |
+ _proFloat dumpStep; // 0 .. manual dump mode, >0 .. live stream |
|
257 |
+ _proFloat dumpNext; |
|
258 |
+ |
|
259 |
+ ProfileTStates_ all, last; |
|
260 |
+ std::string mark; |
|
261 |
+ unsigned lines; |
|
262 |
+ |
|
263 |
+ ProfileFile_() { |
|
264 |
+ running = false; |
|
265 |
+ } |
|
266 |
+ |
|
267 |
+ ProfileFile_(char const *fname, _proFloat _dumpStep = 300.0) { // five minutes default dump interval |
|
268 |
+ running = false; |
|
269 |
+ start(fname, _dumpStep); |
|
270 |
+ } |
|
271 |
+ |
|
272 |
+ ~ProfileFile_() { |
|
273 |
+ if (running) stop(); |
|
274 |
+ } |
|
275 |
+ |
|
276 |
+ inline void start(char const *fname, _proFloat _dumpStep = 300.0, bool append = false) { |
|
277 |
+ if (append) |
|
278 |
+ out = fopen(fname, "a"); |
|
279 |
+ else { |
|
280 |
+ out = fopen(fname, "w"); |
|
281 |
+ dumpHeader(); |
|
282 |
+ } |
|
283 |
+ |
|
284 |
+ if (!out) printf("WARNING: proFile could not be opened.\n"); |
|
285 |
+ |
|
286 |
+ setTime(ProfileData_<>::_proValue); |
|
287 |
+ syncAll(all); |
|
288 |
+ syncAll(last); |
|
289 |
+ running = true; |
|
290 |
+ lines = 0; |
|
291 |
+ dumpStep = _dumpStep; |
|
292 |
+ dumpNext = sysTime(); |
|
293 |
+ dump(last); |
|
294 |
+ } |
|
295 |
+ |
|
296 |
+ inline void stop() { |
|
297 |
+ dump(last); |
|
298 |
+ maximize(all, last); |
|
299 |
+ if (dumpStep == 0) { |
|
300 |
+ mark = "Zusammenfassung"; |
|
301 |
+ dump(all); |
|
302 |
+ } |
|
303 |
+ fclose(out); |
|
304 |
+ running = false; |
|
305 |
+ } |
|
306 |
+ |
|
307 |
+ inline void syncTime(ProfileTStates_ &dst) { |
|
308 |
+ std::memcpy(dst, ProfileData_<>::_proValue, 2 * sizeof(ProfileTimeValue_)); |
|
309 |
+ } |
|
310 |
+ |
|
311 |
+ inline void sync(ProfileTStates_ &dst) { |
|
312 |
+ std::memcpy(&(dst[2]), &(ProfileData_<>::_proValue[2]), sizeof(ProfileTStates_) - 2 * sizeof(ProfileTimeValue_)); |
|
313 |
+ } |
|
314 |
+ |
|
315 |
+ inline void syncAll(ProfileTStates_ &dst) { |
|
316 |
+ std::memcpy(dst, ProfileData_<>::_proValue, sizeof(ProfileTStates_)); |
|
317 |
+ } |
|
318 |
+ |
|
319 |
+ inline static void setTime(ProfileTStates_ &dst) { |
|
320 |
+ dst[0] = sysTime(); |
|
321 |
+ dst[1] = cpuTime(); |
|
322 |
+ } |
|
323 |
+ |
|
324 |
+ inline void maximize(ProfileTStates_ &dst, ProfileTStates_ const &src) { |
|
325 |
+ for(int i = 0; i < SEQAN_PROINDEXCOUNT; ++i) |
|
326 |
+ if (((ProfileValueType_[i] & SEQAN_PROSTATE) != 0)) |
|
327 |
+ if (dst[i] < src[i]) |
|
328 |
+ dst[i] = src[i]; |
|
329 |
+ } |
|
330 |
+ |
|
331 |
+ inline void dumpTab() { |
|
332 |
+ if (!bol) |
|
333 |
+ fprintf(out, " \t"); |
|
334 |
+ bol = false; |
|
335 |
+ } |
|
336 |
+ |
|
337 |
+ inline void dumpEndl() { fprintf(out, "\n"); } |
|
338 |
+ |
|
339 |
+ inline void dumpHeader() { |
|
340 |
+ fprintf(out, "\"Echtzeit\"\t\"CPU-Zeit\"\t\"Speicher\"\t\"I/O-Zugriffe\"\t\"wahlfreie I/Os\"\t\"I/O-Volumen\"\t\"Rekursionstiefe\"\t\"Offene Dateien\"\t\"Idle-Zeit vor I/O\"\t\"Idle-Zeit nach I/O\"\n"); |
|
341 |
+ } |
|
342 |
+ |
|
343 |
+ inline void dumpTime(_proFloat seconds) { |
|
344 |
+ if (seconds < 0) { |
|
345 |
+ fputc('-', out); |
|
346 |
+ seconds = -seconds; |
|
347 |
+ } |
|
348 |
+ int secs = (int)seconds; |
|
349 |
+ int mins = secs/60; secs -= 60*mins; |
|
350 |
+ int hours = mins/60; mins -= 60*hours; |
|
351 |
+ fprintf(out, "%d:%02d:%02d", hours, mins, secs); |
|
352 |
+ } |
|
353 |
+ |
|
354 |
+ inline void dumpTimeEx(_proFloat seconds) { |
|
355 |
+ int milli = (int)(seconds * 1000.0); |
|
356 |
+ int secs = (int)seconds; |
|
357 |
+ int mins = secs/60; secs -= 60*mins; |
|
358 |
+ int hours = mins/60; mins -= 60*hours; |
|
359 |
+ fprintf(out, "%d:%02d:%02d.%03d", hours, mins, secs, milli); |
|
360 |
+ } |
|
361 |
+ |
|
362 |
+ inline void dumpValue(ProfileTStates_ &stat, int valNum) { |
|
363 |
+ _proFloat f = stat[valNum]; |
|
364 |
+ if ((ProfileValueType_[valNum] & SEQAN_PROSTATE) == 0) |
|
365 |
+ f = ProfileData_<>::_proValue[valNum] - f; |
|
366 |
+ |
|
367 |
+ switch (ProfileValueType_[valNum] & SEQAN_PROTYPEMASK) { |
|
368 |
+ case SEQAN_PROINT: // state value -> print last seen maximum |
|
369 |
+ fprintf(out, "%.0f", f); |
|
370 |
+ break; |
|
371 |
+ |
|
372 |
+ case SEQAN_PROFLOAT: |
|
373 |
+ fprintf(out, "%f", f); |
|
374 |
+ break; |
|
375 |
+ |
|
376 |
+ case SEQAN_PROTIME: |
|
377 |
+ dumpTimeEx(f); |
|
378 |
+ } |
|
379 |
+ } |
|
380 |
+ |
|
381 |
+ inline void dumpSysValues(ProfileTStates_ &stat) { |
|
382 |
+ for(int i = 0; i < SEQAN_PROINDEXCOUNT - SEQAN_PROEXTRACOUNT; ++i) { |
|
383 |
+ dumpTab(); |
|
384 |
+ dumpValue(stat, i); |
|
385 |
+ } |
|
386 |
+ } |
|
387 |
+ |
|
388 |
+ inline void dumpExtraValues(ProfileTStates_ &stat) { |
|
389 |
+ for(int i = 0; i < ProfileData_<>::_proExtraCount; ++i) { |
|
390 |
+ dumpTab(); |
|
391 |
+ dumpValue(stat, SEQAN_PROINDEXCOUNT - SEQAN_PROEXTRACOUNT + i); |
|
392 |
+ } |
|
393 |
+ } |
|
394 |
+ |
|
395 |
+ inline void dumpMark() { |
|
396 |
+ if (!mark.empty()) { |
|
397 |
+ dumpTab(); |
|
398 |
+ fprintf(out, "\"%s\"", mark.c_str()); |
|
399 |
+ mark.erase(); |
|
400 |
+ } |
|
401 |
+ } |
|
402 |
+ |
|
403 |
+ inline void dump(ProfileTStates_ &stat) { |
|
404 |
+ setTime(ProfileData_<>::_proValue); |
|
405 |
+ dumpNext += dumpStep; |
|
406 |
+ bol = true; |
|
407 |
+ bool _flush = ((dumpStep == 0.0)) || ((lines & 16) == 0); |
|
408 |
+ |
|
409 |
+ dumpSysValues(stat); |
|
410 |
+ dumpExtraValues(stat); |
|
411 |
+ dumpMark(); |
|
412 |
+ dumpEndl(); |
|
413 |
+ if (_flush) fflush(out); |
|
414 |
+ ++lines; |
|
415 |
+ } |
|
416 |
+ |
|
417 |
+ inline void signalDumpTest(_proFloat now) { |
|
418 |
+ if (dumpStep > 0 && now > dumpNext && running) { |
|
419 |
+ dump(last); |
|
420 |
+ maximize(all, last); |
|
421 |
+ sync(last); |
|
422 |
+ } |
|
423 |
+ } |
|
424 |
+ |
|
425 |
+ inline void signalNewMax(int valNum) { |
|
426 |
+ if (running) |
|
427 |
+ if (last[valNum] < ProfileData_<>::_proValue[valNum]) |
|
428 |
+ last[valNum] = ProfileData_<>::_proValue[valNum]; |
|
429 |
+ } |
|
430 |
+ |
|
431 |
+ inline void setMark(const char *text) { |
|
432 |
+ if (running) { |
|
433 |
+ mark = text; |
|
434 |
+ if (dumpStep == 0.0) { |
|
435 |
+ dump(last); // manual dump; |
|
436 |
+ maximize(all, last); |
|
437 |
+ sync(last); |
|
438 |
+ } |
|
439 |
+ } |
|
440 |
+ } |
|
441 |
+ |
|
442 |
+ inline void reset() { |
|
443 |
+ syncTime(last); |
|
444 |
+ } |
|
445 |
+ |
|
446 |
+ inline void setEndMark(const char *text) { |
|
447 |
+ if (running) { |
|
448 |
+ setMark(text); |
|
449 |
+ reset(); |
|
450 |
+ } |
|
451 |
+ } |
|
452 |
+ |
|
453 |
+ private: |
|
454 |
+ |
|
455 |
+ bool bol; // begin of line |
|
456 |
+ }; |
|
457 |
+ |
|
458 |
+ |
|
459 |
+ |
|
460 |
+/* |
|
461 |
+ inline void _profileSignalDumpTest(_proFloat now); |
|
462 |
+ inline void _profileSignalNewMax(int valNum); |
|
463 |
+ inline void _profileMark(const char *text); |
|
464 |
+ inline void _profileEndMark(const char *text); |
|
465 |
+ inline void _profileReset(); |
|
466 |
+ |
|
467 |
+ inline void _profileSet(int valNum, _proFloat value); |
|
468 |
+ inline void _profileAdd(int valNum, _proFloat value); |
|
469 |
+ inline void _profileSub(int valNum, _proFloat value); |
|
470 |
+ |
|
471 |
+ // simple interface for external programs |
|
472 |
+ inline void *_profileMalloc(size_t size); |
|
473 |
+ inline void _profileFree(void *_ptr); |
|
474 |
+*/ |
|
475 |
+ |
|
476 |
+ inline void _profileSignalDumpTest(_proFloat now) { |
|
477 |
+//IOREV _notio_ |
|
478 |
+ if (ProfileData_<>::_proPFileStream) ProfileData_<>::_proPFileStream->signalDumpTest(now); |
|
479 |
+ } |
|
480 |
+ |
|
481 |
+ inline void _profileSignalNewMax(int valNum) { |
|
482 |
+//IOREV _notio_ |
|
483 |
+ if (((ProfileValueType_[valNum] & SEQAN_PROSTATE) != 0)) { |
|
484 |
+ if (ProfileData_<>::_proPFileStream) ProfileData_<>::_proPFileStream->signalNewMax(valNum); |
|
485 |
+ if (ProfileData_<>::_proPFile) ProfileData_<>::_proPFile->signalNewMax(valNum); |
|
486 |
+ } |
|
487 |
+ } |
|
488 |
+ |
|
489 |
+ inline void _profileMark(const char *text) { |
|
490 |
+//IOREV _notio_ |
|
491 |
+ if (ProfileData_<>::_proPFileStream) ProfileData_<>::_proPFileStream->setMark(text); |
|
492 |
+ if (ProfileData_<>::_proPFile) ProfileData_<>::_proPFile->setMark(text); |
|
493 |
+ } |
|
494 |
+ |
|
495 |
+ inline void _profileEndMark(const char *text) { |
|
496 |
+//IOREV _notio_ |
|
497 |
+ if (ProfileData_<>::_proPFileStream) { ProfileData_<>::_proPFileStream->setEndMark(text); } |
|
498 |
+ if (ProfileData_<>::_proPFile) { ProfileData_<>::_proPFile->setEndMark(text); } |
|
499 |
+ } |
|
500 |
+ |
|
501 |
+ inline void _profileReset() { |
|
502 |
+//IOREV _notio_ |
|
503 |
+ if (ProfileData_<>::_proPFileStream) { ProfileData_<>::_proPFileStream->reset(); } |
|
504 |
+ if (ProfileData_<>::_proPFile) { ProfileData_<>::_proPFile->reset(); } |
|
505 |
+ } |
|
506 |
+ |
|
507 |
+ |
|
508 |
+ |
|
509 |
+ |
|
510 |
+ template <typename TValue> |
|
511 |
+ inline void _profileSet(ProfileValueIndex_ valNum, TValue value) { |
|
512 |
+//IOREV _notio_ |
|
513 |
+ _proFloat now = sysTime(); |
|
514 |
+ ProfileData_<>::_proLastUpdate[valNum] = now; |
|
515 |
+ if (ProfileData_<>::_proValue[valNum] < value) { |
|
516 |
+ ProfileData_<>::_proValue[valNum] = value; |
|
517 |
+ _profileSignalNewMax(valNum); |
|
518 |
+ } else |
|
519 |
+ ProfileData_<>::_proValue[valNum] = value; |
|
520 |
+ _profileSignalDumpTest(now); |
|
521 |
+ } |
|
522 |
+ |
|
523 |
+ template <typename TValue> |
|
524 |
+ inline void _profileAdd(ProfileValueIndex_ valNum, TValue value) { |
|
525 |
+//IOREV _notio_ |
|
526 |
+ _proFloat now = sysTime(); |
|
527 |
+ ProfileData_<>::_proValue[valNum] += value; |
|
528 |
+ ProfileData_<>::_proLastUpdate[valNum] = now; |
|
529 |
+ if (valNum == SEQAN_PROIO) _profileAdd(SEQAN_PROIORANDOM, 1); |
|
530 |
+ _profileSignalNewMax(valNum); |
|
531 |
+ _profileSignalDumpTest(now); |
|
532 |
+ } |
|
533 |
+ |
|
534 |
+ template <typename TValue> |
|
535 |
+ inline void _profileSub(ProfileValueIndex_ valNum, TValue value) { |
|
536 |
+//IOREV _notio_ |
|
537 |
+ _proFloat now = sysTime(); |
|
538 |
+ ProfileData_<>::_proValue[valNum] -= value; |
|
539 |
+ ProfileData_<>::_proLastUpdate[valNum] = now; |
|
540 |
+ _profileSignalDumpTest(now); |
|
541 |
+ } |
|
542 |
+ |
|
543 |
+ // simple interface for external programs |
|
544 |
+ inline void *_profileMalloc(size_t size) { |
|
545 |
+//IOREV _notio_ |
|
546 |
+ size_t *ptr = reinterpret_cast<size_t*>(malloc(size + sizeof(size_t))); |
|
547 |
+ if (ptr) { |
|
548 |
+ _profileAdd(SEQAN_PROMEMORY, (_proFloat)(*ptr = size)); |
|
549 |
+// printf("_profileMalloc %x size %d\n", ptr, size); |
|
550 |
+ ++ptr; |
|
551 |
+ } |
|
552 |
+ return ptr; |
|
553 |
+ } |
|
554 |
+ |
|
555 |
+ inline void _profileFree(void *_ptr) { |
|
556 |
+//IOREV _notio_ |
|
557 |
+ size_t *ptr = reinterpret_cast<size_t*>(_ptr); |
|
558 |
+ if (ptr) { |
|
559 |
+ --ptr; |
|
560 |
+// printf("_profileFree %x size %d\n", _ptr, *ptr); |
|
561 |
+ _profileSub(SEQAN_PROMEMORY, (_proFloat)*ptr); |
|
562 |
+ } |
|
563 |
+ free(ptr); |
|
564 |
+ } |
|
565 |
+ |
|
566 |
+ inline _proFloat _profileUpdate(_proFloat& a) { |
|
567 |
+//IOREV _notio_ |
|
568 |
+ _proFloat x = sysTime() - a; |
|
569 |
+ a += x; |
|
570 |
+ return x; |
|
571 |
+ } |
|
572 |
+} |
|
573 |
+ |
|
574 |
+#endif // #ifndef SEQAN_INCLUDE_SEQAN_BASIC_PROFILING_H_ |