799{
802
803
804
805
807 {
809
820 }
821
822
823
824
826 {
828 }
829
830
831
832
833
835 {
839 {
842 }
843
845 }
846
847
848
850 {
854 {
857 }
858
860 }
861
862
863
865 {
867
869 {
872
874 {
877 }
878
880 {
883
885 {
888 }
889 }
890 }
891
892
896 if (!
Assert(bogusFlags == 0))
897 {
900 }
901
904 if (!
Assert(bogusFlags == 0))
905 {
908 }
909
910
913 }
914
915
916
918 {
920
922
924 {
927 }
928
931
933 {
936 }
937
940
942 {
945 }
946
947
950 }
951
952
953
955 {
957
959
960
962 {
965 }
966
968 {
971 }
972
974 {
977 }
978
979
982 }
983
984
985
987 {
988
990
991
992 string nameOfCurrentModule =
Type().GetModule();
993 if (!
Assert(nameOfCurrentModule !=
""))
994 {
996 }
997
998
1001 {
1003 }
1004
1005 if (!
Assert(currentModule == eptModule))
1006 {
1008 }
1009
1010
1013
1015 {
1018 }
1019
1020
1023
1024
1025
1027
1028
1031
1032
1034 float timeSlept =
Sleep(0.3);
1036 float diff = postTime - previousTime - timeSlept;
1037
1038
1040
1041
1042 if (!
Assert(postTime > 0))
1043 {
1045
1046 if (!wasEnabled)
1048
1050
1052 }
1053
1054 if (!
Assert(diff < 0.00001))
1055 {
1057
1058 if (!wasEnabled)
1060
1062
1064 }
1065
1066
1068
1069
1070 for (int i = 0; i < 1000; ++i)
1071 {
1073 }
1074
1075
1079
1080 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1081
1082 int funcCount = timePerFunc.Count();
1083 for (int j = 0; j < funcCount; ++j)
1084 {
1086 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1087
1088 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1089 {
1091
1092 if (!wasEnabled)
1094
1096
1098 }
1099 }
1100
1103
1104 int classCount = timePerClass.Count();
1105 for (int k = 0; k < classCount; ++k)
1106 {
1107 typename type = timePerClass[k].param2;
1110 {
1112
1113 if (!wasEnabled)
1115
1117
1119 }
1120
1121
1122 if (!
Assert(classModule == eptModule))
1123 {
1125
1126 if (!wasEnabled)
1128
1130
1132 }
1133 }
1134
1135
1138 timePerFunc.Clear();
1140
1141 bool found = false;
1142
1143 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1144
1145 funcCount = timePerFunc.Count();
1146 for (int l = 0; l < funcCount; ++l)
1147 {
1149 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1150
1151 if (tfpc.param2 == "EnumTools::StringToEnum")
1152 {
1153 found = true;
1154 break;
1155 }
1156 }
1157
1159
1160
1166
1169
1170 if (!wasEnabled)
1172
1173 return BTFR(success && found);
1174 }
1175
1176
1177
1179 {
1180
1183
1184
1186
1187
1188 EPTHelperClass clss = new EPTHelperClass();
1189
1190
1192 float timeStressed = clss.DoEverything();
1195 float timeProfiled = postTime - previousTime;
1196 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1197
1198 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1199
1200
1202 if (!wasEnabled)
1204
1205
1206 if (!
Assert(postTime > 0))
1207 {
1209 }
1210
1211 if (!
Assert(postTime == postTimeStatic))
1212 {
1214 }
1215
1216 if (!
Assert(diff < 0.001))
1217 {
1219 }
1220
1222 }
1223
1224
1225
1227 {
1228 const int allocAmount = 9;
1229 const int releaseAmount = 6;
1230 int remainingAmount = allocAmount - releaseAmount;
1231
1232
1234
1235
1238
1240 for (int i = 0; i < allocAmount; ++i)
1241 {
1242 instanceArr.Insert(new EPTHelperClass());
1243 }
1244
1245 for (int j = 0; j < releaseAmount; ++j)
1246 {
1247 delete instanceArr[j];
1248 }
1249
1252
1253 int alloced = postAlloc - previousAlloc;
1254 int instances = postInstances - previousInstances;
1255
1256 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1257
1258
1259 if (!wasEnabled)
1261
1262
1263 if (!
Assert(alloced == allocAmount))
1264 {
1266 }
1267
1268 if (!
Assert(instances == remainingAmount))
1269 {
1271 }
1272
1274 }
1275
1276
1277
1279 {
1280
1283
1284
1286
1287
1291 float timeProfiled = postTime - previousTime;
1292 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1293
1297 float timeProfiled2 = postTime2 - previousTime2;
1298 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1299
1300 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1301
1302
1304 if (!wasEnabled)
1305 {
1307 }
1308
1309
1310 if (!
Assert(postTime > 0))
1311 {
1313 }
1314
1315 if (!
Assert(diff < 0.001))
1316 {
1318 }
1319
1320 if (!
Assert(postTime2 > 0))
1321 {
1323 }
1324
1325 if (!
Assert(diff2 < 0.001))
1326 {
1328 }
1329
1330
1331 if (!
Assert(timeProfiled < timeProfiled2))
1332 {
1334 }
1335
1337 }
1338
1339
1340
1342 {
1343
1345
1346
1347
1348
1352
1353 int callCountCF = postCountCF - previousCountCF;
1354
1355
1359
1360 int callCountCFP = postCountCFP - previousCountCFP;
1361
1362
1366
1367 int callCountRG = postCountRG - previousCountRG;
1368
1369
1373
1374 int callCountC = postCountC - previousCountC;
1375
1376
1378
1379
1383
1384 int callCountS = postCountS - previousCountS;
1385
1386
1390
1391 int callCountG = postCountG - previousCountG;
1392
1393
1394
1397
1398
1399
1401
1402
1403
1406
1407
1408
1411
1412
1413
1416
1417
1418 if (!wasEnabled)
1419 {
1421 }
1422
1423
1424
1425
1426 if (!
Assert(callCountCF == 1))
1427 {
1429 }
1430
1431
1432 if (!
Assert(callCountCFP == 1))
1433 {
1435 }
1436
1437
1438 if (!
Assert(callCountRG == 1))
1439 {
1441 }
1442
1443
1444 if (!
Assert(callCountC == 1))
1445 {
1447 }
1448
1449
1450 if (!
Assert(callCountNon == -1))
1451 {
1453 }
1454
1455
1456 if (!
Assert(callCountS == 1))
1457 {
1459 }
1460
1461
1462 if (!
Assert(callCountG == 1))
1463 {
1465 }
1466
1467
1468 if (!
Assert(callCountGP == 0))
1469 {
1471 }
1472
1473
1474 if (!
Assert(callCountSP == 0))
1475 {
1477 }
1478
1479
1480 if (!
Assert(callCountP == 0))
1481 {
1483 }
1484
1485
1486 if (!
Assert(callCountPN == 0))
1487 {
1489 }
1490
1491
1492 if (!
Assert(callCountSPN == 0))
1493 {
1495 }
1496
1498 }
1499
1500
1501
1502
1503
1504 float Sleep(
float timeS)
1505 {
1507 while (
GetGame().GetTickTime() - startTime < timeS)
1508 {
1509
1510 }
1511
1513 }
1514
1515
1516
1518 {
1520
1521 for (int i = 0; i < 1000; ++i)
1522 {
1523 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
1524 }
1525
1527 }
1528
1529
1530
1532 {
1534
1535 for (int i = 0; i < 1000; ++i)
1536 {
1537 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
1538 }
1539
1541 }
1542
1543
1544
1546 {
1547 int dummy = 3;
1548 }
1549
1550
1551
1553 {
1554 int dummy = 3;
1555 }
1556}
1557
1558class EPTHelperClass
1559{
1560 float Sleep2(
float timeS)
1561 {
1563 while (
GetGame().GetTickTime() - startTime < timeS)
1564 {
1565
1566 }
1567
1569 }
1571 {
1573 while (
GetGame().GetTickTime() - startTime < timeS)
1574 {
1575
1576 }
1577
1579 }
1580
1582 {
1584
1587
1589 }
1590}
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.