814{
817
818
819
820
822 {
824
835 }
836
837
838
839
841 {
843 }
844
845
846
847
848
850 {
854 {
857 }
858
860 }
861
862
863
865 {
869 {
872 }
873
875 }
876
877
878
880 {
882
884 {
887
889 {
892 }
893
895 {
898
900 {
903 }
904 }
905 }
906
907
911 if (!
Assert(bogusFlags == 0))
912 {
915 }
916
919 if (!
Assert(bogusFlags == 0))
920 {
923 }
924
925
928 }
929
930
931
933 {
935
937
939 {
942 }
943
946
948 {
951 }
952
955
957 {
960 }
961
962
965 }
966
967
968
970 {
972
974
975
977 {
980 }
981
983 {
986 }
987
989 {
992 }
993
994
997 }
998
999
1000
1002 {
1003
1005
1006
1007 string nameOfCurrentModule =
Type().GetModule();
1008 if (!
Assert(nameOfCurrentModule !=
""))
1009 {
1011 }
1012
1013
1016 {
1018 }
1019
1020 if (!
Assert(currentModule == eptModule))
1021 {
1023 }
1024
1025
1028
1030 {
1033 }
1034
1035
1038
1039
1040
1042
1043
1046
1047
1049 float timeSlept =
Sleep(0.3);
1051 float diff = postTime - previousTime - timeSlept;
1052
1053
1055
1056
1057 if (!
Assert(postTime > 0))
1058 {
1060
1061 if (!wasEnabled)
1063
1065
1067 }
1068
1069 if (!
Assert(diff < 0.00001))
1070 {
1072
1073 if (!wasEnabled)
1075
1077
1079 }
1080
1081
1083
1084
1085 for (int i = 0; i < 1000; ++i)
1086 {
1088 }
1089
1090
1094
1095 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1096
1097 int funcCount = timePerFunc.Count();
1098 for (int j = 0; j < funcCount; ++j)
1099 {
1101 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1102
1103 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1104 {
1106
1107 if (!wasEnabled)
1109
1111
1113 }
1114 }
1115
1118
1119 int classCount = timePerClass.Count();
1120 for (int k = 0; k < classCount; ++k)
1121 {
1122 typename type = timePerClass[k].param2;
1125 {
1127
1128 if (!wasEnabled)
1130
1132
1134 }
1135
1136
1137 if (!
Assert(classModule == eptModule))
1138 {
1140
1141 if (!wasEnabled)
1143
1145
1147 }
1148 }
1149
1150
1153 timePerFunc.Clear();
1155
1156 bool found = false;
1157
1158 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1159
1160 funcCount = timePerFunc.Count();
1161 for (int l = 0; l < funcCount; ++l)
1162 {
1164 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1165
1166 if (tfpc.param2 == "EnumTools::StringToEnum")
1167 {
1168 found = true;
1169 break;
1170 }
1171 }
1172
1174
1175
1181
1184
1185 if (!wasEnabled)
1187
1188 return BTFR(success && found);
1189 }
1190
1191
1192
1194 {
1195
1198
1199
1201
1202
1203 EPTHelperClass clss = new EPTHelperClass();
1204
1205
1207 float timeStressed = clss.DoEverything();
1210 float timeProfiled = postTime - previousTime;
1211 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1212
1213 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1214
1215
1217 if (!wasEnabled)
1219
1220
1221 if (!
Assert(postTime > 0))
1222 {
1224 }
1225
1226 if (!
Assert(postTime == postTimeStatic))
1227 {
1229 }
1230
1231 if (!
Assert(diff < 0.001))
1232 {
1234 }
1235
1237 }
1238
1239
1240
1242 {
1243 const int allocAmount = 9;
1244 const int releaseAmount = 6;
1245 int remainingAmount = allocAmount - releaseAmount;
1246
1247
1249
1250
1253
1255 for (int i = 0; i < allocAmount; ++i)
1256 {
1257 instanceArr.Insert(new EPTHelperClass());
1258 }
1259
1260 for (int j = 0; j < releaseAmount; ++j)
1261 {
1262 delete instanceArr[j];
1263 }
1264
1267
1268 int alloced = postAlloc - previousAlloc;
1269 int instances = postInstances - previousInstances;
1270
1271 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1272
1273
1274 if (!wasEnabled)
1276
1277
1278 if (!
Assert(alloced == allocAmount))
1279 {
1281 }
1282
1283 if (!
Assert(instances == remainingAmount))
1284 {
1286 }
1287
1289 }
1290
1291
1292
1294 {
1295
1298
1299
1301
1302
1306 float timeProfiled = postTime - previousTime;
1307 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1308
1312 float timeProfiled2 = postTime2 - previousTime2;
1313 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1314
1315 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1316
1317
1319 if (!wasEnabled)
1320 {
1322 }
1323
1324
1325 if (!
Assert(postTime > 0))
1326 {
1328 }
1329
1330 if (!
Assert(diff < 0.001))
1331 {
1333 }
1334
1335 if (!
Assert(postTime2 > 0))
1336 {
1338 }
1339
1340 if (!
Assert(diff2 < 0.001))
1341 {
1343 }
1344
1345
1346 if (!
Assert(timeProfiled < timeProfiled2))
1347 {
1349 }
1350
1352 }
1353
1354
1355
1357 {
1358
1360
1361
1362
1363
1367
1368 int callCountCF = postCountCF - previousCountCF;
1369
1370
1374
1375 int callCountCFP = postCountCFP - previousCountCFP;
1376
1377
1381
1382 int callCountRG = postCountRG - previousCountRG;
1383
1384
1388
1389 int callCountC = postCountC - previousCountC;
1390
1391
1393
1394
1398
1399 int callCountS = postCountS - previousCountS;
1400
1401
1405
1406 int callCountG = postCountG - previousCountG;
1407
1408
1409
1412
1413
1414
1416
1417
1418
1421
1422
1423
1426
1427
1428
1431
1432
1433 if (!wasEnabled)
1434 {
1436 }
1437
1438
1439
1440
1441 if (!
Assert(callCountCF == 1))
1442 {
1444 }
1445
1446
1447 if (!
Assert(callCountCFP == 1))
1448 {
1450 }
1451
1452
1453 if (!
Assert(callCountRG == 1))
1454 {
1456 }
1457
1458
1459 if (!
Assert(callCountC == 1))
1460 {
1462 }
1463
1464
1465 if (!
Assert(callCountNon == -1))
1466 {
1468 }
1469
1470
1471 if (!
Assert(callCountS == 1))
1472 {
1474 }
1475
1476
1477 if (!
Assert(callCountG == 1))
1478 {
1480 }
1481
1482
1483 if (!
Assert(callCountGP == 0))
1484 {
1486 }
1487
1488
1489 if (!
Assert(callCountSP == 0))
1490 {
1492 }
1493
1494
1495 if (!
Assert(callCountP == 0))
1496 {
1498 }
1499
1500
1501 if (!
Assert(callCountPN == 0))
1502 {
1504 }
1505
1506
1507 if (!
Assert(callCountSPN == 0))
1508 {
1510 }
1511
1513 }
1514
1515
1516
1517
1518
1519 float Sleep(
float timeS)
1520 {
1522 while (
GetGame().GetTickTime() - startTime < timeS)
1523 {
1524
1525 }
1526
1528 }
1529
1530
1531
1533 {
1535
1536 for (int i = 0; i < 1000; ++i)
1537 {
1538 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
1539 }
1540
1542 }
1543
1544
1545
1547 {
1549
1550 for (int i = 0; i < 1000; ++i)
1551 {
1552 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
1553 }
1554
1556 }
1557
1558
1559
1561 {
1562 int dummy = 3;
1563 }
1564
1565
1566
1568 {
1569 int dummy = 3;
1570 }
1571}
1572
1573class EPTHelperClass
1574{
1575 float Sleep2(
float timeS)
1576 {
1578 while (
GetGame().GetTickTime() - startTime < timeS)
1579 {
1580
1581 }
1582
1584 }
1586 {
1588 while (
GetGame().GetTickTime() - startTime < timeS)
1589 {
1590
1591 }
1592
1594 }
1595
1597 {
1599
1602
1604 }
1605}
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.