Main Page Class List Class Members

NvBlastTime.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27
28
29 #ifndef NVBLASTTIME_H
30 #define NVBLASTTIME_H
31
32 #include "NvBlastTypes.h"
33
34
35 namespace Nv
36 {
37 namespace Blast
38 {
39
40 class Time
41 {
42 public:
43 Time() : m_lastTickCount(getTimeTicks()) {}
44
45 int64_t getElapsedTicks()
46 {
47 const int64_t lastTickCount = m_lastTickCount;
48 m_lastTickCount = getTimeTicks();
49 return m_lastTickCount - lastTickCount;
50 }
51
52 int64_t peekElapsedTicks() const
53 {
54 return getTimeTicks() - m_lastTickCount;
55 }
56
57 int64_t getLastTickCount() const
58 {
59 return m_lastTickCount;
60 }
61
62 static double seconds(int64_t ticks)
63 {
64 return s_secondsPerTick * ticks;
65 }
66
67 private:
68 int64_t getTimeTicks() const;
69 static double getTickDuration();
70
71 int64_t m_lastTickCount;
72 static const double s_secondsPerTick;
73 };
74
75 } // namespace Blast
76 } // namespace Nv
77
78
80
81 #if NV_MICROSOFT_FAMILY
82
83 #include "NvBlastIncludeWindows.h"
84
85 NV_INLINE int64_t Nv::Blast::Time::getTimeTicks() const
86 {
87 LARGE_INTEGER a;
88 QueryPerformanceCounter(&a);
89 return a.QuadPart;
90 }
91
92 NV_INLINE double Nv::Blast::Time::getTickDuration()
93 {
94 LARGE_INTEGER a;
95 QueryPerformanceFrequency(&a);
96 return 1.0 / (double)a.QuadPart;
97 }
98
99 #elif NV_UNIX_FAMILY
100
101 #include <time.h>
102
103 NV_INLINE int64_t Nv::Blast::Time::getTimeTicks() const
104 {
105 struct timespec mCurrTimeInt;
106 clock_gettime(CLOCK_REALTIME, &mCurrTimeInt);
107 return (static_cast<int64_t>(mCurrTimeInt.tv_sec) * 1000000000) + (static_cast<int64_t>(mCurrTimeInt.tv_nsec));
108 }
109
110 NV_INLINE double Nv::Blast::Time::getTickDuration()
111 {
112 return 1.e-9;
113 }
114
115 #elif NV_PS4
116
117 #include "ps4/NvBlastTimePS4.h"
118
119 #endif
120
121 #endif // #ifndef NVBLASTTIME_H
Nv::Blast::Time::getLastTickCount
int64_t getLastTickCount() const
Definition: NvBlastTime.h:57
NvBlastIncludeWindows.h
NvBlastTypes.h
Nv::Blast::Time::seconds
static double seconds(int64_t ticks)
Definition: NvBlastTime.h:62
Nv::Blast::Time::peekElapsedTicks
int64_t peekElapsedTicks() const
Definition: NvBlastTime.h:52
Nv::Blast::Time::Time
Time()
Definition: NvBlastTime.h:43
NV_INLINE
#define NV_INLINE
Definition: NvPreprocessor.h:350
Nv::Blast::Time
Definition: NvBlastTime.h:40
Nv::Blast::Time::getElapsedTicks
int64_t getElapsedTicks()
Definition: NvBlastTime.h:45
Nv
Definition: NvBlastArray.h:37