aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/perfutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/perfutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/perfutil.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/perfutil.cpp b/src/libs/dutil/WixToolset.DUtil/perfutil.cpp
new file mode 100644
index 00000000..bc138d34
--- /dev/null
+++ b/src/libs/dutil/WixToolset.DUtil/perfutil.cpp
@@ -0,0 +1,82 @@
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
6// Exit macros
7#define PerfExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
8#define PerfExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
9#define PerfExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
10#define PerfExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
11#define PerfExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
12#define PerfExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
13#define PerfExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PERFUTIL, p, x, e, s, __VA_ARGS__)
14#define PerfExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PERFUTIL, p, x, s, __VA_ARGS__)
15#define PerfExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PERFUTIL, p, x, e, s, __VA_ARGS__)
16#define PerfExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PERFUTIL, p, x, s, __VA_ARGS__)
17#define PerfExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PERFUTIL, e, x, s, __VA_ARGS__)
18#define PerfExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PERFUTIL, g, x, s, __VA_ARGS__)
19
20static BOOL vfHighPerformanceCounter = TRUE; // assume the system has a high performance counter
21static double vdFrequency = 1;
22
23
24/********************************************************************
25 PerfInitialize - initializes internal static variables
26
27********************************************************************/
28extern "C" void DAPI PerfInitialize(
29 )
30{
31 LARGE_INTEGER liFrequency = { };
32
33 //
34 // check for high perf counter
35 //
36 if (!::QueryPerformanceFrequency(&liFrequency))
37 {
38 vfHighPerformanceCounter = FALSE;
39 vdFrequency = 1000; // ticks are measured in milliseconds
40 }
41 else
42 vdFrequency = static_cast<double>(liFrequency.QuadPart);
43}
44
45
46/********************************************************************
47 PerfClickTime - resets the clicker, or returns elapsed time since last call
48
49 NOTE: if pliElapsed is NULL, resets the elapsed time
50 if pliElapsed is not NULL, returns perf number since last call to PerfClickTime()
51********************************************************************/
52extern "C" void DAPI PerfClickTime(
53 __out_opt LARGE_INTEGER* pliElapsed
54 )
55{
56 static LARGE_INTEGER liStart = { };
57 LARGE_INTEGER* pli = pliElapsed;
58
59 if (!pli) // if elapsed time time was not requested, reset the start time
60 pli = &liStart;
61
62 if (vfHighPerformanceCounter)
63 ::QueryPerformanceCounter(pli);
64 else
65 pli->QuadPart = ::GetTickCount();
66
67 if (pliElapsed)
68 pliElapsed->QuadPart -= liStart.QuadPart;
69}
70
71
72/********************************************************************
73 PerfConvertToSeconds - converts perf number to seconds
74
75********************************************************************/
76extern "C" double DAPI PerfConvertToSeconds(
77 __in const LARGE_INTEGER* pli
78 )
79{
80 Assert(0 < vdFrequency);
81 return pli->QuadPart / vdFrequency;
82}