UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GenericPlatformTime.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "CoreTypes.h"
7#include "HAL/PlatformCrt.h"
8
9#if PLATFORM_HAS_BSD_TIME
10 #include <sys/time.h> // IWYU pragma: export
11#endif
12
13
16{
22
24 {
26 CPUTimePctRelative += Other.CPUTimePctRelative;
27 return *this;
28 }
29
32
36};
37
38
43{
44#if PLATFORM_HAS_BSD_TIME
53 static CORE_API double InitTiming();
54
55 static inline double Seconds()
56 {
57 struct timeval tv;
58 gettimeofday( &tv, NULL );
59 return ((double) tv.tv_sec) + (((double) tv.tv_usec) / 1000000.0);
60 }
61
62 static inline uint32 Cycles()
63 {
64 struct timeval tv;
65 gettimeofday( &tv, NULL );
66 return (uint32) ((((uint64)tv.tv_sec) * 1000000ULL) + (((uint64)tv.tv_usec)));
67 }
68 static inline uint64 Cycles64()
69 {
70 struct timeval tv;
71 gettimeofday( &tv, NULL );
72 return ((((uint64)tv.tv_sec) * 1000000ULL) + (((uint64)tv.tv_usec)));
73 }
74
76 static CORE_API void SystemTime( int32& Year, int32& Month, int32& DayOfWeek, int32& Day, int32& Hour, int32& Min, int32& Sec, int32& MSec );
77
79 static CORE_API void UtcTime( int32& Year, int32& Month, int32& DayOfWeek, int32& Day, int32& Hour, int32& Min, int32& Sec, int32& MSec );
80#endif
81
89 static CORE_API TCHAR* StrDate( TCHAR* Dest, SIZE_T DestSize );
97 static CORE_API TCHAR* StrTime( TCHAR* Dest, SIZE_T DestSize );
98
105 static CORE_API const TCHAR* StrTimestamp();
106
113 static CORE_API FString PrettyTime( double Seconds );
114
116 static bool UpdateCPUTime( float DeltaTime )
117 {
118 return false;
119 }
120
122 static bool UpdateThreadCPUTime(float = 0.0)
123 {
124 return false;
125 }
126
128 static void AutoUpdateGameThreadCPUTime(double UpdateInterval)
129 {
130 }
131
136 {
137 return FCPUTime( 0.0f, 0.0f );
138 }
139
146 {
147 return FCPUTime(0.0f, 0.0f);
148 }
149
154 {
156 }
157
164 {
165 return 0.0;
166 }
167
177 static double GetSecondsPerCycle()
178 {
179 return SecondsPerCycle;
180 }
181
183 static float ToMilliseconds( const uint32 Cycles )
184 {
185 return (float)double( SecondsPerCycle * 1000.0 * Cycles );
186 }
187
189 static float ToSeconds( const uint32 Cycles )
190 {
191 return (float)double( SecondsPerCycle * Cycles );
192 }
193
194
196 static double GetSecondsPerCycle64()
197 {
198 return SecondsPerCycle64;
199 }
200
202 static double ToMilliseconds64(const uint64 Cycles)
203 {
204 return ToSeconds64(Cycles) * 1000.0;
205 }
206
208 static double ToSeconds64(const uint64 Cycles)
209 {
210 return GetSecondsPerCycle64() * double(Cycles);
211 }
212
215 {
216 return static_cast<uint64>(Seconds / GetSecondsPerCycle64());
217 }
218
219protected:
220
224};
#define NULL
Definition oodle2base.h:134
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition GenericPlatformTime.h:16
float CPUTimePct
Definition GenericPlatformTime.h:31
FCPUTime & operator+=(const FCPUTime &Other)
Definition GenericPlatformTime.h:23
FCPUTime(float InCPUTimePct, float InCPUTimePctRelative)
Definition GenericPlatformTime.h:18
float CPUTimePctRelative
Definition GenericPlatformTime.h:35
Definition GenericPlatformTime.h:43
static float ToSeconds(const uint32 Cycles)
Definition GenericPlatformTime.h:189
static bool UpdateThreadCPUTime(float=0.0)
Definition GenericPlatformTime.h:122
static double ToSeconds64(const uint64 Cycles)
Definition GenericPlatformTime.h:208
static void AutoUpdateGameThreadCPUTime(double UpdateInterval)
Definition GenericPlatformTime.h:128
static CORE_API double SecondsPerCycle
Definition GenericPlatformTime.h:221
static bool UpdateCPUTime(float DeltaTime)
Definition GenericPlatformTime.h:116
static CORE_API FString PrettyTime(double Seconds)
Definition GenericPlatformTime.cpp:121
static double GetSecondsPerCycle64()
Definition GenericPlatformTime.h:196
static double GetSecondsPerCycle()
Definition GenericPlatformTime.h:177
static CORE_API double LastIntervalCPUTimeInSeconds
Definition GenericPlatformTime.h:223
static CORE_API double SecondsPerCycle64
Definition GenericPlatformTime.h:222
static CORE_API TCHAR * StrDate(TCHAR *Dest, SIZE_T DestSize)
Definition GenericPlatformTime.cpp:74
static FCPUTime GetThreadCPUTime()
Definition GenericPlatformTime.h:145
static CORE_API TCHAR * StrTime(TCHAR *Dest, SIZE_T DestSize)
Definition GenericPlatformTime.cpp:90
static double ToMilliseconds64(const uint64 Cycles)
Definition GenericPlatformTime.h:202
static FCPUTime GetCPUTime()
Definition GenericPlatformTime.h:135
static double GetLastIntervalThreadCPUTimeInSeconds()
Definition GenericPlatformTime.h:163
static CORE_API const TCHAR * StrTimestamp()
Definition GenericPlatformTime.cpp:106
static uint64 SecondsToCycles64(double Seconds)
Definition GenericPlatformTime.h:214
static float ToMilliseconds(const uint32 Cycles)
Definition GenericPlatformTime.h:183
static double GetLastIntervalCPUTimeInSeconds()
Definition GenericPlatformTime.h:153