Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
GenericPlatformTime.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/UnrealString.h"
6#include "CoreTypes.h"
7#include "HAL/PlatformCrt.h"
8
10 #include <sys/time.h> // IWYU pragma: export
11#endif
12
13
14/** Contains CPU utilization data. */
16{
17 /** Initialization constructor. */
18 FCPUTime( float InCPUTimePct, float InCPUTimePctRelative )
19 : CPUTimePct( InCPUTimePct )
20 , CPUTimePctRelative( InCPUTimePctRelative )
21 {}
22
23 FCPUTime& operator+=( const FCPUTime& Other )
24 {
25 CPUTimePct += Other.CPUTimePct;
27 return *this;
28 }
29
30 /** Percentage CPU utilization for the last interval. */
32
33 /** Percentage CPU utilization for the last interval relative to one core,
34 ** so if CPUTimePct is 8.0% and you have 6 core this value will be 48.0%. */
36};
37
38
39/**
40* Generic implementation for most platforms
41**/
43{
45 /**
46 * Does per platform initialization of timing information and returns the current time. This function is
47 * called before the execution of main as GStartTime is statically initialized by it. The function also
48 * internally sets SecondsPerCycle, which is safe to do as static initialization order enforces complex
49 * initialization after the initial 0 initialization of the value.
50 *
51 * @return current time
52 */
53 static double InitTiming();
54
55 static FORCEINLINE 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
63 {
64 struct timeval tv;
65 gettimeofday( &tv, NULL );
66 return (uint32) ((((uint64)tv.tv_sec) * 1000000ULL) + (((uint64)tv.tv_usec)));
67 }
69 {
70 struct timeval tv;
71 gettimeofday( &tv, NULL );
72 return ((((uint64)tv.tv_sec) * 1000000ULL) + (((uint64)tv.tv_usec)));
73 }
74
75 /** Returns the system time. */
77
78 /** Returns the UTC time. */
80#endif
81
82 /**
83 * Get the system date
84 *
85 * @param Dest Destination buffer to copy to
86 * @param DestSize Size of destination buffer in characters
87 * @return Date string
88 */
89 static TCHAR* StrDate( TCHAR* Dest, SIZE_T DestSize );
90 /**
91 * Get the system time
92 *
93 * @param Dest Destination buffer to copy to
94 * @param DestSize Size of destination buffer in characters
95 * @return Time string
96 */
97 static TCHAR* StrTime( TCHAR* Dest, SIZE_T DestSize );
98
99 /**
100 * Returns a timestamp string built from the current date and time.
101 * NOTE: Only one return value is valid at a time!
102 *
103 * @return timestamp string
104 */
105 static const TCHAR* StrTimestamp();
106
107 /**
108 * Returns a pretty-string for a time given in seconds. (I.e. "4:31 min", "2:16:30 hours", etc)
109 *
110 * @param Seconds Time in seconds
111 * @return Time in a pretty formatted string
112 */
113 static FString PrettyTime( double Seconds );
114
115 /** Updates CPU utilization, called through a delegate from the Core ticker. */
116 static bool UpdateCPUTime( float DeltaTime )
117 {
118 return false;
119 }
120
121 /** Updates current thread CPU utilization, calling is user defined per-thread (unused float parameter, is for FTicker compatibility). */
122 static bool UpdateThreadCPUTime(float = 0.0)
123 {
124 return false;
125 }
126
127 /** Registers automatic updates of Game Thread CPU utilization */
128 static void AutoUpdateGameThreadCPUTime(double UpdateInterval)
129 {
130 }
131
132 /**
133 * @return structure that contains CPU utilization data.
134 */
136 {
137 return FCPUTime( 0.0f, 0.0f );
138 }
139
140 /**
141 * Gets current threads CPU Utilization
142 *
143 * @return Current threads CPU Utilization
144 */
146 {
147 return FCPUTime(0.0f, 0.0f);
148 }
149
150 /**
151 * @return the cpu processing time (kernel + user time of all threads) from the last update
152 */
154 {
156 }
157
158 /**
159 * Gets the per-thread CPU processing time (kernel + user) from the last update
160 *
161 * @return The per-thread CPU processing time from the last update
162 */
164 {
165 return 0.0;
166 }
167
168 /**
169 * @return seconds per cycle.
170 */
171 static double GetSecondsPerCycle()
172 {
173 return SecondsPerCycle;
174 }
175 /** Converts cycles to milliseconds. */
176 static float ToMilliseconds( const uint32 Cycles )
177 {
178 return (float)double( SecondsPerCycle * 1000.0 * Cycles );
179 }
180
181 /** Converts cycles to seconds. */
182 static float ToSeconds( const uint32 Cycles )
183 {
184 return (float)double( SecondsPerCycle * Cycles );
185 }
186 /**
187 * @return seconds per cycle.
188 */
189 static double GetSecondsPerCycle64();
190 /** Converts cycles to milliseconds. */
191 static double ToMilliseconds64(const uint64 Cycles)
192 {
193 return ToSeconds64(Cycles) * 1000.0;
194 }
195
196 /** Converts cycles to seconds. */
197 static double ToSeconds64(const uint64 Cycles)
198 {
199 return GetSecondsPerCycle64() * double(Cycles);
200 }
201
202protected:
203
204 static double SecondsPerCycle;
205 static double SecondsPerCycle64;
207};
#define PLATFORM_HAS_BSD_TIME
Definition Platform.h:271
FCPUTime & operator+=(const FCPUTime &Other)
FCPUTime(float InCPUTimePct, float InCPUTimePctRelative)
float CPUTimePctRelative
static float ToSeconds(const uint32 Cycles)
static bool UpdateThreadCPUTime(float=0.0)
static double ToSeconds64(const uint64 Cycles)
static void AutoUpdateGameThreadCPUTime(double UpdateInterval)
static FString PrettyTime(double Seconds)
static bool UpdateCPUTime(float DeltaTime)
static double GetSecondsPerCycle64()
static double GetSecondsPerCycle()
static const TCHAR * StrTimestamp()
static double LastIntervalCPUTimeInSeconds
static FCPUTime GetThreadCPUTime()
static double ToMilliseconds64(const uint64 Cycles)
static FCPUTime GetCPUTime()
static TCHAR * StrTime(TCHAR *Dest, SIZE_T DestSize)
static double GetLastIntervalThreadCPUTimeInSeconds()
static float ToMilliseconds(const uint32 Cycles)
static TCHAR * StrDate(TCHAR *Dest, SIZE_T DestSize)
static double GetLastIntervalCPUTimeInSeconds()