919{
922
923
924
925
927 {
929
940 }
941
942
943
944
946 {
948 }
949
950
951
952
953
955 {
959 {
962 }
963
965 }
966
967
968
970 {
974 {
977 }
978
980 }
981
982
983
985 {
987
989 {
992
994 {
997 }
998
1000 {
1003
1005 {
1008 }
1009 }
1010 }
1011
1012
1016 if (!
Assert(bogusFlags == 0))
1017 {
1020 }
1021
1024 if (!
Assert(bogusFlags == 0))
1025 {
1028 }
1029
1030
1033 }
1034
1035
1036
1038 {
1040
1042
1044 {
1047 }
1048
1051
1053 {
1056 }
1057
1060
1062 {
1065 }
1066
1067
1070 }
1071
1072
1073
1075 {
1077
1079
1080
1082 {
1085 }
1086
1088 {
1091 }
1092
1094 {
1097 }
1098
1099
1102 }
1103
1104
1105
1107 {
1108
1110
1111
1112 string nameOfCurrentModule =
Type().GetModule();
1113 if (!
Assert(nameOfCurrentModule !=
""))
1114 {
1116 }
1117
1118
1121 {
1123 }
1124
1125 if (!
Assert(currentModule == eptModule))
1126 {
1128 }
1129
1130
1133
1135 {
1138 }
1139
1140
1143
1144
1145
1147
1148
1151
1152
1154 float timeSlept =
Sleep(0.3);
1156 float diff = postTime - previousTime - timeSlept;
1157
1158
1160
1161
1162 if (!
Assert(postTime > 0))
1163 {
1165
1166 if (!wasEnabled)
1168
1170
1172 }
1173
1174 if (!
Assert(diff < 0.00001))
1175 {
1177
1178 if (!wasEnabled)
1180
1182
1184 }
1185
1186
1188
1189
1190 for (int i = 0; i < 1000; ++i)
1191 {
1193 }
1194
1195
1199
1200 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1201
1202 int funcCount = timePerFunc.Count();
1203 for (int j = 0; j < funcCount; ++j)
1204 {
1206 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1207
1208 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1209 {
1211
1212 if (!wasEnabled)
1214
1216
1218 }
1219 }
1220
1223
1224 int classCount = timePerClass.Count();
1225 for (int k = 0; k < classCount; ++k)
1226 {
1227 typename type = timePerClass[k].param2;
1230 {
1232
1233 if (!wasEnabled)
1235
1237
1239 }
1240
1241
1242 if (!
Assert(classModule == eptModule))
1243 {
1245
1246 if (!wasEnabled)
1248
1250
1252 }
1253 }
1254
1255
1258 timePerFunc.Clear();
1260
1261 bool found = false;
1262
1263 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1264
1265 funcCount = timePerFunc.Count();
1266 for (int l = 0; l < funcCount; ++l)
1267 {
1269 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1270
1271 if (tfpc.param2 == "EnumTools::StringToEnum")
1272 {
1273 found = true;
1274 break;
1275 }
1276 }
1277
1279
1280
1286
1289
1290 if (!wasEnabled)
1292
1293 return BTFR(success && found);
1294 }
1295
1296
1297
1299 {
1300
1303
1304
1306
1307
1308 EPTHelperClass clss = new EPTHelperClass();
1309
1310
1312 float timeStressed = clss.DoEverything();
1315 float timeProfiled = postTime - previousTime;
1316 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1317
1318 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1319
1320
1322 if (!wasEnabled)
1324
1325
1326 if (!
Assert(postTime > 0))
1327 {
1329 }
1330
1331 if (!
Assert(postTime == postTimeStatic))
1332 {
1334 }
1335
1336 if (!
Assert(diff < 0.001))
1337 {
1339 }
1340
1342 }
1343
1344
1345
1347 {
1348 const int allocAmount = 9;
1349 const int releaseAmount = 6;
1350 int remainingAmount = allocAmount - releaseAmount;
1351
1352
1354
1355
1358
1360 for (int i = 0; i < allocAmount; ++i)
1361 {
1362 instanceArr.Insert(new EPTHelperClass());
1363 }
1364
1365 for (int j = 0; j < releaseAmount; ++j)
1366 {
1367 delete instanceArr[j];
1368 }
1369
1372
1373 int alloced = postAlloc - previousAlloc;
1374 int instances = postInstances - previousInstances;
1375
1376 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1377
1378
1379 if (!wasEnabled)
1381
1382
1383 if (!
Assert(alloced == allocAmount))
1384 {
1386 }
1387
1388 if (!
Assert(instances == remainingAmount))
1389 {
1391 }
1392
1394 }
1395
1396
1397
1399 {
1400
1403
1404
1406
1407
1411 float timeProfiled = postTime - previousTime;
1412 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1413
1417 float timeProfiled2 = postTime2 - previousTime2;
1418 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1419
1420 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1421
1422
1424 if (!wasEnabled)
1425 {
1427 }
1428
1429
1430 if (!
Assert(postTime > 0))
1431 {
1433 }
1434
1435 if (!
Assert(diff < 0.001))
1436 {
1438 }
1439
1440 if (!
Assert(postTime2 > 0))
1441 {
1443 }
1444
1445 if (!
Assert(diff2 < 0.001))
1446 {
1448 }
1449
1450
1451 if (!
Assert(timeProfiled < timeProfiled2))
1452 {
1454 }
1455
1457 }
1458
1459
1460
1462 {
1463
1465
1466
1467
1468
1472
1473 int callCountCF = postCountCF - previousCountCF;
1474
1475
1479
1480 int callCountCFP = postCountCFP - previousCountCFP;
1481
1482
1486
1487 int callCountRG = postCountRG - previousCountRG;
1488
1489
1493
1494 int callCountC = postCountC - previousCountC;
1495
1496
1498
1499
1503
1504 int callCountS = postCountS - previousCountS;
1505
1506
1510
1511 int callCountG = postCountG - previousCountG;
1512
1513
1514
1517
1518
1519
1521
1522
1523
1526
1527
1528
1531
1532
1533
1536
1537
1538 if (!wasEnabled)
1539 {
1541 }
1542
1543
1544
1545
1546 if (!
Assert(callCountCF == 1))
1547 {
1549 }
1550
1551
1552 if (!
Assert(callCountCFP == 1))
1553 {
1555 }
1556
1557
1558 if (!
Assert(callCountRG == 1))
1559 {
1561 }
1562
1563
1564 if (!
Assert(callCountC == 1))
1565 {
1567 }
1568
1569
1570 if (!
Assert(callCountNon == -1))
1571 {
1573 }
1574
1575
1576 if (!
Assert(callCountS == 1))
1577 {
1579 }
1580
1581
1582 if (!
Assert(callCountG == 1))
1583 {
1585 }
1586
1587
1588 if (!
Assert(callCountGP == 0))
1589 {
1591 }
1592
1593
1594 if (!
Assert(callCountSP == 0))
1595 {
1597 }
1598
1599
1600 if (!
Assert(callCountP == 0))
1601 {
1603 }
1604
1605
1606 if (!
Assert(callCountPN == 0))
1607 {
1609 }
1610
1611
1612 if (!
Assert(callCountSPN == 0))
1613 {
1615 }
1616
1618 }
1619
1620
1621
1622
1623
1624 float Sleep(
float timeS)
1625 {
1627 while (
GetGame().GetTickTime() - startTime < timeS)
1628 {
1629
1630 }
1631
1633 }
1634
1635
1636
1638 {
1640
1641 for (int i = 0; i < 1000; ++i)
1642 {
1643 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
1644 }
1645
1647 }
1648
1649
1650
1652 {
1654
1655 for (int i = 0; i < 1000; ++i)
1656 {
1657 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
1658 }
1659
1661 }
1662
1663
1664
1666 {
1667 int dummy = 3;
1668 }
1669
1670
1671
1673 {
1674 int dummy = 3;
1675 }
1676}
1677
1678class EPTHelperClass
1679{
1680 float Sleep2(
float timeS)
1681 {
1683 while (
GetGame().GetTickTime() - startTime < timeS)
1684 {
1685
1686 }
1687
1689 }
1691 {
1693 while (
GetGame().GetTickTime() - startTime < timeS)
1694 {
1695
1696 }
1697
1699 }
1700
1702 {
1704
1707
1709 }
1710}
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.