resetting manifest requested domain to floor
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Profiling.h
1 /*
2 CDTestFramework http://codercorner.com
3 Copyright (c) 2007-2008 Pierre Terdiman,  pierre@codercorner.com
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose, 
8 including commercial applications, and to alter it and redistribute it freely, 
9 subject to the following restrictions:
10
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 #ifndef PROFILING_H
16 #define PROFILING_H
17
18         __forceinline void      StartProfile(int& val)
19         {
20 #ifdef WIN32
21                 __asm{
22                         cpuid
23                         rdtsc
24                         mov             ebx, val
25                         mov             [ebx], eax
26                 }
27 #endif
28         }
29
30         __forceinline void      EndProfile(int& val)
31         {
32 #ifdef WIN32
33                 __asm{
34                         cpuid
35                         rdtsc
36                         mov             ebx, val
37                         sub             eax, [ebx]
38                         mov             [ebx], eax
39                 }
40 #endif
41         }
42
43         class Profiler
44         {
45                 public:
46                                                                 Profiler() : mCycles(0), mTime(0.0f), mNbQueries(0), mMsTime(0.0f)
47                                                                 {
48                                                                         QueryPerformanceFrequency((LARGE_INTEGER*)&mFreq);
49                                                                 }
50
51                 inline_ void                    Start()
52                                                                 {
53                                                                         QueryPerformanceCounter((LARGE_INTEGER*)&mCounter0);
54                                                                         //StartProfile(mCycles);
55                                                                 }
56
57                 inline_ void                    End()
58                                                                 {
59                                                                         //EndProfile(mCycles);
60                                                                         QueryPerformanceCounter((LARGE_INTEGER*)&mCounter1);
61                                                                 }
62
63                                         void    Reset()
64                                                                 {
65                                                                         mCycles = 0;
66                                                                         mTime = 0.0f;
67                                                                         mNbQueries = 0;
68                                                                         mMsTime=0.0f;
69                                                                 }
70
71                                 void                    Accum()
72                                                                 {
73                                                                         double t = ((double)mCounter1 - (double)mCounter0)/(double)mFreq;
74                                                                         float mms = (float)t*1000000;
75
76                                                                         mTime += mms;
77                                                                         mNbQueries++;
78                                                                         if(mNbQueries==100)
79                                                                         {
80                                                                                 mNbQueries=1;
81                                                                                 mTime = mms;
82                                                                         }
83
84                                                                         mMsTime = mTime/float(mNbQueries);
85                                                                 }
86
87                                 void                    AddToTweakBar(TwBar* tbar)
88                                                                 {
89                                                                         TwAddVarRO(tbar, "Microseconds", TW_TYPE_FLOAT, &mMsTime, " group='Profiling' ");
90                                                                 }
91
92                                 __int64                 mFreq;
93                                 __int64                 mCounter0;
94                                 __int64                 mCounter1;
95                                 int                             mCycles;
96                                 float                   mTime;
97                                 udword                  mNbQueries;
98                                 float                   mMsTime;
99         };
100
101 #endif  // PROFILING_H
102