951{
954
955
956
957
959 {
961
972 }
973
974
975
976
978 {
980 }
981
982
983
984
985
987 {
991 {
994 }
995
997 }
998
999
1000
1002 {
1006 {
1009 }
1010
1012 }
1013
1014
1015
1017 {
1019
1021 {
1024
1026 {
1029 }
1030
1032 {
1035
1037 {
1040 }
1041 }
1042 }
1043
1044
1048 if (!
Assert(bogusFlags == 0))
1049 {
1052 }
1053
1056 if (!
Assert(bogusFlags == 0))
1057 {
1060 }
1061
1062
1065 }
1066
1067
1068
1070 {
1072
1074
1076 {
1079 }
1080
1083
1085 {
1088 }
1089
1092
1094 {
1097 }
1098
1099
1102 }
1103
1104
1105
1107 {
1109
1111
1112
1114 {
1117 }
1118
1120 {
1123 }
1124
1126 {
1129 }
1130
1131
1134 }
1135
1136
1137
1139 {
1140
1142
1143
1144 string nameOfCurrentModule =
Type().GetModule();
1145 if (!
Assert(nameOfCurrentModule !=
""))
1146 {
1148 }
1149
1150
1153 {
1155 }
1156
1157 if (!
Assert(currentModule == eptModule))
1158 {
1160 }
1161
1162
1165
1167 {
1170 }
1171
1172
1175
1176
1177
1179
1180
1183
1184
1186 float timeSlept =
Sleep(0.3);
1188 float diff = postTime - previousTime - timeSlept;
1189
1190
1192
1193
1194 if (!
Assert(postTime > 0))
1195 {
1197
1198 if (!wasEnabled)
1200
1202
1204 }
1205
1206 if (!
Assert(diff < 0.00001))
1207 {
1209
1210 if (!wasEnabled)
1212
1214
1216 }
1217
1218
1220
1221
1222 for (int i = 0; i < 1000; ++i)
1223 {
1225 }
1226
1227
1231
1232 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1233
1234 int funcCount = timePerFunc.Count();
1235 for (int j = 0; j < funcCount; ++j)
1236 {
1238 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1239
1240 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1241 {
1243
1244 if (!wasEnabled)
1246
1248
1250 }
1251 }
1252
1255
1256 int classCount = timePerClass.Count();
1257 for (int k = 0; k < classCount; ++k)
1258 {
1259 typename type = timePerClass[k].param2;
1262 {
1264
1265 if (!wasEnabled)
1267
1269
1271 }
1272
1273
1274 if (!
Assert(classModule == eptModule))
1275 {
1277
1278 if (!wasEnabled)
1280
1282
1284 }
1285 }
1286
1287
1290 timePerFunc.Clear();
1292
1293 bool found = false;
1294
1295 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1296
1297 funcCount = timePerFunc.Count();
1298 for (int l = 0; l < funcCount; ++l)
1299 {
1301 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1302
1303 if (tfpc.param2 == "EnumTools::StringToEnum")
1304 {
1305 found = true;
1306 break;
1307 }
1308 }
1309
1311
1312
1318
1321
1322 if (!wasEnabled)
1324
1325 return BTFR(success && found);
1326 }
1327
1328
1329
1331 {
1332
1335
1336
1338
1339
1340 EPTHelperClass clss = new EPTHelperClass();
1341
1342
1344 float timeStressed = clss.DoEverything();
1347 float timeProfiled = postTime - previousTime;
1348 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1349
1350 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1351
1352
1354 if (!wasEnabled)
1356
1357
1358 if (!
Assert(postTime > 0))
1359 {
1361 }
1362
1363 if (!
Assert(postTime == postTimeStatic))
1364 {
1366 }
1367
1368 if (!
Assert(diff < 0.001))
1369 {
1371 }
1372
1374 }
1375
1376
1377
1379 {
1380 const int allocAmount = 9;
1381 const int releaseAmount = 6;
1382 int remainingAmount = allocAmount - releaseAmount;
1383
1384
1386
1387
1390
1392 for (int i = 0; i < allocAmount; ++i)
1393 {
1394 instanceArr.Insert(new EPTHelperClass());
1395 }
1396
1397 for (int j = 0; j < releaseAmount; ++j)
1398 {
1399 delete instanceArr[j];
1400 }
1401
1404
1405 int alloced = postAlloc - previousAlloc;
1406 int instances = postInstances - previousInstances;
1407
1408 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1409
1410
1411 if (!wasEnabled)
1413
1414
1415 if (!
Assert(alloced == allocAmount))
1416 {
1418 }
1419
1420 if (!
Assert(instances == remainingAmount))
1421 {
1423 }
1424
1426 }
1427
1428
1429
1431 {
1432
1435
1436
1438
1439
1443 float timeProfiled = postTime - previousTime;
1444 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1445
1449 float timeProfiled2 = postTime2 - previousTime2;
1450 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1451
1452 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1453
1454
1456 if (!wasEnabled)
1457 {
1459 }
1460
1461
1462 if (!
Assert(postTime > 0))
1463 {
1465 }
1466
1467 if (!
Assert(diff < 0.001))
1468 {
1470 }
1471
1472 if (!
Assert(postTime2 > 0))
1473 {
1475 }
1476
1477 if (!
Assert(diff2 < 0.001))
1478 {
1480 }
1481
1482
1483 if (!
Assert(timeProfiled < timeProfiled2))
1484 {
1486 }
1487
1489 }
1490
1491
1492
1494 {
1495
1497
1498
1499
1500
1504
1505 int callCountCF = postCountCF - previousCountCF;
1506
1507
1511
1512 int callCountCFP = postCountCFP - previousCountCFP;
1513
1514
1518
1519 int callCountRG = postCountRG - previousCountRG;
1520
1521
1525
1526 int callCountC = postCountC - previousCountC;
1527
1528
1530
1531
1535
1536 int callCountS = postCountS - previousCountS;
1537
1538
1542
1543 int callCountG = postCountG - previousCountG;
1544
1545
1546
1549
1550
1551
1553
1554
1555
1558
1559
1560
1563
1564
1565
1568
1569
1570 if (!wasEnabled)
1571 {
1573 }
1574
1575
1576
1577
1578 if (!
Assert(callCountCF == 1))
1579 {
1581 }
1582
1583
1584 if (!
Assert(callCountCFP == 1))
1585 {
1587 }
1588
1589
1590 if (!
Assert(callCountRG == 1))
1591 {
1593 }
1594
1595
1596 if (!
Assert(callCountC == 1))
1597 {
1599 }
1600
1601
1602 if (!
Assert(callCountNon == -1))
1603 {
1605 }
1606
1607
1608 if (!
Assert(callCountS == 1))
1609 {
1611 }
1612
1613
1614 if (!
Assert(callCountG == 1))
1615 {
1617 }
1618
1619
1620 if (!
Assert(callCountGP == 0))
1621 {
1623 }
1624
1625
1626 if (!
Assert(callCountSP == 0))
1627 {
1629 }
1630
1631
1632 if (!
Assert(callCountP == 0))
1633 {
1635 }
1636
1637
1638 if (!
Assert(callCountPN == 0))
1639 {
1641 }
1642
1643
1644 if (!
Assert(callCountSPN == 0))
1645 {
1647 }
1648
1650 }
1651
1652
1653
1654
1655
1656 float Sleep(
float timeS)
1657 {
1659 while (
GetGame().GetTickTime() - startTime < timeS)
1660 {
1661
1662 }
1663
1665 }
1666
1667
1668
1670 {
1672
1673 for (int i = 0; i < 1000; ++i)
1674 {
1675 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
1676 }
1677
1679 }
1680
1681
1682
1684 {
1686
1687 for (int i = 0; i < 1000; ++i)
1688 {
1689 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
1690 }
1691
1693 }
1694
1695
1696
1698 {
1699 int dummy = 3;
1700 }
1701
1702
1703
1705 {
1706 int dummy = 3;
1707 }
1708}
1709
1710class EPTHelperClass
1711{
1712 float Sleep2(
float timeS)
1713 {
1715 while (
GetGame().GetTickTime() - startTime < timeS)
1716 {
1717
1718 }
1719
1721 }
1723 {
1725 while (
GetGame().GetTickTime() - startTime < timeS)
1726 {
1727
1728 }
1729
1731 }
1732
1734 {
1736
1739
1741 }
1742}
float SleepAgain(float timeS)
void TestFuncCountDataHelper()
TFResult TestClearFlags()
TFResult TestTogglingImmediate()
TFResult TestFuncCountData()
EnProfilerTests TestFramework Sleep2(float timeS)
TFResult TestClassTimeData()
static void TestFuncCountDataHelperStatic()
TFResult TestClassCountData()
bool m_bWasProfilerEnabled
Remember this, so we can restore the previous state before the test!
TFResult TestFuncTimeData()
TFResult NTFR(TFR result)
bool Assert(bool condition)
void TFResult(TFR result)
void AddInitTest(string test)
TFResult BTFR(bool result)
proto native float GetTickTime()
Returns current time from start of the game.
proto owned string GetHostName()
Gets the server name. (from client)
proto native bool IsServer()
static void TFLog(string message=LOG_DEFAULT, TestFramework caller=null, string function="")
Set of methods for accessing script profiling data.
static proto native ErrorModuleHandler GetInstance()
Gets the EMH Instance.
The error handler itself, for managing and distributing errors to modules Manages the ErrorHandlerMod...
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
proto volatile int CallFunctionParams(Class inst, string function, out void returnVal, Class parms)
proto volatile int Call(Class inst, string function, void parm)
proto volatile int CallFunction(Class inst, string function, out void returnVal, void parm)
static proto float AbsFloat(float f)
Returns absolute value.
static proto int GetTimeResolution()
Get the currently set time resolution.
static proto EnProfilerModule GetModule()
Get the currently profiled module.
static proto void GetTimePerFunc(notnull out array< ref EnProfilerTimeFuncPair > outArr, int count=int.MAX)
Obtain [SD] for Time Per Function.
Param2< float, string > EnProfilerTimeFuncPair
static proto int GetAllocationsOfClass(typename clss, bool immediate=false)
Obtain [SD] or [PD] regarding the allocations of a specific class.
static proto float GetTimeOfClass(typename clss, bool immediate=false)
Obtain [SD] or [PD] regarding the time a specific class consumed.
static proto int GetCountOfFunc(string funct, typename clss, bool immediate=false)
Obtain [SD] or [PD] regarding the amount of times a specific function was called.
static proto int GetFlags()
Get the currently used flags across the API.
static proto int ClearFlags(bool sessionReset=true)
Remove all flags from the currently used set of EnProfilerFlags across the API.
static proto float GetTimeOfFunc(string funct, typename clss, bool immediate=false)
Obtain [SD] or [PD] regarding the time consumed by a specific function.
static proto void SetTimeResolution(int resolution)
Set the resolution of the fetched Time data.
static proto void SortData()
The internal sorting that happens at the end of the frame (so it is NOT necessary to call this manual...
static proto void SetModule(EnProfilerModule module, bool sessionReset=true)
Set the module to be profiled.
static proto void ResetSession(bool fullReset=false)
Perform [SR], clearing SessionFrame, ProfiledSessionFrames, [SD] and [PD] (except for [CI])
static bool IsEnabledP()
Return if script profiling is enabled through EnProfiler.
static bool IsEnabledC()
Return if script profiling is actually turned on inside of the script context.
static proto int GetInstancesOfClass(typename clss, bool immediate=false)
Obtain [SD] or [PD] regarding the [CI] of a specific class.
EnProfilerFlags
Flags that influences the behaviour of the EnProfiler API, applied through ...Flags functions.
static proto void GetTimePerClass(notnull out array< ref EnProfilerTimeClassPair > outArr, int count=int.MAX)
Obtain [SD] for Time Per Class.
static proto int SetFlags(int flags, bool sessionReset=true)
Override the currently used set of EnProfilerFlags across the API.
static proto void Enable(bool enable, bool immediate=false, bool sessionReset=true)
Enable the gathering of script profiling data.
EnProfilerModule
Current base scripted modules.
static proto bool NameToModule(string moduleName, out EnProfilerModule module)
Convert string to EnProfilerModule.
static bool RequestImmediateData()
Helper method to ascertain the profiler will record [PD] right after this call.
static proto int RemoveFlags(int flags, bool sessionReset=true)
Remove flags from the currently used set of EnProfilerFlags across the API.
static proto int GetCountOfFuncG(string funct, bool immediate=false)
Obtain [SD] or [PD] regarding the amount of times a specific function was called.
static proto int AddFlags(int flags, bool sessionReset=true)
Add flags to the currently used set of EnProfilerFlags across the API.