aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/hierarchical__timer_8cpp-source.html
blob: 19359fb75702e8c725073bba1b9dddb17026556e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
	<TITLE>nevrax.org : docs</TITLE>
	<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">

<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0>
 <TR>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>

<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 height=100%>
 <TR>
	<TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

		<!------ Begin Box ------>
		<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0  cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
		<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td  colspan=2 bgcolor=#FFFFFF>
		<TABLE cellspacing=0 cellpadding=1 border=0>
			<tr><td ALIGN=middle><a  class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
&nbsp;

<!-- block -->
<TABLE  bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>hierarchical_timer.cpp</h1><a href="hierarchical__timer_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00007 <font class="comment">/* Copyright, 2000, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NeL Network Services.</font>
00010 <font class="comment"> * NEVRAX NeL Network Services is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NeL Network Services is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NeL Network Services; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025 
00026 <font class="preprocessor">#include "<a class="code" href="stdmisc_8h.html">stdmisc.h</a>"</font>
00027 
00028 <font class="preprocessor">#include "<a class="code" href="hierarchical__timer_8h.html">nel/misc/hierarchical_timer.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="common_8h.html">nel/misc/common.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="debug_8h.html">nel/misc/debug.h</a>"</font>
00031 
00032 <font class="preprocessor">#ifdef NL_CPU_INTEL</font>
00033 <font class="preprocessor"></font><font class="preprocessor">#include "<a class="code" href="time__nl_8h.html">nel/misc/time_nl.h</a>"</font>
00034 <font class="preprocessor">#endif</font>
00035 <font class="preprocessor"></font>
00036 <font class="preprocessor">#include &lt;map&gt;</font>
00037 
00038 <font class="keyword">namespace </font>NLMISC
00039 {
00040 
00041      
<a name="l00042"></a><a class="code" href="classNLMISC_1_1CSimpleClock.html#r0">00042</a> <font class="keywordtype">bool</font>   CSimpleClock::_InitDone = <font class="keyword">false</font>;
<a name="l00043"></a><a class="code" href="classNLMISC_1_1CSimpleClock.html#r1">00043</a> uint64 CSimpleClock::_StartStopNumTicks = 0;
00044 
00045 
00046 <font class="comment">// root node for all execution paths</font>
<a name="l00047"></a><a class="code" href="classNLMISC_1_1CHTimer.html#r0">00047</a> CHTimer::CNode  CHTimer::_RootNode;
<a name="l00048"></a><a class="code" href="classNLMISC_1_1CHTimer.html#r1">00048</a> CHTimer::CNode *CHTimer::_CurrNode = &amp;_RootNode;
<a name="l00049"></a><a class="code" href="classNLMISC_1_1CHTimer.html#r3">00049</a> CSimpleClock    CHTimer::_PreambuleClock;
00050 CHTimer                 CHTimer::_RootTimer(<font class="stringliteral">"root"</font>, <font class="keyword">true</font>);
<a name="l00051"></a><a class="code" href="classNLMISC_1_1CHTimer.html#r5">00051</a> <font class="keywordtype">bool</font>                    CHTimer::_Benching = <font class="keyword">false</font>;
<a name="l00052"></a><a class="code" href="classNLMISC_1_1CHTimer.html#r6">00052</a> <font class="keywordtype">bool</font>                    CHTimer::_BenchStartedOnce = <font class="keyword">false</font>;
<a name="l00053"></a><a class="code" href="classNLMISC_1_1CHTimer.html#r4">00053</a> <font class="keywordtype">double</font>                  CHTimer::_MsPerTick;
<a name="l00054"></a><a class="code" href="classNLMISC_1_1CHTimer.html#r7">00054</a> <font class="keywordtype">bool</font>                    CHTimer::_WantStandardDeviation = <font class="keyword">false</font>;
<a name="l00055"></a><a class="code" href="classNLMISC_1_1CHTimer.html#r8">00055</a> CHTimer            *CHTimer::_CurrTimer = &amp;_RootTimer;
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 <font class="comment">//=================================================================</font>
<a name="l00064"></a><a class="code" href="classNLMISC_1_1CSimpleClock.html#d0">00064</a> <font class="keywordtype">void</font> CSimpleClock::init()
00065 {       
00066         <font class="keywordflow">if</font> (_InitDone) <font class="keywordflow">return</font>;
00067         <font class="keyword">const</font> uint numSamples = 10000;
00068 
00069         <a class="code" href="classNLMISC_1_1CSimpleClock.html#a0">CSimpleClock</a> observedClock;
00070         <a class="code" href="classNLMISC_1_1CSimpleClock.html#a0">CSimpleClock</a> measuringClock;
00071         
00072         measuringClock.start();
00073         <font class="keywordflow">for</font>(uint <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> = 0; <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> &lt; numSamples; ++<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>)
00074         {               
00075                 observedClock.start();
00076                 observedClock.stop();
00077         }
00078         measuringClock.stop();
00079 
00080         <a class="code" href="classNLMISC_1_1CSimpleClock.html#r1">_StartStopNumTicks</a> = (measuringClock.getNumTicks() &gt;&gt; 1) / numSamples;  
00081         <a class="code" href="classNLMISC_1_1CSimpleClock.html#r0">_InitDone</a> = <font class="keyword">true</font>;
00082 }
00083 
00084 
00085 
00086 <font class="comment">//=================================================================</font>
00089 <font class="comment"></font><font class="comment">/*static void PerformStatistics(const std::vector&lt;double&gt; &amp;values, double &amp;standardDeviation)</font>
00090 <font class="comment">{</font>
00091 <font class="comment">        nlassert(!values.empty());</font>
00092 <font class="comment">        double total = 0;       </font>
00093 <font class="comment">        double variance = 0;</font>
00094 <font class="comment">        uint k;</font>
00095 <font class="comment">        for(k = 0; k &lt; values.size(); ++k)</font>
00096 <font class="comment">        {</font>
00097 <font class="comment">                total += (double) values[k];            </font>
00098 <font class="comment">        }</font>
00099 <font class="comment">        meanValue = total / values.size();</font>
00100 <font class="comment">        if (values.size() &lt;= 1)</font>
00101 <font class="comment">        {</font>
00102 <font class="comment">                standardDeviation = 0.f;</font>
00103 <font class="comment">                return;</font>
00104 <font class="comment">        }</font>
00105 <font class="comment">        for(k = 0; k &lt; values.size(); ++k)</font>
00106 <font class="comment">        {</font>
00107 <font class="comment">                variance += NLMISC::sqr((values[k] - meanValue));</font>
00108 <font class="comment">        }</font>
00109 <font class="comment">        standardDeviation = ::sqrt(variance / values.size() - 1);</font>
00110 <font class="comment">}*/</font>
00111 
00112 
00113 
00114 <font class="comment">//=================================================================</font>
<a name="l00115"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a1">00115</a> CHTimer::CNode::~CNode()
00116 {
00117         <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a3">releaseSons</a>();
00118         <font class="keywordflow">for</font>(uint k = 0; k &lt; <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>.size(); ++k)
00119                 <font class="keyword">delete</font> <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>[k];
00120 }
00121 
00122 <font class="comment">//=================================================================</font>
<a name="l00123"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a3">00123</a> <font class="keywordtype">void</font> CHTimer::CNode::releaseSons()
00124 {
00125         <font class="keywordflow">for</font>(uint k = 0; k &lt; <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>.size(); ++k)
00126                 <font class="keyword">delete</font> <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>[k];
00127         <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>.clear();
00128 }
00129 
00130 <font class="comment">//=================================================================</font>
<a name="l00131"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a5">00131</a> <font class="keywordtype">void</font> CHTimer::CNode::displayPath(CLog *log)<font class="keyword"> const</font>
00132 <font class="keyword"></font>{
00133         std::string path;
00134         <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a6">getPath</a>(path);
00135         log-&gt;displayRawNL((<font class="stringliteral">"HTIMER: "</font> + path).c_str());
00136 }
00137 
00138 <font class="comment">//=================================================================</font>
<a name="l00139"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a6">00139</a> <font class="keywordtype">void</font> CHTimer::CNode::getPath(std::string &amp;path)<font class="keyword"> const</font>
00140 <font class="keyword"></font>{
00141         path.clear();
00142         <font class="keyword">const</font> <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a0">CNode</a> *currNode = <font class="keyword">this</font>;
00143         <font class="keywordflow">do</font>
00144         {
00145                 path = path.empty() ? currNode-&gt;Owner-&gt;getName() 
00146                         : currNode-&gt;Owner-&gt;getName() + std::string(<font class="stringliteral">"::"</font>) + path;
00147                 currNode = currNode-&gt;Parent;
00148         }
00149         <font class="keywordflow">while</font> (currNode);
00150 }
00151 
00152 
00153 <font class="comment">//=================================================================</font>
<a name="l00154"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a2">00154</a> uint CHTimer::CNode::getNumNodes()<font class="keyword"> const</font>
00155 <font class="keyword"></font>{
00156         uint sum = 1;
00157         <font class="keywordflow">for</font>(uint k = 0; k &lt; <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>.size(); ++k)
00158         {
00159                 sum += <a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>[k]-&gt;getNumNodes();
00160         }
00161         <font class="keywordflow">return</font> sum;
00162 }
00163 
00164 
00165 <font class="comment">//=================================================================</font>
<a name="l00166"></a><a class="code" href="classNLMISC_1_1CHTimer.html#c0">00166</a> <font class="keywordtype">void</font> CHTimer::walkTreeToCurrent()
00167 {
00168         <font class="keywordflow">if</font> (_IsRoot) <font class="keywordflow">return</font>;    
00169         <font class="keywordtype">bool</font> found = <font class="keyword">false</font>;
00170         <font class="keywordflow">for</font>(uint k = 0; k &lt; <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>.size(); ++k)
00171         {
00172                 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>[k]-&gt;Owner == <font class="keyword">this</font>)
00173                 {
00174                         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a> = <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>[k];
00175                         found = <font class="keyword">true</font>;
00176                         <font class="keywordflow">break</font>;
00177                 }
00178         }
00179         <font class="keywordflow">if</font> (!found)
00180         {
00181                 <font class="comment">// no node for this execution path : create a new one</font>
00182                 <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>.push_back(<font class="keyword">new</font> CNode(<font class="keyword">this</font>, <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>));
00183                 <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>.back()-&gt;Parent = <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>;
00184                 <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a> = <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m1">Sons</a>.back();
00185         }
00186 }
00187 
00188 <font class="preprocessor">#ifdef  NL_CPU_INTEL</font>
00189 <font class="preprocessor"></font><font class="comment">//=================================================================</font>
00190 uint64 CHTimer::getProcessorFrequency(<font class="keywordtype">bool</font> quick)
00191 {
00192         <font class="keyword">static</font> uint64 freq;
00193         <font class="keyword">static</font> <font class="keywordtype">bool</font> freqComputed = <font class="keyword">false</font>;       
00194         <font class="keywordflow">if</font> (freqComputed) <font class="keywordflow">return</font> freq;
00195 
00196         <font class="keywordflow">if</font> (!quick)
00197         {
00198                 <a class="code" href="namespaceNLMISC.html#a184">TTicks</a> bestNumTicks   = 0;
00199                 uint64 bestNumCycles;
00200                 uint64 numCycles;
00201                 <font class="keyword">const</font> uint numSamples = 5;
00202                 <font class="keyword">const</font> uint numLoops   = 50000000;
00203 
00204                 <font class="keyword">volatile</font> uint k; <font class="comment">// prevent optimisation for the loop</font>
00205                 <font class="keyword">volatile</font> dummy = 0;
00206                 <font class="keywordflow">for</font>(uint <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> = 0; <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> &lt; numSamples; ++<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>)
00207                 {       
00208                         <a class="code" href="namespaceNLMISC.html#a184">TTicks</a> startTick = <a class="code" href="classNLMISC_1_1CTime.html#d2">NLMISC::CTime::getPerformanceTime</a>();
00209                         uint64 startCycle = rdtsc();
00210                         uint dummy = 0;
00211                         <font class="keywordflow">for</font>(k = 0; k &lt; numLoops; ++k)
00212                         {               
00213                                 ++ dummy;
00214                         }               
00215                         numCycles = rdtsc() - startCycle;
00216                         <a class="code" href="namespaceNLMISC.html#a184">TTicks</a> numTicks = <a class="code" href="classNLMISC_1_1CTime.html#d2">NLMISC::CTime::getPerformanceTime</a>() - startTick;
00217                         <font class="keywordflow">if</font> (numTicks &gt; bestNumTicks)
00218                         {               
00219                                 bestNumTicks  = numTicks;
00220                                 bestNumCycles = numCycles;
00221                         }
00222                 }
00223                 freq = (uint64) ((double) bestNumCycles * 1 / CTime::ticksToSecond(bestNumTicks));
00224         }
00225         <font class="keywordflow">else</font>
00226         {
00227                 <a class="code" href="namespaceNLMISC.html#a184">TTicks</a> timeBefore = <a class="code" href="classNLMISC_1_1CTime.html#d2">NLMISC::CTime::getPerformanceTime</a>();
00228                 uint64 tickBefore = rdtsc();
00229                 <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a> (100);
00230                 <a class="code" href="namespaceNLMISC.html#a184">TTicks</a> timeAfter = <a class="code" href="classNLMISC_1_1CTime.html#d2">NLMISC::CTime::getPerformanceTime</a>();
00231                 <a class="code" href="namespaceNLMISC.html#a184">TTicks</a> tickAfter = rdtsc();
00232 
00233                 <font class="keywordtype">double</font> timeDelta = CTime::ticksToSecond(timeAfter - timeBefore);
00234                 <a class="code" href="namespaceNLMISC.html#a184">TTicks</a> tickDelta = tickAfter - tickBefore;
00235 
00236                 freq = (uint64) ((double)tickDelta / timeDelta);
00237         }
00238 
00239         <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"HTIMER: Processor frequency is %.0f MHz"</font>, (<font class="keywordtype">float</font>)freq/1000000.0);
00240         freqComputed = <font class="keyword">true</font>;
00241         <font class="keywordflow">return</font> freq;
00242 }
00243 <font class="preprocessor">#endif</font>
00244 <font class="preprocessor"></font>
00245 
00246 <font class="comment">//=================================================================</font>
<a name="l00247"></a><a class="code" href="classNLMISC_1_1CHTimer.html#d0">00247</a> <font class="keywordtype">void</font>    CHTimer::startBench(<font class="keywordtype">bool</font> wantStandardDeviation <font class="comment">/*= false*/</font>, <font class="keywordtype">bool</font> quick)
00248 {
00249         <a class="code" href="debug_8h.html#a6">nlassert</a>(!<a class="code" href="classNLMISC_1_1CHTimer.html#r5">_Benching</a>)
00250         <a class="code" href="classNLMISC_1_1CHTimer.html#d9">clear</a>();
00251         <a class="code" href="classNLMISC_1_1CHTimer.html#r5">_Benching</a> = <font class="keyword">true</font>;
00252         <a class="code" href="classNLMISC_1_1CHTimer.html#r6">_BenchStartedOnce</a> = <font class="keyword">true</font>;
00253         <a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>.<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m2">Owner</a> = &amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r2">_RootTimer</a>;
00254 <font class="preprocessor">#       ifdef NL_CPU_INTEL</font>
00255 <font class="preprocessor"></font>                <font class="keywordtype">double</font> freq = (double) getProcessorFrequency(quick);
00256                 <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a> = 1000 / (double) freq;
00257 <font class="preprocessor">#       else</font>
00258 <font class="preprocessor"></font>                <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a> = CTime::ticksToSecond(1000);
00259 <font class="preprocessor">#       endif</font>
00260 <font class="preprocessor"></font>        CSimpleClock::init();
00261         <a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>.<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m2">Owner</a> = &amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r2">_RootTimer</a>;
00262         <a class="code" href="classNLMISC_1_1CHTimer.html#r7">_WantStandardDeviation</a> = wantStandardDeviation;
00263         <a class="code" href="classNLMISC_1_1CHTimer.html#r2">_RootTimer</a>.before();
00264 }
00265 
00266 <font class="comment">//=================================================================</font>
<a name="l00267"></a><a class="code" href="classNLMISC_1_1CHTimer.html#d3">00267</a> <font class="keywordtype">void</font>    CHTimer::endBench()
00268 {
00269         <font class="keywordflow">if</font> (!<a class="code" href="classNLMISC_1_1CHTimer.html#r5">_Benching</a>)
00270                 <font class="keywordflow">return</font>;
00271 
00272         <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a> == &amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>)
00273         {
00274                 <a class="code" href="classNLMISC_1_1CHTimer.html#r2">_RootTimer</a>.after();
00275         }
00276         <font class="keywordflow">else</font>
00277         {
00278                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"FEHTIMER&gt; Stopping the bench inside a benched functions !"</font>);
00279         }
00280         <a class="code" href="classNLMISC_1_1CHTimer.html#r5">_Benching</a> = <font class="keyword">false</font>;
00281 }
00282 
00283 <font class="comment">//=================================================================</font>
<a name="l00284"></a><a class="code" href="classNLMISC_1_1CHTimer.html#d4">00284</a> <font class="keywordtype">void</font>    CHTimer::display(CLog *log, TSortCriterion criterion, <font class="keywordtype">bool</font> displayInline <font class="comment">/*= true*/</font>, <font class="keywordtype">bool</font> displayEx)
00285 {       
00286         CSimpleClock    benchClock;
00287         benchClock.start();
00288         <font class="keywordflow">if</font>(!<a class="code" href="classNLMISC_1_1CHTimer.html#r6">_BenchStartedOnce</a>) <font class="comment">// should have done at least one bench   </font>
00289         {
00290                 benchClock.stop();
00291                 <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m10">SonsPreambule</a> += benchClock.getNumTicks();
00292                 <font class="keywordflow">return</font>;
00293         }
00294         log-&gt;displayNL(<font class="stringliteral">"HTIMER: ========================================================================="</font>);
00295         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Bench cumuled results"</font>);
00296         <font class="keyword">typedef</font> std::map&lt;CHTimer *, TNodeVect&gt; TNodeMap;
00297         TNodeMap nodeMap;
00298         <a class="code" href="classNLMISC_1_1CHTimer.html#u0">TNodeVect</a> nodeLeft;     
00299         nodeLeft.push_back(&amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>);
00301         <font class="keywordflow">while</font> (!nodeLeft.empty())
00302         {       
00303                 CNode *currNode = nodeLeft.back();
00304                 nodeMap[currNode-&gt;Owner].push_back(currNode);
00305                 nodeLeft.pop_back();
00306                 nodeLeft.insert(nodeLeft.end(), currNode-&gt;Sons.begin(), currNode-&gt;Sons.end());
00307 
00308         }
00309         <font class="comment">//      </font>
00310         <font class="comment">// 2 ) build statistics </font>
00311         <font class="keyword">typedef</font> std::vector&lt;CTimerStat&gt; TTimerStatVect;
00312         <font class="keyword">typedef</font> std::vector&lt;CTimerStat *&gt; TTimerStatPtrVect;
00313         TTimerStatVect          stats(nodeMap.size());
00314         TTimerStatPtrVect       statsPtr(stats.size());
00315         <font class="comment">//</font>
00316         uint k = 0;
00317         <font class="keywordflow">for</font>(TNodeMap::iterator it = nodeMap.begin(); it != nodeMap.end(); ++it)
00318         {
00319                 statsPtr[k] = &amp;stats[k];
00320                 stats[k].Timer = it-&gt;first;
00321                 stats[k].buildFromNodes(&amp;(it-&gt;second[0]), it-&gt;second.size(), <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);
00322                 ++k;
00323         }
00324         <font class="comment">// 3 ) sort statistics</font>
00325         <font class="keywordflow">if</font> (criterion != <a class="code" href="classNLMISC_1_1CHTimer.html#s8s0">NoSort</a>)
00326         {
00327                 CStatSorter sorter(criterion);
00328                 std::sort(statsPtr.begin(), statsPtr.end(), sorter);            
00329         }
00330 
00331         <font class="comment">// 4 ) get root total time.</font>
00332         CStats  rootStats;
00333         rootStats.buildFromNode( &amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>, <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);
00334 
00335         <font class="comment">// 5 ) display statistics</font>
00336         uint maxNodeLenght = 0;
00337         std::string <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>;
00338         <font class="keywordflow">if</font> (displayInline)
00339         {
00340                 <font class="keywordflow">for</font>(TTimerStatPtrVect::iterator statIt = statsPtr.begin(); statIt != statsPtr.end(); ++statIt)
00341                 {
00342                         maxNodeLenght = std::max(maxNodeLenght, strlen((*statIt)-&gt;Timer-&gt;_Name));
00343                 }
00344                 <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a> = <font class="stringliteral">"HTIMER: %-"</font> + <a class="code" href="namespaceNLMISC.html#a243">NLMISC::toString</a>(maxNodeLenght + 1) + <font class="stringliteral">"s %s"</font>;
00345         }
00346         std::string statsInline;
00347 
00348         log-&gt;displayRawNL(<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.c_str(), <font class="stringliteral">""</font>, <font class="stringliteral">" |      total |      local |       visits |  loc%/ glb% |       min |       max |      mean"</font>);
00349 
00350         <font class="keywordflow">for</font>(TTimerStatPtrVect::iterator statIt = statsPtr.begin(); statIt != statsPtr.end(); ++statIt)
00351         {
00352                 <font class="keywordflow">if</font> (!displayInline)
00353                 {               
00354                         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: ================================="</font>);
00355                         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Node %s"</font>, (*statIt)-&gt;Timer-&gt;_Name);          
00356                         (*statIt)-&gt;display(log, displayEx, <a class="code" href="classNLMISC_1_1CHTimer.html#r7">_WantStandardDeviation</a>);
00357                 }
00358                 <font class="keywordflow">else</font>
00359                 {
00360                         (*statIt)-&gt;getStats(statsInline, displayEx, rootStats.TotalTime, <a class="code" href="classNLMISC_1_1CHTimer.html#r7">_WantStandardDeviation</a>);
00361                         <font class="keywordtype">char</font> out[4096];
00362                         <a class="code" href="namespaceNLMISC.html#a211">NLMISC::smprintf</a>(out, 2048, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.c_str(), (*statIt)-&gt;Timer-&gt;_Name, statsInline.c_str());
00363                         log-&gt;displayRawNL(out);                                 
00364                 }
00365         }       
00366         benchClock.stop();
00367         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m10">SonsPreambule</a> += benchClock.getNumTicks();
00368 }
00369 
00370 <font class="comment">//================================================================================================</font>
<a name="l00371"></a><a class="code" href="classNLMISC_1_1CHTimer.html#d5">00371</a> <font class="keywordtype">void</font>            CHTimer::displayByExecutionPath(CLog *log, TSortCriterion criterion, <font class="keywordtype">bool</font> displayInline, <font class="keywordtype">bool</font> alignPaths, <font class="keywordtype">bool</font> displayEx)
00372 {       
00373         CSimpleClock    benchClock;
00374         benchClock.start();
00375         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: ========================================================================="</font>);
00376         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Bench by execution path"</font>);
00377         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNLMISC_1_1CHTimer.html#r6">_BenchStartedOnce</a>); <font class="comment">// should have done at least one bench     </font>
00378         <font class="comment">//</font>
00379         <font class="keyword">typedef</font> std::vector&lt;CNodeStat&gt;   TNodeStatVect;
00380         <font class="keyword">typedef</font> std::vector&lt;CNodeStat *&gt; TNodeStatPtrVect;
00381 
00382         TNodeStatVect nodeStats;
00383         nodeStats.reserve(<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>.<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a2">getNumNodes</a>());
00384         <a class="code" href="classNLMISC_1_1CHTimer.html#u0">TNodeVect</a> nodeLeft;     
00385         nodeLeft.push_back(&amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>);
00387         <font class="keywordflow">while</font> (!nodeLeft.empty())
00388         {       
00389                 CNode *currNode = nodeLeft.back();
00390                 
00391                 nodeStats.push_back(CNodeStat());
00392                 nodeStats.back().buildFromNode(currNode, <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);
00393                 nodeStats.back().Node = currNode;
00394 
00395                 nodeLeft.pop_back();
00396                 nodeLeft.insert(nodeLeft.end(), currNode-&gt;Sons.begin(), currNode-&gt;Sons.end());
00397 
00398         }
00399 
00401         <font class="comment">// create a pointer list</font>
00402         TNodeStatPtrVect nodeStatsPtrs(nodeStats.size());
00403         <font class="keywordflow">for</font>(uint k = 0; k &lt; nodeStats.size(); ++k)
00404         {
00405                 nodeStatsPtrs[k] = &amp;nodeStats[k];
00406         }
00407 
00408         <font class="comment">// 3 ) sort statistics</font>
00409         <font class="keywordflow">if</font> (criterion != <a class="code" href="classNLMISC_1_1CHTimer.html#s8s0">NoSort</a>)
00410         {
00411                 CStatSorter sorter(criterion);
00412                 std::sort(nodeStatsPtrs.begin(), nodeStatsPtrs.end(), sorter);
00413         }
00414 
00415         <font class="comment">// 4 ) get root total time.</font>
00416         CStats  rootStats;
00417         rootStats.buildFromNode(&amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>, <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);
00418 
00419         <font class="comment">// 5 ) display statistics</font>
00420         std::string statsInline;
00421         std::string nodePath;
00422 
00423         std::string <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>;
00424         <font class="keywordflow">if</font> (displayInline)
00425         {
00426                 <font class="keywordflow">if</font> (alignPaths)
00427                 {
00428                         uint maxSize = 0;
00429                         std::string nodePath;
00430                         <font class="keywordflow">for</font>(TNodeStatPtrVect::iterator it = nodeStatsPtrs.begin(); it != nodeStatsPtrs.end(); ++it)
00431                         {
00432                                 (*it)-&gt;Node-&gt;getPath(nodePath);
00433                                 maxSize = std::max(maxSize, nodePath.size());
00434                         }
00435                         <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a> = <font class="stringliteral">"HTIMER: %-"</font> + <a class="code" href="namespaceNLMISC.html#a243">NLMISC::toString</a>(maxSize) +<font class="stringliteral">"s %s"</font>;
00436                 }
00437                 <font class="keywordflow">else</font>
00438                 {
00439                         <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a> = <font class="stringliteral">"HTIMER: %s %s"</font>;
00440                 }
00441         }
00442 
00443         log-&gt;displayRawNL(<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.c_str(), <font class="stringliteral">""</font>, <font class="stringliteral">" |      total |      local |       visits |  loc%/ glb% |       min |       max |      mean"</font>);
00444 
00445         <font class="keywordflow">for</font>(TNodeStatPtrVect::iterator it = nodeStatsPtrs.begin(); it != nodeStatsPtrs.end(); ++it)
00446         {
00447                 <font class="keywordflow">if</font> (!displayInline)
00448                 {               
00449                         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: ================================="</font>);
00450                         (*it)-&gt;Node-&gt;displayPath(log);
00451                         (*it)-&gt;display(log, displayEx, <a class="code" href="classNLMISC_1_1CHTimer.html#r7">_WantStandardDeviation</a>);
00452                 }
00453                 <font class="keywordflow">else</font>
00454                 {
00455                         (*it)-&gt;getStats(statsInline, displayEx, rootStats.TotalTime, <a class="code" href="classNLMISC_1_1CHTimer.html#r7">_WantStandardDeviation</a>);
00456                         (*it)-&gt;Node-&gt;getPath(nodePath);
00457 
00458                         <font class="keywordtype">char</font> out[2048];
00459                         <a class="code" href="namespaceNLMISC.html#a211">NLMISC::smprintf</a>(out, 2048, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.c_str(), nodePath.c_str(), statsInline.c_str());
00460                         log-&gt;displayRawNL(out);
00461                 }
00462         }
00463         benchClock.stop();
00464         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m10">SonsPreambule</a> += benchClock.getNumTicks();
00465 }
00466 
00467 <font class="comment">//=================================================================</font>
<a name="l00468"></a><a class="code" href="classNLMISC_1_1CHTimer.html#d6">00468</a> <font class="comment">/*static*/</font> <font class="keywordtype">void</font> CHTimer::displayHierarchical(CLog *log, <font class="keywordtype">bool</font> displayEx <font class="comment">/*=true*/</font>,uint labelNumChar <font class="comment">/*=32*/</font>, uint indentationStep <font class="comment">/*= 2*/</font>)
00469 {
00470         CSimpleClock    benchClock;
00471         benchClock.start();
00472         log-&gt;displayNL(<font class="stringliteral">"HTIMER: ========================================================================="</font>);
00473         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Hierarchical display of bench"</font>);
00474         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNLMISC_1_1CHTimer.html#r6">_BenchStartedOnce</a>); <font class="comment">// should have done at least one bench</font>
00475         <font class="keyword">typedef</font> std::map&lt;CHTimer *, TNodeVect&gt; TNodeMap;
00476         TNodeMap nodeMap;
00477         <a class="code" href="classNLMISC_1_1CHTimer.html#u0">TNodeVect</a> nodeLeft;     
00478         nodeLeft.push_back(&amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>);
00480         <font class="keywordflow">while</font> (!nodeLeft.empty())
00481         {       
00482                 CNode *currNode = nodeLeft.back();
00483                 nodeMap[currNode-&gt;Owner].push_back(currNode);
00484                 nodeLeft.pop_back();
00485                 nodeLeft.insert(nodeLeft.end(), currNode-&gt;Sons.begin(), currNode-&gt;Sons.end());
00486 
00487         }
00488         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: %*s |      total |      local |       visits |  loc%%/ glb%% |       min |       max |      mean"</font>, labelNumChar, <font class="stringliteral">""</font>);
00489 
00491         CStats  rootStats;
00492         rootStats.buildFromNode(&amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>, <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);
00493 
00495         CStats  currNodeStats;
00496         std::vector&lt;uint&gt; sonsIndex;
00497         uint <a class="code" href="driver__opengl__extension__def_8h.html#a391">depth</a> = 0;
00498         <a class="code" href="classNLMISC_1_1CHTimer.html#a0">CHTimer</a> *currTimer = &amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r2">_RootTimer</a>;
00499         sonsIndex.push_back(0);
00500         <font class="keywordtype">bool</font> displayStat = <font class="keyword">true</font>;
00501         std::string resultName;
00502         std::string resultStats;
00503         <font class="keywordflow">while</font> (!sonsIndex.empty())
00504         {               
00505                 <font class="keywordflow">if</font> (displayStat)
00506                 {
00507                         resultName.resize(labelNumChar);
00508                         std::fill(resultName.begin(), resultName.end(), <font class="charliteral">'.'</font>);
00509                         uint startIndex = <a class="code" href="driver__opengl__extension__def_8h.html#a391">depth</a> * indentationStep;
00510                         uint endIndex = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(startIndex + ::strlen(currTimer-&gt;_Name), labelNumChar);                        
00511                         <font class="keywordflow">if</font> ((sint) (endIndex - startIndex) &gt;= 1)
00512                         {
00513                                 std::copy(currTimer-&gt;_Name, currTimer-&gt;_Name + (endIndex - startIndex), resultName.begin() + startIndex);
00514                         }
00515                         <a class="code" href="classNLMISC_1_1CHTimer.html#u0">TNodeVect</a> &amp;execNodes = nodeMap[currTimer];
00516                         currNodeStats.buildFromNodes(&amp;execNodes[0], execNodes.size(), <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);                      
00517                         currNodeStats.getStats(resultStats, displayEx, rootStats.TotalTime, <a class="code" href="classNLMISC_1_1CHTimer.html#r7">_WantStandardDeviation</a>);
00518                         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: %s"</font>, (resultName + resultStats).c_str());
00519                 }
00520                 <font class="keywordflow">if</font> (sonsIndex.back() == currTimer-&gt;_Sons.size())
00521                 {
00522                         sonsIndex.pop_back();
00523                         currTimer = currTimer-&gt;_Parent;
00524                         displayStat = <font class="keyword">false</font>;
00525                         -- <a class="code" href="driver__opengl__extension__def_8h.html#a391">depth</a>;
00526                 }
00527                 <font class="keywordflow">else</font>
00528                 {
00529                         currTimer = currTimer-&gt;_Sons[sonsIndex.back()];
00530                         ++ sonsIndex.back();
00531                         sonsIndex.push_back(0);                 
00532                         displayStat = <font class="keyword">true</font>;
00533                         ++ <a class="code" href="driver__opengl__extension__def_8h.html#a391">depth</a>;
00534                 }
00535         }       
00536         benchClock.stop();
00537         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m10">SonsPreambule</a> += benchClock.getNumTicks();
00538 }
00539 
00540 
00541 <font class="comment">//=================================================================</font>
<a name="l00542"></a><a class="code" href="classNLMISC_1_1CHTimer.html#d7">00542</a> <font class="comment">/*static*/</font> <font class="keywordtype">void</font>         CHTimer::displayHierarchicalByExecutionPath(CLog *log, <font class="keywordtype">bool</font> displayEx, uint labelNumChar, uint indentationStep)
00543 {
00544         <a class="code" href="classNLMISC_1_1CHTimer.html#d8">displayHierarchicalByExecutionPathSorted</a>(log, <a class="code" href="classNLMISC_1_1CHTimer.html#s8s0">NoSort</a>, displayEx, labelNumChar, indentationStep);
00545 }
00546 
00547 
00548 <font class="comment">//=================================================================</font>
<a name="l00549"></a><a class="code" href="classNLMISC_1_1CHTimer.html#d8">00549</a> <font class="comment">/*static*/</font> <font class="keywordtype">void</font>         CHTimer::displayHierarchicalByExecutionPathSorted(CLog *log, TSortCriterion criterion, <font class="keywordtype">bool</font> displayEx, uint labelNumChar, uint indentationStep)
00550 {
00551 
00552         CSimpleClock    benchClock;
00553         benchClock.start();
00554         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNLMISC_1_1CHTimer.html#r6">_BenchStartedOnce</a>); <font class="comment">// should have done at least one bench</font>
00555 
00556         <font class="comment">// get root total time.</font>
00557         CStats  rootStats;
00558         rootStats.buildFromNode(&amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>, <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);
00559 
00560 
00561         <font class="comment">// display header.</font>
00562         TDisplayInfo    dummyDspInfo;
00563         log-&gt;displayNL(<font class="stringliteral">"HTIMER: ========================================================================="</font>);
00564         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Hierarchical display of bench by execution path"</font>);
00565         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: %*s |      total |      local |       visits |  loc%%/ glb%% |       min |       max |      mean"</font>, labelNumChar, <font class="stringliteral">""</font>);
00566 
00567 
00568         <font class="comment">// use list because vector of vector is bad.</font>
00569         <a class="code" href="classstd_1_1list.html">std::list&lt; CExamStackEntry &gt;</a>    examStack;
00570 
00571         <font class="comment">// Add the root to the stack.</font>
00572         examStack.push_back( CExamStackEntry( &amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a> ) );
00573         CStats          currNodeStats;
00574         std::string resultName;
00575         std::string resultStats;
00576 
00577         <font class="keywordflow">while</font> (!examStack.empty())
00578         {
00579                 CNode                           *node = examStack.back().Node;
00580                 std::vector&lt;CNode*&gt;     &amp;children= examStack.back().Children;
00581                 uint                            child = examStack.back().CurrentChild;
00582 
00583                 <font class="comment">// If child 0, then must first build children info and display me.</font>
00584                 <font class="keywordflow">if</font> (child == 0)
00585                 {
00586                         <font class="comment">// Build Sons Infos.</font>
00587                         <font class="comment">// ==============</font>
00588                         
00589                         <font class="comment">// resize array</font>
00590                         children.resize(node-&gt;Sons.size());
00591 
00592                         <font class="comment">// If no sort, easy.</font>
00593                         <font class="keywordflow">if</font>(criterion == <a class="code" href="classNLMISC_1_1CHTimer.html#s8s0">NoSort</a>)
00594                         {
00595                                 children= node-&gt;Sons;
00596                         }
00597                         <font class="comment">// else, Sort them with criterion.</font>
00598                         <font class="keywordflow">else</font>
00599                         {
00600                                 std::vector&lt;CNodeStat&gt;          stats;
00601                                 std::vector&lt;CNodeStat *&gt;        ptrStats;
00602                                 stats.resize(children.size());
00603                                 ptrStats.resize(children.size());
00604 
00605                                 <font class="comment">// build stats.</font>
00606                                 uint    i;
00607                                 <font class="keywordflow">for</font>(i=0; i&lt;children.size(); i++)
00608                                 {
00609                                         CNode   *childNode= node-&gt;Sons[i];
00610                                         stats[i].buildFromNode(childNode, <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);
00611                                         stats[i].Node = childNode;
00612                                         ptrStats[i]= &amp;stats[i];
00613                                 }
00614 
00615                                 <font class="comment">// sort.</font>
00616                                 CStatSorter     sorter;
00617                                 sorter.Criterion= criterion;
00618                                 std::sort(ptrStats.begin(), ptrStats.end(), sorter);            
00619 
00620                                 <font class="comment">// fill children.</font>
00621                                 <font class="keywordflow">for</font>(i=0; i&lt;children.size(); i++)
00622                                 {
00623                                         children[i]= ptrStats[i]-&gt;Node;
00624                                 }
00625                         }
00626 
00627 
00628                         <font class="comment">// Display our infos</font>
00629                         <font class="comment">// ==============</font>
00630                         <font class="comment">// build the indented node name.</font>
00631                         resultName.resize(labelNumChar);
00632                         std::fill(resultName.begin(), resultName.end(), <font class="charliteral">'.'</font>);
00633                         uint startIndex = (examStack.size()-1) * indentationStep;
00634                         uint endIndex = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(startIndex + ::strlen(node-&gt;Owner-&gt;_Name), labelNumChar);                      
00635                         <font class="keywordflow">if</font> ((sint) (endIndex - startIndex) &gt;= 1)
00636                         {
00637                                 std::copy(node-&gt;Owner-&gt;_Name, node-&gt;Owner-&gt;_Name + (endIndex - startIndex), resultName.begin() + startIndex);
00638                         }
00639 
00640                         <font class="comment">// build the stats string.</font>
00641                         currNodeStats.buildFromNode(node, <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);                  
00642                         currNodeStats.getStats(resultStats, displayEx, rootStats.TotalTime, <a class="code" href="classNLMISC_1_1CHTimer.html#r7">_WantStandardDeviation</a>);
00643 
00644                         <font class="comment">// display</font>
00645                         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: %s"</font>, (resultName + resultStats).c_str());
00646                 }
00647 
00648                 <font class="comment">// End of sons?? stop.</font>
00649                 <font class="keywordflow">if</font> (child &gt;= children.size())
00650                 {
00651                         examStack.pop_back();
00652                         <font class="keywordflow">continue</font>;
00653                 }
00654 
00655                 <font class="comment">// next son.</font>
00656                 ++(examStack.back().CurrentChild);
00657 
00658                 <font class="comment">// process the current son.</font>
00659                 examStack.push_back( CExamStackEntry( children[child] ) );
00660         }
00661 
00662         <font class="comment">//</font>
00663         benchClock.stop();
00664         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m10">SonsPreambule</a> += benchClock.getNumTicks();
00665 }
00666 
00667 <font class="comment">//=================================================================</font>
<a name="l00668"></a><a class="code" href="classNLMISC_1_1CHTimer.html#d9">00668</a> <font class="keywordtype">void</font>    CHTimer::clear()
00669 {
00670         <font class="comment">// should not be benching !</font>
00671         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a> == &amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>)
00672         <a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>.<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a3">releaseSons</a>();
00673         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a> = &amp;<a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>;
00674         <a class="code" href="classNLMISC_1_1CHTimer.html#r0">_RootNode</a>.<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#a4">reset</a>();      
00675 }
00676 
00677 <font class="comment">//=================================================================</font>
<a name="l00678"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#a0">00678</a> <font class="keywordtype">void</font> CHTimer::CStats::buildFromNode(CNode *node, <font class="keywordtype">double</font> msPerTick)
00679 {
00680         <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#a1">buildFromNodes</a>(&amp;node, 1, msPerTick);
00681 }
00682 
00683 <font class="comment">//=================================================================</font>
<a name="l00684"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#a1">00684</a> <font class="keywordtype">void</font> CHTimer::CStats::buildFromNodes(CNode **nodes, uint numNodes, <font class="keywordtype">double</font> msPerTick)
00685 {
00686         <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a> = 0;  
00687         <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m2">TotalTimeWithoutSons</a> = 0;       
00688         <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m4">NumVisits</a> = 0;
00689         
00690         uint64 minTime = (uint64) -1;
00691         uint64 maxTime = 0;
00692         
00693         uint k, <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>;
00694         <font class="keywordflow">for</font>(k = 0; k &lt; numNodes; ++k)
00695         {               
00696                 <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a> += nodes[k]-&gt;TotalTime * msPerTick;
00697                 <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m2">TotalTimeWithoutSons</a> += (nodes[k]-&gt;TotalTime -  nodes[k]-&gt;LastSonsTotalTime) * msPerTick;
00698                 <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m4">NumVisits</a> += nodes[k]-&gt;NumVisits;
00699                 minTime = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(minTime, nodes[k]-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m5">MinTime</a>);
00700                 maxTime = std::max(maxTime, nodes[k]-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m6">MaxTime</a>);                         
00701         }
00702         <font class="keywordflow">if</font> (minTime == (uint64) -1) 
00703         {
00704                 minTime = 0;
00705         }
00706         <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m5">MinTime</a>  = minTime * msPerTick;
00707         <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m6">MaxTime</a>  = maxTime * msPerTick;
00708         <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m3">MeanTime</a> = <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a> / <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m4">NumVisits</a>;
00709 
00710         <font class="comment">// compute standard deviation</font>
00711         <font class="keywordtype">double</font> varianceSum = 0;
00712         uint   numMeasures = 0;
00713         <font class="keywordflow">for</font>(k = 0; k &lt; numNodes; ++k)
00714         {
00715                 numMeasures += nodes[k]-&gt;Measures.size();
00716                 <font class="keywordflow">for</font>(<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> = 0; <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> &lt; nodes[k]-&gt;Measures.size(); ++<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>)
00717                 {
00718                         varianceSum += <a class="code" href="namespaceNLMISC.html#a214">NLMISC::sqr</a>(nodes[k]-&gt;Measures[<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>] - <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m3">MeanTime</a>);
00719                 }               
00720         }
00721         <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m0">TimeStandardDeviation</a> = numMeasures == 0 ? 0
00722                                                                                          : ::sqrt(varianceSum / (numMeasures +1));
00723 }
00724 
00725 <font class="comment">//=================================================================</font>
<a name="l00726"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#a2">00726</a> <font class="keywordtype">void</font> CHTimer::CStats::display(CLog *log, <font class="keywordtype">bool</font> displayEx, <font class="keywordtype">bool</font> wantStandardDeviation <font class="comment">/* = false*/</font>)
00727 {
00728         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Total time                = %.3f ms"</font>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a>);
00729         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Total time without sons   = %.3f ms"</font>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m2">TotalTimeWithoutSons</a>);
00730         log-&gt;displayRawNL((<font class="stringliteral">"HTIMER: Num visits                = "</font> + NLMISC::toString(<a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m4">NumVisits</a>)).c_str());      
00731         <font class="keywordflow">if</font> (displayEx)
00732         {
00733                         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Min time                  = %.3f ms"</font>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m5">MinTime</a>);
00734                         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Max time                  = %.3f ms"</font>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m6">MaxTime</a>);
00735                         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Mean time                 = %.3f ms"</font>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m3">MeanTime</a>);
00736                         <font class="keywordflow">if</font> (wantStandardDeviation)
00737                         {
00738                         log-&gt;displayRawNL(<font class="stringliteral">"HTIMER: Standard deviation        = %.3f ms"</font>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m0">TimeStandardDeviation</a>);
00739                         }
00740                         <font class="comment">//log-&gt;displayRawNL("Time standard deviation    = %.3f ms", (float) TimeStandardDeviation);</font>
00741         }
00742 }
00743 
00744 
00745 <font class="comment">//=================================================================</font>
<a name="l00746"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#a3">00746</a> <font class="keywordtype">void</font> CHTimer::CStats::getStats(std::string &amp;dest, <font class="keywordtype">bool</font> statEx, <font class="keywordtype">double</font> rootTotalTime, <font class="keywordtype">bool</font> wantStandardDeviation <font class="comment">/*= false*/</font>)
00747 {
00748         <font class="keywordtype">char</font> buf[1024];
00749         <font class="keywordflow">if</font> (!wantStandardDeviation)
00750         {       
00751                 <font class="keywordflow">if</font> (!statEx)
00752                 {       
00753                         <a class="code" href="namespaceNLMISC.html#a211">NLMISC::smprintf</a>(buf, 1024, <font class="stringliteral">" | %10.3f | %10.3f | %12s "</font>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m2">TotalTimeWithoutSons</a>, <a class="code" href="namespaceNLMISC.html#a243">toString</a>(NumVisits).c_str());
00754                 }
00755                 <font class="keywordflow">else</font>
00756                 {
00757                         <a class="code" href="namespaceNLMISC.html#a211">NLMISC::smprintf</a>(buf, 1024, <font class="stringliteral">" | %10.3f | %10.3f | %12s | %5.1f/%5.1f | %9.3f | %9.3f | %9.3f"</font>,
00758                                           (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m2">TotalTimeWithoutSons</a>, <a class="code" href="namespaceNLMISC.html#a243">toString</a>(NumVisits).c_str(), 
00759                                           float(100*<a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m2">TotalTimeWithoutSons</a>/rootTotalTime), float(100*<a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a>/rootTotalTime), 
00760                                           (float) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m5">MinTime</a>, (float) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m6">MaxTime</a>, (float) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m3">MeanTime</a>
00761                                          );
00762                 }
00763         }
00764         <font class="keywordflow">else</font>
00765         {
00766                 <font class="keywordflow">if</font> (!statEx)
00767                 {       
00768                         <a class="code" href="namespaceNLMISC.html#a211">NLMISC::smprintf</a>(buf, 1024, <font class="stringliteral">" | %10.3f | %10.3f | %12s | std deviation %9.3f"</font>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m2">TotalTimeWithoutSons</a>, <a class="code" href="namespaceNLMISC.html#a243">toString</a>(NumVisits).c_str(), (float) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m0">TimeStandardDeviation</a>);
00769                 }
00770                 <font class="keywordflow">else</font>
00771                 {
00772                         <a class="code" href="namespaceNLMISC.html#a211">NLMISC::smprintf</a>(buf, 1024, <font class="stringliteral">" | %10.3f | %10.3f | %12s | %5.1f/%5.1f | %9.3f | %9.3f | %9.3f | std deviation %9.3f"</font>,
00773                                                           (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a>, (<font class="keywordtype">float</font>) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m2">TotalTimeWithoutSons</a>, <a class="code" href="namespaceNLMISC.html#a243">toString</a>(NumVisits).c_str(), 
00774                                                           float(100*<a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m2">TotalTimeWithoutSons</a>/rootTotalTime), float(100*<a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m1">TotalTime</a>/rootTotalTime), 
00775                                                           (float) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m5">MinTime</a>, (float) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m6">MaxTime</a>, (float) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m3">MeanTime</a>,
00776                                                           (float) <a class="code" href="structNLMISC_1_1CHTimer_1_1CStats.html#m0">TimeStandardDeviation</a>
00777                                                         );
00778                 }
00779         }
00780         dest = buf;
00781 }
00782 
00783 
00784 <font class="comment">//=================================================================</font>
<a name="l00785"></a><a class="code" href="structNLMISC_1_1CHTimer_1_1CStatSorter.html#a1">00785</a> <font class="keywordtype">bool</font> CHTimer::CStatSorter::operator()(<font class="keyword">const</font> CHTimer::CStats *lhs, <font class="keyword">const</font> CHTimer::CStats *rhs)
00786 {
00787         <font class="keywordflow">switch</font>(Criterion)
00788         {
00789                 <font class="keywordflow">case</font> CHTimer::TotalTime:                                <font class="keywordflow">return</font> lhs-&gt;TotalTime &gt;= rhs-&gt;TotalTime;
00790                 <font class="keywordflow">case</font> CHTimer::TotalTimeWithoutSons:             <font class="keywordflow">return</font> lhs-&gt;TotalTimeWithoutSons &gt;= rhs-&gt;TotalTimeWithoutSons;
00791                 <font class="keywordflow">case</font> CHTimer::MeanTime:                                 <font class="keywordflow">return</font> lhs-&gt;MeanTime &gt;= rhs-&gt;MeanTime;
00792                 <font class="keywordflow">case</font> CHTimer::NumVisits:                                <font class="keywordflow">return</font> lhs-&gt;NumVisits &gt;= rhs-&gt;NumVisits;
00793                 <font class="keywordflow">case</font> CHTimer::MaxTime:                                  <font class="keywordflow">return</font> lhs-&gt;MaxTime &gt;= rhs-&gt;MaxTime;
00794                 <font class="keywordflow">case</font> CHTimer::MinTime:                                  <font class="keywordflow">return</font> lhs-&gt;MinTime &lt; rhs-&gt;MinTime;     
00795                 <font class="keywordflow">default</font>:
00796                         <a class="code" href="debug_8h.html#a6">nlassert</a>(0); <font class="comment">// not a valid criterion</font>
00797                 <font class="keywordflow">break</font>;
00798         }
00799         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00800 }
00801 
00802 
00803 <font class="comment">//===============================================</font>
<a name="l00804"></a><a class="code" href="classNLMISC_1_1CHTimer.html#a1">00804</a> <font class="keywordtype">void</font>    CHTimer::before()
00805 {       
00806         <font class="keywordflow">if</font> (!<a class="code" href="classNLMISC_1_1CHTimer.html#r5">_Benching</a>) <font class="keywordflow">return</font>;
00807         <a class="code" href="classNLMISC_1_1CHTimer.html#r3">_PreambuleClock</a>.start();        
00808         <a class="code" href="classNLMISC_1_1CHTimer.html#c0">walkTreeToCurrent</a>();                    
00809         ++ <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m9">NumVisits</a>;
00810         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m10">SonsPreambule</a> = 0;
00811         <font class="keywordflow">if</font> (!<a class="code" href="classNLMISC_1_1CHTimer.html#o1">_Parent</a> &amp;&amp; <a class="code" href="classNLMISC_1_1CHTimer.html#r8">_CurrTimer</a> != <font class="keyword">this</font>)
00812         {
00813                 <a class="code" href="classNLMISC_1_1CHTimer.html#o1">_Parent</a> = <a class="code" href="classNLMISC_1_1CHTimer.html#r8">_CurrTimer</a>;
00814                 <font class="comment">// register as a son of the parent</font>
00815                 <a class="code" href="classNLMISC_1_1CHTimer.html#o1">_Parent</a>-&gt;_Sons.push_back(<font class="keyword">this</font>); 
00816         }
00817         <a class="code" href="classNLMISC_1_1CHTimer.html#r8">_CurrTimer</a> = <font class="keyword">this</font>;
00818         <a class="code" href="classNLMISC_1_1CHTimer.html#r3">_PreambuleClock</a>.stop();
00819         <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m0">Parent</a>)
00820         {       
00821                 <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m0">Parent</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m10">SonsPreambule</a> += <a class="code" href="classNLMISC_1_1CHTimer.html#r3">_PreambuleClock</a>.getNumTicks();
00822         }
00823         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m11">Clock</a>.start();
00824 }
00825 
00826 <font class="comment">//===============================================</font>
<a name="l00827"></a><a class="code" href="classNLMISC_1_1CHTimer.html#a2">00827</a> <font class="keywordtype">void</font>    CHTimer::after(<font class="keywordtype">bool</font> displayAfter <font class="comment">/*= false*/</font>)
00828 {
00829         <font class="keywordflow">if</font> (!<a class="code" href="classNLMISC_1_1CHTimer.html#r5">_Benching</a>) <font class="keywordflow">return</font>;
00830         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m11">Clock</a>.stop();                
00831         <a class="code" href="classNLMISC_1_1CHTimer.html#r3">_PreambuleClock</a>.start();
00832         <font class="comment">//              </font>
00833         <font class="comment">//nlinfo((std::string("clock ") + _Name + std::string(" time = ") + NLMISC::toString(_CurrNode-&gt;Clock.getNumTicks())).c_str());</font>
00834         sint64 numTicks = <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m11">Clock</a>.getNumTicks()  - <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m10">SonsPreambule</a> - (CSimpleClock::getStartStopNumTicks() &lt;&lt; 1);
00835         numTicks= std::max((sint64)0, numTicks);
00836 
00837         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m3">TotalTime</a> += numTicks;               
00838         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m7">MinTime</a> = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(<a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m7">MinTime</a>, (uint64)numTicks);
00839         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m8">MaxTime</a> = std::max(<a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m8">MaxTime</a>, (uint64)numTicks);
00840         <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m4">LastSonsTotalTime</a> = <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m5">SonsTotalTime</a>;
00841 
00842         <font class="keywordflow">if</font> (displayAfter)
00843         {               
00844                 <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">"FEHTIMER&gt; %s %.3fms loop number %d"</font>, <a class="code" href="classNLMISC_1_1CHTimer.html#o0">_Name</a>, numTicks * <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>, <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m9">NumVisits</a>);
00845         }
00846         <font class="comment">//</font>
00847         <font class="keywordflow">if</font> (_WantStandardDeviation)
00848         {
00849                 <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m6">Measures</a>.push_back(numTicks * <a class="code" href="classNLMISC_1_1CHTimer.html#r4">_MsPerTick</a>);
00850         }
00851         <font class="comment">//</font>
00852         <font class="keywordflow">if</font> (_Parent)
00853         {
00854                 <a class="code" href="classNLMISC_1_1CHTimer.html#r8">_CurrTimer</a> = <a class="code" href="classNLMISC_1_1CHTimer.html#o1">_Parent</a>;
00855         }       
00856         <font class="comment">//</font>
00857         <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m0">Parent</a>)
00858         {
00859                 <a class="code" href="classNLMISC_1_1CHTimer.html#r3">_PreambuleClock</a>.stop();
00860                 <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a> = <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m0">Parent</a>;
00861                 <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m5">SonsTotalTime</a> += numTicks;
00862                 <a class="code" href="classNLMISC_1_1CHTimer.html#r1">_CurrNode</a>-&gt;<a class="code" href="structNLMISC_1_1CHTimer_1_1CNode.html#m10">SonsPreambule</a> += <a class="code" href="classNLMISC_1_1CHTimer.html#r3">_PreambuleClock</a>.getNumTicks();
00863         }
00864         <font class="keywordflow">else</font>
00865         {
00866                 <a class="code" href="classNLMISC_1_1CHTimer.html#r3">_PreambuleClock</a>.stop();
00867         }
00868 }
00869 
00870 } <font class="comment">// NLMISC</font>
00871 
</pre></div>

<!-- footer -->
<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
</TD>
<TD WIDTH=15><IMG  SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>