882{
885
886
887
888
890 {
892
903 }
904
905
906
907
909 {
911 }
912
913
914
915
916
918 {
922 {
925 }
926
928 }
929
930
931
933 {
937 {
940 }
941
943 }
944
945
946
948 {
950
952 {
955
957 {
960 }
961
963 {
966
968 {
971 }
972 }
973 }
974
975
979 if (!
Assert(bogusFlags == 0))
980 {
983 }
984
987 if (!
Assert(bogusFlags == 0))
988 {
991 }
992
993
996 }
997
998
999
1001 {
1003
1005
1007 {
1010 }
1011
1014
1016 {
1019 }
1020
1023
1025 {
1028 }
1029
1030
1033 }
1034
1035
1036
1038 {
1040
1042
1043
1045 {
1048 }
1049
1051 {
1054 }
1055
1057 {
1060 }
1061
1062
1065 }
1066
1067
1068
1070 {
1071
1073
1074
1075 string nameOfCurrentModule =
Type().GetModule();
1076 if (!
Assert(nameOfCurrentModule !=
""))
1077 {
1079 }
1080
1081
1084 {
1086 }
1087
1088 if (!
Assert(currentModule == eptModule))
1089 {
1091 }
1092
1093
1096
1098 {
1101 }
1102
1103
1106
1107
1108
1110
1111
1114
1115
1117 float timeSlept =
Sleep(0.3);
1119 float diff = postTime - previousTime - timeSlept;
1120
1121
1123
1124
1125 if (!
Assert(postTime > 0))
1126 {
1128
1129 if (!wasEnabled)
1131
1133
1135 }
1136
1137 if (!
Assert(diff < 0.00001))
1138 {
1140
1141 if (!wasEnabled)
1143
1145
1147 }
1148
1149
1151
1152
1153 for (int i = 0; i < 1000; ++i)
1154 {
1156 }
1157
1158
1162
1163 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1164
1165 int funcCount = timePerFunc.Count();
1166 for (int j = 0; j < funcCount; ++j)
1167 {
1169 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1170
1171 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1172 {
1174
1175 if (!wasEnabled)
1177
1179
1181 }
1182 }
1183
1186
1187 int classCount = timePerClass.Count();
1188 for (int k = 0; k < classCount; ++k)
1189 {
1190 typename type = timePerClass[k].param2;
1193 {
1195
1196 if (!wasEnabled)
1198
1200
1202 }
1203
1204
1205 if (!
Assert(classModule == eptModule))
1206 {
1208
1209 if (!wasEnabled)
1211
1213
1215 }
1216 }
1217
1218
1221 timePerFunc.Clear();
1223
1224 bool found = false;
1225
1226 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1227
1228 funcCount = timePerFunc.Count();
1229 for (int l = 0; l < funcCount; ++l)
1230 {
1232 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1233
1234 if (tfpc.param2 == "EnumTools::StringToEnum")
1235 {
1236 found = true;
1237 break;
1238 }
1239 }
1240
1242
1243
1249
1252
1253 if (!wasEnabled)
1255
1256 return BTFR(success && found);
1257 }
1258
1259
1260
1262 {
1263
1266
1267
1269
1270
1271 EPTHelperClass clss = new EPTHelperClass();
1272
1273
1275 float timeStressed = clss.DoEverything();
1278 float timeProfiled = postTime - previousTime;
1279 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1280
1281 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1282
1283
1285 if (!wasEnabled)
1287
1288
1289 if (!
Assert(postTime > 0))
1290 {
1292 }
1293
1294 if (!
Assert(postTime == postTimeStatic))
1295 {
1297 }
1298
1299 if (!
Assert(diff < 0.001))
1300 {
1302 }
1303
1305 }
1306
1307
1308
1310 {
1311 const int allocAmount = 9;
1312 const int releaseAmount = 6;
1313 int remainingAmount = allocAmount - releaseAmount;
1314
1315
1317
1318
1321
1323 for (int i = 0; i < allocAmount; ++i)
1324 {
1325 instanceArr.Insert(new EPTHelperClass());
1326 }
1327
1328 for (int j = 0; j < releaseAmount; ++j)
1329 {
1330 delete instanceArr[j];
1331 }
1332
1335
1336 int alloced = postAlloc - previousAlloc;
1337 int instances = postInstances - previousInstances;
1338
1339 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1340
1341
1342 if (!wasEnabled)
1344
1345
1346 if (!
Assert(alloced == allocAmount))
1347 {
1349 }
1350
1351 if (!
Assert(instances == remainingAmount))
1352 {
1354 }
1355
1357 }
1358
1359
1360
1362 {
1363
1366
1367
1369
1370
1374 float timeProfiled = postTime - previousTime;
1375 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1376
1380 float timeProfiled2 = postTime2 - previousTime2;
1381 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1382
1383 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1384
1385
1387 if (!wasEnabled)
1388 {
1390 }
1391
1392
1393 if (!
Assert(postTime > 0))
1394 {
1396 }
1397
1398 if (!
Assert(diff < 0.001))
1399 {
1401 }
1402
1403 if (!
Assert(postTime2 > 0))
1404 {
1406 }
1407
1408 if (!
Assert(diff2 < 0.001))
1409 {
1411 }
1412
1413
1414 if (!
Assert(timeProfiled < timeProfiled2))
1415 {
1417 }
1418
1420 }
1421
1422
1423
1425 {
1426
1428
1429
1430
1431
1435
1436 int callCountCF = postCountCF - previousCountCF;
1437
1438
1442
1443 int callCountCFP = postCountCFP - previousCountCFP;
1444
1445
1449
1450 int callCountRG = postCountRG - previousCountRG;
1451
1452
1456
1457 int callCountC = postCountC - previousCountC;
1458
1459
1461
1462
1466
1467 int callCountS = postCountS - previousCountS;
1468
1469
1473
1474 int callCountG = postCountG - previousCountG;
1475
1476
1477
1480
1481
1482
1484
1485
1486
1489
1490
1491
1494
1495
1496
1499
1500
1501 if (!wasEnabled)
1502 {
1504 }
1505
1506
1507
1508
1509 if (!
Assert(callCountCF == 1))
1510 {
1512 }
1513
1514
1515 if (!
Assert(callCountCFP == 1))
1516 {
1518 }
1519
1520
1521 if (!
Assert(callCountRG == 1))
1522 {
1524 }
1525
1526
1527 if (!
Assert(callCountC == 1))
1528 {
1530 }
1531
1532
1533 if (!
Assert(callCountNon == -1))
1534 {
1536 }
1537
1538
1539 if (!
Assert(callCountS == 1))
1540 {
1542 }
1543
1544
1545 if (!
Assert(callCountG == 1))
1546 {
1548 }
1549
1550
1551 if (!
Assert(callCountGP == 0))
1552 {
1554 }
1555
1556
1557 if (!
Assert(callCountSP == 0))
1558 {
1560 }
1561
1562
1563 if (!
Assert(callCountP == 0))
1564 {
1566 }
1567
1568
1569 if (!
Assert(callCountPN == 0))
1570 {
1572 }
1573
1574
1575 if (!
Assert(callCountSPN == 0))
1576 {
1578 }
1579
1581 }
1582
1583
1584
1585
1586
1587 float Sleep(
float timeS)
1588 {
1590 while (
GetGame().GetTickTime() - startTime < timeS)
1591 {
1592
1593 }
1594
1596 }
1597
1598
1599
1601 {
1603
1604 for (int i = 0; i < 1000; ++i)
1605 {
1606 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
1607 }
1608
1610 }
1611
1612
1613
1615 {
1617
1618 for (int i = 0; i < 1000; ++i)
1619 {
1620 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
1621 }
1622
1624 }
1625
1626
1627
1629 {
1630 int dummy = 3;
1631 }
1632
1633
1634
1636 {
1637 int dummy = 3;
1638 }
1639}
1640
1641class EPTHelperClass
1642{
1643 float Sleep2(
float timeS)
1644 {
1646 while (
GetGame().GetTickTime() - startTime < timeS)
1647 {
1648
1649 }
1650
1652 }
1654 {
1656 while (
GetGame().GetTickTime() - startTime < timeS)
1657 {
1658
1659 }
1660
1662 }
1663
1665 {
1667
1670
1672 }
1673}
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.