DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ TestModule()

TFResult EnProfilerTests::TestModule ( )
inlineprivate

См. определение в файле EnProfilerTests.c строка 189

190 {
191 // File lives in Game, use it while testing
192 const EnProfilerModule eptModule = EnProfilerModule.GAME;
193
194 // This was added at the same time as this API, so check if it works as well
195 string nameOfCurrentModule = Type().GetModule();
196 if (!Assert(nameOfCurrentModule != ""))
197 {
198 return NTFR(TFR.FAIL);
199 }
200
201 // We know we are in Game, so use it as a test
202 EnProfilerModule currentModule;
203 if (!Assert(EnProfiler.NameToModule(nameOfCurrentModule, currentModule)))
204 {
205 return NTFR(TFR.FAIL);
206 }
207
208 if (!Assert(currentModule == eptModule))
209 {
210 return NTFR(TFR.FAIL);
211 }
212
213 // Test if setting and getting works
214 EnProfilerModule currentlyProfiledModule = EnProfiler.GetModule();
215 EnProfiler.SetModule(eptModule);
216
217 if (!Assert(EnProfiler.GetModule() == eptModule))
218 {
219 EnProfiler.SetModule(currentlyProfiledModule);
220 return NTFR(TFR.FAIL);
221 }
222
223 // Data to restore
224 int currentFlags = EnProfiler.GetFlags();
225 bool wasEnabled = EnProfiler.RequestImmediateData();
226
227 // Make sure we are only profiling Game and that the data is clean
228 // Only valid for the Get...Per... methods, as they need to be sorted
229 EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE);
230
231 // GetTickTime() returns in seconds, so gather the results in seconds too
232 int resolution = EnProfiler.GetTimeResolution();
233 EnProfiler.SetTimeResolution(1);
234
235 // Time to sleeb
236 float previousTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
237 float timeSlept = Sleep(0.3);
238 float postTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
239 float diff = postTime - previousTime - timeSlept;
240
241 // Restore
242 EnProfiler.SetTimeResolution(resolution);
243
244 // We called the function, so it must have some time
245 if (!Assert(postTime > 0))
246 {
247 EnProfiler.SetFlags(currentFlags);
248
249 if (!wasEnabled)
250 EnProfiler.Enable(false, true);
251
252 EnProfiler.SetModule(currentlyProfiledModule);
253
254 return NTFR(TFR.FAIL);
255 }
256
257 if (!Assert(diff < 0.00001))
258 {
259 EnProfiler.SetFlags(currentFlags);
260
261 if (!wasEnabled)
262 EnProfiler.Enable(false, true);
263
264 EnProfiler.SetModule(currentlyProfiledModule);
265
266 return NTFR(TFR.FAIL);
267 }
268
269 // Clean the session
270 EnProfiler.ResetSession(true);
271
272 // Something from a different module should not get sorted, so just fire something from a different module
273 for (int i = 0; i < 1000; ++i)
274 {
275 EnumTools.StringToEnum(EnProfilerModule, "MISSION_CUSTOM");
276 }
277
278 // Sort and gather the data and validate if it is correct
279 EnProfiler.SortData();
280 array<ref EnProfilerTimeFuncPair> timePerFunc = {};
281 EnProfiler.GetTimePerFunc(timePerFunc);
282
283 Debug.TFLog("Game fncs:", this, "TestModule");
284
285 int funcCount = timePerFunc.Count();
286 for (int j = 0; j < funcCount; ++j)
287 {
288 EnProfilerTimeFuncPair tfp = timePerFunc[j];
289 Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfp.param1, tfp.param2), this, "TestModule");
290 // We are currently profiling Game, so this Core function shouldn't be present
291 if (!Assert(tfp.param2 != "EnumTools::StringToEnum"))
292 {
293 EnProfiler.SetFlags(currentFlags);
294
295 if (!wasEnabled)
296 EnProfiler.Enable(false, true);
297
298 EnProfiler.SetModule(currentlyProfiledModule);
299
300 return NTFR(TFR.FAIL);
301 }
302 }
303
304 array<ref EnProfilerTimeClassPair> timePerClass = {};
305 EnProfiler.GetTimePerClass(timePerClass);
306
307 int classCount = timePerClass.Count();
308 for (int k = 0; k < classCount; ++k)
309 {
310 typename type = timePerClass[k].param2;
311 EnProfilerModule classModule;
312 if (!Assert(EnProfiler.NameToModule(type.GetModule(), classModule)))
313 {
314 EnProfiler.SetFlags(currentFlags);
315
316 if (!wasEnabled)
317 EnProfiler.Enable(false, true);
318
319 EnProfiler.SetModule(currentlyProfiledModule);
320
321 return NTFR(TFR.FAIL);
322 }
323
324 // Only classes from Game should be present
325 if (!Assert(classModule == eptModule))
326 {
327 EnProfiler.SetFlags(currentFlags);
328
329 if (!wasEnabled)
330 EnProfiler.Enable(false, true);
331
332 EnProfiler.SetModule(currentlyProfiledModule);
333
334 return NTFR(TFR.FAIL);
335 }
336 }
337
338 // Now let's check if we can gather the data of what we called earlier by switching the profiled module without resetting the session
339 EnProfiler.SetModule(EnProfilerModule.CORE, false);
340 EnProfiler.SortData();
341 timePerFunc.Clear(); // Let's reuse the array, but the Get...Per... methods only appends to the array, clearing is our responsibility
342 EnProfiler.GetTimePerFunc(timePerFunc);
343
344 bool found = false;
345
346 Debug.TFLog("Core fncs:", this, "TestModule");
347
348 funcCount = timePerFunc.Count();
349 for (int l = 0; l < funcCount; ++l)
350 {
351 EnProfilerTimeFuncPair tfpc = timePerFunc[l];
352 Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfpc.param1, tfpc.param2), this, "TestModule");
353 // We are currently profiling Core, so this Core function should be present
354 if (tfpc.param2 == "EnumTools::StringToEnum")
355 {
356 found = true;
357 break;
358 }
359 }
360
361 Assert(found);
362
363 // Test some bogus
364 EnProfilerModule mod = EnProfiler.GetModule();
365 EnProfiler.SetModule(-333);
366 bool success = Assert(EnProfiler.GetModule() == mod);
367 EnProfiler.SetModule(6003);
368 success &= Assert(EnProfiler.GetModule() == mod);
369
370 EnProfiler.SetFlags(currentFlags);
371 EnProfiler.SetModule(currentlyProfiledModule);
372
373 if (!wasEnabled)
374 EnProfiler.Enable(false, true);
375
376 return BTFR(success && found);
377 }
string Type
Определения JsonDataContaminatedArea.c:11
TFResult NTFR(TFR result)
Определения TestFramework.c:273
bool Assert(bool condition)
Определения TestFramework.c:262
TFR
Определения TestFramework.c:2
TFResult BTFR(bool result)
Определения TestFramework.c:278
void Debug()
Определения UniversalTemperatureSource.c:349
float Sleep(float timeS)
Определения EnProfilerTests.c:707
Param2< float, string > EnProfilerTimeFuncPair
Определения EnProfiler.c:58
EnProfilerFlags
Flags that influences the behaviour of the EnProfiler API, applied through ...Flags functions.
Определения EnProfiler.c:9
EnProfilerModule
Current base scripted modules.
Определения EnProfiler.c:22

Перекрестные ссылки Assert(), BTFR(), EnProfiler::Enable(), EnProfiler::GetFlags(), EnProfiler::GetModule(), EnProfiler::GetTimeOfFunc(), EnProfiler::GetTimePerClass(), EnProfiler::GetTimePerFunc(), EnProfiler::GetTimeResolution(), EnProfiler::NameToModule(), NTFR(), EnProfiler::RemoveFlags(), EnProfiler::RequestImmediateData(), EnProfiler::ResetSession(), EnProfiler::SetFlags(), EnProfiler::SetModule(), EnProfiler::SetTimeResolution(), Sleep(), EnProfiler::SortData(), EnumTools::StringToEnum(), Debug::TFLog(), TFResult() и Type.