diff options
Diffstat (limited to '')
-rw-r--r-- | src/dutil/perfutil.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/dutil/perfutil.cpp b/src/dutil/perfutil.cpp new file mode 100644 index 00000000..5c4e0774 --- /dev/null +++ b/src/dutil/perfutil.cpp | |||
@@ -0,0 +1,67 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | static BOOL vfHighPerformanceCounter = TRUE; // assume the system has a high performance counter | ||
6 | static double vdFrequency = 1; | ||
7 | |||
8 | |||
9 | /******************************************************************** | ||
10 | PerfInitialize - initializes internal static variables | ||
11 | |||
12 | ********************************************************************/ | ||
13 | extern "C" void DAPI PerfInitialize( | ||
14 | ) | ||
15 | { | ||
16 | LARGE_INTEGER liFrequency = { }; | ||
17 | |||
18 | // | ||
19 | // check for high perf counter | ||
20 | // | ||
21 | if (!::QueryPerformanceFrequency(&liFrequency)) | ||
22 | { | ||
23 | vfHighPerformanceCounter = FALSE; | ||
24 | vdFrequency = 1000; // ticks are measured in milliseconds | ||
25 | } | ||
26 | else | ||
27 | vdFrequency = static_cast<double>(liFrequency.QuadPart); | ||
28 | } | ||
29 | |||
30 | |||
31 | /******************************************************************** | ||
32 | PerfClickTime - resets the clicker, or returns elapsed time since last call | ||
33 | |||
34 | NOTE: if pliElapsed is NULL, resets the elapsed time | ||
35 | if pliElapsed is not NULL, returns perf number since last call to PerfClickTime() | ||
36 | ********************************************************************/ | ||
37 | extern "C" void DAPI PerfClickTime( | ||
38 | __out_opt LARGE_INTEGER* pliElapsed | ||
39 | ) | ||
40 | { | ||
41 | static LARGE_INTEGER liStart = { }; | ||
42 | LARGE_INTEGER* pli = pliElapsed; | ||
43 | |||
44 | if (!pli) // if elapsed time time was not requested, reset the start time | ||
45 | pli = &liStart; | ||
46 | |||
47 | if (vfHighPerformanceCounter) | ||
48 | ::QueryPerformanceCounter(pli); | ||
49 | else | ||
50 | pli->QuadPart = ::GetTickCount(); | ||
51 | |||
52 | if (pliElapsed) | ||
53 | pliElapsed->QuadPart -= liStart.QuadPart; | ||
54 | } | ||
55 | |||
56 | |||
57 | /******************************************************************** | ||
58 | PerfConvertToSeconds - converts perf number to seconds | ||
59 | |||
60 | ********************************************************************/ | ||
61 | extern "C" double DAPI PerfConvertToSeconds( | ||
62 | __in const LARGE_INTEGER* pli | ||
63 | ) | ||
64 | { | ||
65 | Assert(0 < vdFrequency); | ||
66 | return pli->QuadPart / vdFrequency; | ||
67 | } | ||