DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ TestAddFlags()

TFResult Sleep2::TestAddFlags ( )

См. определение в файле EnProfilerTests.c строка 918

919{
922
923 //---------------------------------------------------------------------------
924 // Ctor - Decides the tests to run
925 //---------------------------------------------------------------------------
926 void EnProfilerTests()
927 {
929
930 AddInitTest("TestToggling");
931 AddInitTest("TestTogglingImmediate");
932 AddInitTest("TestSetFlags");
933 AddInitTest("TestClearFlags");
934 AddInitTest("TestAddFlags");
935 AddInitTest("TestModule");
936 AddInitTest("TestClassTimeData");
937 AddInitTest("TestClassCountData");
938 AddInitTest("TestFuncTimeData");
939 AddInitTest("TestFuncCountData");
940 }
941
942 //---------------------------------------------------------------------------
943 // Dtor
944 //---------------------------------------------------------------------------
945 void ~EnProfilerTests()
946 {
948 }
949
950 //---------------------------------------------------------------------------
951 // Tests
952 //---------------------------------------------------------------------------
953 // Test toggling state
955 {
956 bool currentlyEnabled = EnProfiler.IsEnabledP();
957 EnProfiler.Enable(!currentlyEnabled);
958 if (Assert(currentlyEnabled != EnProfiler.IsEnabledP()))
959 {
960 EnProfiler.Enable(currentlyEnabled);
961 return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledP()));
962 }
963
964 return NTFR(TFR.FAIL);
965 }
966
967 //---------------------------------------------------------------------------
968 // Test toggling immediate state
970 {
971 bool currentlyEnabled = EnProfiler.IsEnabledC();
972 EnProfiler.Enable(!currentlyEnabled, true);
973 if (Assert(currentlyEnabled != EnProfiler.IsEnabledC()))
974 {
975 EnProfiler.Enable(currentlyEnabled, true);
976 return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledC()));
977 }
978
979 return NTFR(TFR.FAIL);
980 }
981
982 //---------------------------------------------------------------------------
983 // Test SetFlags/GetFlags
985 {
986 int currentFlags = EnProfiler.GetFlags();
987
988 for (int i = 0; i < EnumTools.GetEnumSize(EnProfilerFlags); ++i)
989 {
990 int flags = EnumTools.GetEnumValue(EnProfilerFlags, i);
991 EnProfiler.SetFlags(flags);
992
993 if (!Assert(EnProfiler.GetFlags() == flags))
994 {
995 EnProfiler.SetFlags(currentFlags);
996 return NTFR(TFR.FAIL);
997 }
998
999 for (int j = 0; j < EnumTools.GetEnumSize(EnProfilerFlags); ++j)
1000 {
1002 EnProfiler.SetFlags(flags);
1003
1004 if (!Assert(EnProfiler.GetFlags() == flags))
1005 {
1006 EnProfiler.SetFlags(currentFlags);
1007 return NTFR(TFR.FAIL);
1008 }
1009 }
1010 }
1011
1012 // Let's test some bogus
1013 EnProfiler.SetFlags(-333);
1014 int bogusFlags = EnProfiler.GetFlags();
1015 bogusFlags &= ~EnProfilerFlags.ALL;
1016 if (!Assert(bogusFlags == 0))
1017 {
1018 EnProfiler.SetFlags(currentFlags);
1019 return NTFR(TFR.FAIL);
1020 }
1021
1022 bogusFlags = EnProfiler.SetFlags(6003);
1023 bogusFlags &= ~EnProfilerFlags.ALL;
1024 if (!Assert(bogusFlags == 0))
1025 {
1026 EnProfiler.SetFlags(currentFlags);
1027 return NTFR(TFR.FAIL);
1028 }
1029
1030 // Reset
1031 EnProfiler.SetFlags(currentFlags);
1032 return NTFR(TFR.SUCCESS);
1033 }
1034
1035 //---------------------------------------------------------------------------
1036 // Test removing of flags
1038 {
1039 int currentFlags = EnProfiler.GetFlags();
1040
1042
1044 {
1045 EnProfiler.SetFlags(currentFlags);
1046 return NTFR(TFR.FAIL);
1047 }
1048
1051
1052 if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
1053 {
1054 EnProfiler.SetFlags(currentFlags);
1055 return NTFR(TFR.FAIL);
1056 }
1057
1060
1061 if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
1062 {
1063 EnProfiler.SetFlags(currentFlags);
1064 return NTFR(TFR.FAIL);
1065 }
1066
1067 // Reset
1068 EnProfiler.SetFlags(currentFlags);
1069 return NTFR(TFR.SUCCESS);
1070 }
1071
1072 //---------------------------------------------------------------------------
1073 // Test adding of flags
1075 {
1076 int currentFlags = EnProfiler.GetFlags();
1077
1079
1080 // Return should match resulting flags
1082 {
1083 EnProfiler.SetFlags(currentFlags);
1084 return NTFR(TFR.FAIL);
1085 }
1086
1087 if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.RESET))
1088 {
1089 EnProfiler.SetFlags(currentFlags);
1090 return NTFR(TFR.FAIL);
1091 }
1092
1093 if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RECURSIVE) == (EnProfilerFlags.RESET | EnProfilerFlags.RECURSIVE)))
1094 {
1095 EnProfiler.SetFlags(currentFlags);
1096 return NTFR(TFR.FAIL);
1097 }
1098
1099 // Reset
1100 EnProfiler.SetFlags(currentFlags);
1101 return NTFR(TFR.SUCCESS);
1102 }
1103
1104 //---------------------------------------------------------------------------
1105 // Test module
1107 {
1108 // File lives in Game, use it while testing
1109 const EnProfilerModule eptModule = EnProfilerModule.GAME;
1110
1111 // This was added at the same time as this API, so check if it works as well
1112 string nameOfCurrentModule = Type().GetModule();
1113 if (!Assert(nameOfCurrentModule != ""))
1114 {
1115 return NTFR(TFR.FAIL);
1116 }
1117
1118 // We know we are in Game, so use it as a test
1119 EnProfilerModule currentModule;
1120 if (!Assert(EnProfiler.NameToModule(nameOfCurrentModule, currentModule)))
1121 {
1122 return NTFR(TFR.FAIL);
1123 }
1124
1125 if (!Assert(currentModule == eptModule))
1126 {
1127 return NTFR(TFR.FAIL);
1128 }
1129
1130 // Test if setting and getting works
1131 EnProfilerModule currentlyProfiledModule = EnProfiler.GetModule();
1132 EnProfiler.SetModule(eptModule);
1133
1134 if (!Assert(EnProfiler.GetModule() == eptModule))
1135 {
1136 EnProfiler.SetModule(currentlyProfiledModule);
1137 return NTFR(TFR.FAIL);
1138 }
1139
1140 // Data to restore
1141 int currentFlags = EnProfiler.GetFlags();
1142 bool wasEnabled = EnProfiler.RequestImmediateData();
1143
1144 // Make sure we are only profiling Game and that the data is clean
1145 // Only valid for the Get...Per... methods, as they need to be sorted
1147
1148 // GetTickTime() returns in seconds, so gather the results in seconds too
1149 int resolution = EnProfiler.GetTimeResolution();
1151
1152 // Time to sleeb
1153 float previousTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
1154 float timeSlept = Sleep(0.3);
1155 float postTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
1156 float diff = postTime - previousTime - timeSlept;
1157
1158 // Restore
1159 EnProfiler.SetTimeResolution(resolution);
1160
1161 // We called the function, so it must have some time
1162 if (!Assert(postTime > 0))
1163 {
1164 EnProfiler.SetFlags(currentFlags);
1165
1166 if (!wasEnabled)
1167 EnProfiler.Enable(false, true);
1168
1169 EnProfiler.SetModule(currentlyProfiledModule);
1170
1171 return NTFR(TFR.FAIL);
1172 }
1173
1174 if (!Assert(diff < 0.00001))
1175 {
1176 EnProfiler.SetFlags(currentFlags);
1177
1178 if (!wasEnabled)
1179 EnProfiler.Enable(false, true);
1180
1181 EnProfiler.SetModule(currentlyProfiledModule);
1182
1183 return NTFR(TFR.FAIL);
1184 }
1185
1186 // Clean the session
1188
1189 // Something from a different module should not get sorted, so just fire something from a different module
1190 for (int i = 0; i < 1000; ++i)
1191 {
1192 EnumTools.StringToEnum(EnProfilerModule, "MISSION_CUSTOM");
1193 }
1194
1195 // Sort and gather the data and validate if it is correct
1197 array<ref EnProfilerTimeFuncPair> timePerFunc = {};
1198 EnProfiler.GetTimePerFunc(timePerFunc);
1199
1200 Debug.TFLog("Game fncs:", this, "TestModule");
1201
1202 int funcCount = timePerFunc.Count();
1203 for (int j = 0; j < funcCount; ++j)
1204 {
1205 EnProfilerTimeFuncPair tfp = timePerFunc[j];
1206 Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfp.param1, tfp.param2), this, "TestModule");
1207 // We are currently profiling Game, so this Core function shouldn't be present
1208 if (!Assert(tfp.param2 != "EnumTools::StringToEnum"))
1209 {
1210 EnProfiler.SetFlags(currentFlags);
1211
1212 if (!wasEnabled)
1213 EnProfiler.Enable(false, true);
1214
1215 EnProfiler.SetModule(currentlyProfiledModule);
1216
1217 return NTFR(TFR.FAIL);
1218 }
1219 }
1220
1221 array<ref EnProfilerTimeClassPair> timePerClass = {};
1222 EnProfiler.GetTimePerClass(timePerClass);
1223
1224 int classCount = timePerClass.Count();
1225 for (int k = 0; k < classCount; ++k)
1226 {
1227 typename type = timePerClass[k].param2;
1228 EnProfilerModule classModule;
1229 if (!Assert(EnProfiler.NameToModule(type.GetModule(), classModule)))
1230 {
1231 EnProfiler.SetFlags(currentFlags);
1232
1233 if (!wasEnabled)
1234 EnProfiler.Enable(false, true);
1235
1236 EnProfiler.SetModule(currentlyProfiledModule);
1237
1238 return NTFR(TFR.FAIL);
1239 }
1240
1241 // Only classes from Game should be present
1242 if (!Assert(classModule == eptModule))
1243 {
1244 EnProfiler.SetFlags(currentFlags);
1245
1246 if (!wasEnabled)
1247 EnProfiler.Enable(false, true);
1248
1249 EnProfiler.SetModule(currentlyProfiledModule);
1250
1251 return NTFR(TFR.FAIL);
1252 }
1253 }
1254
1255 // Now let's check if we can gather the data of what we called earlier by switching the profiled module without resetting the session
1258 timePerFunc.Clear(); // Let's reuse the array, but the Get...Per... methods only appends to the array, clearing is our responsibility
1259 EnProfiler.GetTimePerFunc(timePerFunc);
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 {
1268 EnProfilerTimeFuncPair tfpc = timePerFunc[l];
1269 Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfpc.param1, tfpc.param2), this, "TestModule");
1270 // We are currently profiling Core, so this Core function should be present
1271 if (tfpc.param2 == "EnumTools::StringToEnum")
1272 {
1273 found = true;
1274 break;
1275 }
1276 }
1277
1278 Assert(found);
1279
1280 // Test some bogus
1282 EnProfiler.SetModule(-333);
1283 bool success = Assert(EnProfiler.GetModule() == mod);
1284 EnProfiler.SetModule(6003);
1285 success &= Assert(EnProfiler.GetModule() == mod);
1286
1287 EnProfiler.SetFlags(currentFlags);
1288 EnProfiler.SetModule(currentlyProfiledModule);
1289
1290 if (!wasEnabled)
1291 EnProfiler.Enable(false, true);
1292
1293 return BTFR(success && found);
1294 }
1295
1296 //---------------------------------------------------------------------------
1297 // Test to see if class time data is correct
1299 {
1300 // We should restore this when done
1301 int resolution = EnProfiler.GetTimeResolution();
1302 bool wasEnabled = EnProfiler.RequestImmediateData();
1303
1304 // GetTickTime() returns in seconds, so gather the results in seconds too
1306
1307 // Create the classes
1308 EPTHelperClass clss = new EPTHelperClass();
1309
1310 // Time to stress
1311 float previousTime = EnProfiler.GetTimeOfClass(clss.Type(), true);
1312 float timeStressed = clss.DoEverything();
1313 float postTime = EnProfiler.GetTimeOfClass(clss.Type(), true);
1314 float postTimeStatic = EnProfiler.GetTimeOfClass(StaticGetType(EPTHelperClass), true);
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 // Restore
1321 EnProfiler.SetTimeResolution(resolution);
1322 if (!wasEnabled)
1323 EnProfiler.Enable(false, true);
1324
1325 // We called the function, so it must have some time
1326 if (!Assert(postTime > 0))
1327 {
1328 return NTFR(TFR.FAIL);
1329 }
1330
1331 if (!Assert(postTime == postTimeStatic))
1332 {
1333 return NTFR(TFR.FAIL);
1334 }
1335
1336 if (!Assert(diff < 0.001))
1337 {
1338 return NTFR(TFR.FAIL);
1339 }
1340
1341 return NTFR(TFR.SUCCESS);
1342 }
1343
1344 //---------------------------------------------------------------------------
1345 // Test to see if class count data is correct
1347 {
1348 const int allocAmount = 9;
1349 const int releaseAmount = 6;
1350 int remainingAmount = allocAmount - releaseAmount;
1351
1352 // We should restore this when done
1353 bool wasEnabled = EnProfiler.RequestImmediateData();
1354
1355 // Time to test
1356 int previousAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
1357 int previousInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
1358
1359 array<ref EPTHelperClass> instanceArr = {};
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
1370 int postAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
1371 int postInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
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 // Restore
1379 if (!wasEnabled)
1380 EnProfiler.Enable(false, true);
1381
1382 // Time to check
1383 if (!Assert(alloced == allocAmount))
1384 {
1385 return NTFR(TFR.FAIL);
1386 }
1387
1388 if (!Assert(instances == remainingAmount))
1389 {
1390 return NTFR(TFR.FAIL);
1391 }
1392
1393 return NTFR(TFR.SUCCESS);
1394 }
1395
1396 //---------------------------------------------------------------------------
1397 // Test to see if func time data is correct
1399 {
1400 // We should restore this when done
1401 int resolution = EnProfiler.GetTimeResolution();
1402 bool wasEnabled = EnProfiler.RequestImmediateData();
1403
1404 // GetTickTime() returns in seconds, so gather the results in seconds too
1406
1407 // Time to stress
1408 float previousTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
1409 float timeStressed = StringFormat();
1410 float postTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
1411 float timeProfiled = postTime - previousTime;
1412 float diff = Math.AbsFloat(timeProfiled - timeStressed);
1413
1414 float previousTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
1415 float timeStressed2 = StringConcat();
1416 float postTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
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 // Restore
1423 EnProfiler.SetTimeResolution(resolution);
1424 if (!wasEnabled)
1425 {
1426 EnProfiler.Enable(false, true);
1427 }
1428
1429 // We called the function, so it must have some time
1430 if (!Assert(postTime > 0))
1431 {
1432 return NTFR(TFR.FAIL);
1433 }
1434
1435 if (!Assert(diff < 0.001))
1436 {
1437 return NTFR(TFR.FAIL);
1438 }
1439
1440 if (!Assert(postTime2 > 0))
1441 {
1442 return NTFR(TFR.FAIL);
1443 }
1444
1445 if (!Assert(diff2 < 0.001))
1446 {
1447 return NTFR(TFR.FAIL);
1448 }
1449
1450 // I know that string.Format is faster than additive concatenation
1451 if (!Assert(timeProfiled < timeProfiled2))
1452 {
1453 return NTFR(TFR.FAIL);
1454 }
1455
1456 return NTFR(TFR.SUCCESS);
1457 }
1458
1459 //---------------------------------------------------------------------------
1460 // Test to see if func count data is correct
1462 {
1463 // We should restore this when done
1464 bool wasEnabled = EnProfiler.RequestImmediateData();
1465
1466 // Time to count
1467
1468 // - CallFunction
1469 int previousCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
1470 GetGame().GameScript.CallFunction(this, "TestFuncCountDataHelper", null, 0);
1471 int postCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
1472
1473 int callCountCF = postCountCF - previousCountCF;
1474
1475 // - CallFunctionParams
1476 int previousCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
1477 GetGame().GameScript.CallFunctionParams(this, "TestFuncCountDataHelper", null, null);
1478 int postCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
1479
1480 int callCountCFP = postCountCFP - previousCountCFP;
1481
1482 // - Regular call
1483 int previousCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
1485 int postCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
1486
1487 int callCountRG = postCountRG - previousCountRG;
1488
1489 // - Call
1490 int previousCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
1491 GetGame().GameScript.Call(this, "TestFuncCountDataHelper", 0);
1492 int postCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
1493
1494 int callCountC = postCountC - previousCountC;
1495
1496 // - Garbage
1497 int callCountNon = EnProfiler.GetCountOfFunc("Non Existing Method", Type(), true);
1498
1499 // - Static
1500 int previousCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
1502 int postCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
1503
1504 int callCountS = postCountS - previousCountS;
1505
1506 // - Global
1507 int previousCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
1508 GetDayZGame();
1509 int postCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
1510
1511 int callCountG = postCountG - previousCountG;
1512
1513 // - Global proto
1514 // Not tracked, so don't need to compare before and after, should always be 0
1515 ErrorEx("Testing global proto call", ErrorExSeverity.INFO);
1516 int callCountGP = EnProfiler.GetCountOfFuncG("ErrorEx", true);
1517
1518 // - Static proto
1519 // Not tracked, so don't need to compare before and after, should always be 0
1520 int callCountSP = EnProfiler.GetCountOfFunc("GetCountOfFunc", StaticGetType(EnProfiler), true);
1521
1522 // - proto
1523 // Not tracked, so don't need to compare before and after, should always be 0
1524 GetGame().GetHostName();
1525 int callCountP = EnProfiler.GetCountOfFunc("GetHostName", GetGame().Type(), true);
1526
1527 // - proto native
1528 // Not tracked, so don't need to compare before and after, should always be 0
1529 GetGame().IsServer();
1530 int callCountPN = EnProfiler.GetCountOfFunc("IsServer", GetGame().Type(), true);
1531
1532 // - static proto native
1533 // Not tracked, so don't need to compare before and after, should always be 0
1535 int callCountSPN = EnProfiler.GetCountOfFunc("GetInstance", StaticGetType(ErrorModuleHandler), true);
1536
1537 // Restore
1538 if (!wasEnabled)
1539 {
1540 EnProfiler.Enable(false, true);
1541 }
1542
1543 // Do the checks
1544
1545 // - CallFunction
1546 if (!Assert(callCountCF == 1))
1547 {
1548 return NTFR(TFR.FAIL);
1549 }
1550
1551 // - CallFunctionParams
1552 if (!Assert(callCountCFP == 1))
1553 {
1554 return NTFR(TFR.FAIL);
1555 }
1556
1557 // - Regular call
1558 if (!Assert(callCountRG == 1))
1559 {
1560 return NTFR(TFR.FAIL);
1561 }
1562
1563 // - Call
1564 if (!Assert(callCountC == 1))
1565 {
1566 return NTFR(TFR.FAIL);
1567 }
1568
1569 // - Garbage
1570 if (!Assert(callCountNon == -1))
1571 {
1572 return NTFR(TFR.FAIL);
1573 }
1574
1575 // - Static
1576 if (!Assert(callCountS == 1))
1577 {
1578 return NTFR(TFR.FAIL);
1579 }
1580
1581 // - Global
1582 if (!Assert(callCountG == 1))
1583 {
1584 return NTFR(TFR.FAIL);
1585 }
1586
1587 // - Global proto
1588 if (!Assert(callCountGP == 0))
1589 {
1590 return NTFR(TFR.FAIL);
1591 }
1592
1593 // - Static proto
1594 if (!Assert(callCountSP == 0))
1595 {
1596 return NTFR(TFR.FAIL);
1597 }
1598
1599 // - proto
1600 if (!Assert(callCountP == 0))
1601 {
1602 return NTFR(TFR.FAIL);
1603 }
1604
1605 // - proto native
1606 if (!Assert(callCountPN == 0))
1607 {
1608 return NTFR(TFR.FAIL);
1609 }
1610
1611 // - static proto native
1612 if (!Assert(callCountSPN == 0))
1613 {
1614 return NTFR(TFR.FAIL);
1615 }
1616
1617 return NTFR(TFR.SUCCESS);
1618 }
1619
1620 //---------------------------------------------------------------------------
1621 // Helpers
1622 //---------------------------------------------------------------------------
1623 // Snore
1624 float Sleep(float timeS)
1625 {
1626 float startTime = GetGame().GetTickTime();
1627 while (GetGame().GetTickTime() - startTime < timeS)
1628 {
1629 // Zzz
1630 }
1631
1632 return GetGame().GetTickTime() - startTime;
1633 }
1634
1635 //---------------------------------------------------------------------------
1636 // Example stress method
1637 float StringFormat()
1638 {
1639 float startTime = GetGame().GetTickTime();
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
1646 return GetGame().GetTickTime() - startTime;
1647 }
1648
1649 //---------------------------------------------------------------------------
1650 // Example stress method 2
1651 float StringConcat()
1652 {
1653 float startTime = GetGame().GetTickTime();
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
1660 return GetGame().GetTickTime() - startTime;
1661 }
1662
1663 //---------------------------------------------------------------------------
1664 // To make sure it is only ever called in that test
1666 {
1667 int dummy = 3;
1668 }
1669
1670 //---------------------------------------------------------------------------
1671 // To make sure it is only ever called in that test
1672 static void TestFuncCountDataHelperStatic()
1673 {
1674 int dummy = 3;
1675 }
1676}
1677
1678class EPTHelperClass
1679{
1680 float Sleep2(float timeS)
1681 {
1682 float startTime = GetGame().GetTickTime();
1683 while (GetGame().GetTickTime() - startTime < timeS)
1684 {
1685 // Zzz
1686 }
1687
1688 return GetGame().GetTickTime() - startTime;
1689 }
1690 float SleepAgain(float timeS)
1691 {
1692 float startTime = GetGame().GetTickTime();
1693 while (GetGame().GetTickTime() - startTime < timeS)
1694 {
1695 // Zzz
1696 }
1697
1698 return GetGame().GetTickTime() - startTime;
1699 }
1700
1701 float DoEverything()
1702 {
1703 float startTime = GetGame().GetTickTime();
1704
1705 Sleep2(3);
1706 SleepAgain(3);
1707
1708 return GetGame().GetTickTime() - startTime;
1709 }
1710}
DayZGame GetDayZGame()
Определения DayZGame.c:3870
float StringConcat()
Определения EnProfilerTests.c:1495
float SleepAgain(float timeS)
Определения EnProfilerTests.c:773
float Sleep(float timeS)
Определения EnProfilerTests.c:1468
void TestFuncCountDataHelper()
Определения EnProfilerTests.c:1509
void EnProfilerTests()
Определения EnProfilerTests.c:770
TFResult TestModule()
Определения EnProfilerTests.c:950
float DoEverything()
Определения EnProfilerTests.c:784
TFResult TestClearFlags()
Определения EnProfilerTests.c:881
void ~EnProfilerTests()
Определения EnProfilerTests.c:789
TFResult TestTogglingImmediate()
Определения EnProfilerTests.c:813
TFResult TestFuncCountData()
Определения EnProfilerTests.c:1305
EnProfilerTests TestFramework Sleep2(float timeS)
Определения EnProfilerTests.c:763
TFResult TestClassTimeData()
Определения EnProfilerTests.c:1142
static void TestFuncCountDataHelperStatic()
Определения EnProfilerTests.c:1516
float StringFormat()
Определения EnProfilerTests.c:1481
TFResult TestClassCountData()
Определения EnProfilerTests.c:1190
TFResult TestAddFlags()
Определения EnProfilerTests.c:918
bool m_bWasProfilerEnabled
Remember this, so we can restore the previous state before the test!
Определения EnProfilerTests.c:765
TFResult TestFuncTimeData()
Определения EnProfilerTests.c:1242
TFResult TestSetFlags()
Определения EnProfilerTests.c:828
TFResult TestToggling()
Определения EnProfilerTests.c:798
string Type
Определения JsonDataContaminatedArea.c:11
void TestFramework()
Определения TestFramework.c:217
TFResult NTFR(TFR result)
Определения TestFramework.c:273
bool Assert(bool condition)
Определения TestFramework.c:262
void TFResult(TFR result)
Определения TestFramework.c:12
TFR
Определения TestFramework.c:2
void AddInitTest(string test)
Определения TestFramework.c:249
TFResult BTFR(bool result)
Определения TestFramework.c:278
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()
ScriptModule GameScript
Определения Game.c:12
static void TFLog(string message=LOG_DEFAULT, TestFramework caller=null, string function="")
Определения Debug.c:177
Определения Debug.c:2
Set of methods for accessing script profiling data.
Определения EnProfiler.c:73
static int GetEnumSize(typename e)
Return amount of values in enum.
Определения EnConvert.c:623
static int GetEnumValue(typename e, int idx)
Return the nth value in the enum.
Определения EnConvert.c:634
static int StringToEnum(typename e, string enumName)
Return enum value from string name.
Определения EnConvert.c:612
Определения EnConvert.c:590
static proto native ErrorModuleHandler GetInstance()
Gets the EMH Instance.
The error handler itself, for managing and distributing errors to modules Manages the ErrorHandlerMod...
Определения ErrorModuleHandler.c:29
Определения EnMath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
ErrorExSeverity
Определения EnDebug.c:62
enum ShapeType ErrorEx
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
Определения EnProfiler.c:58
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.
Определения EnProfiler.c:138
static bool IsEnabledC()
Return if script profiling is actually turned on inside of the script context.
Определения EnProfiler.c:152
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.
Определения EnProfiler.c:9
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.
Определения EnProfiler.c:22
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.
Определения EnProfiler.c:745
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.