1143{
1146
1147
1148
1149
1151 {
1153
1164 }
1165
1166
1167
1168
1170 {
1172 }
1173
1174
1175
1176
1177
1179 {
1183 {
1186 }
1187
1189 }
1190
1191
1192
1194 {
1198 {
1201 }
1202
1204 }
1205
1206
1207
1209 {
1211
1213 {
1216
1218 {
1221 }
1222
1224 {
1227
1229 {
1232 }
1233 }
1234 }
1235
1236
1240 if (!
Assert(bogusFlags == 0))
1241 {
1244 }
1245
1248 if (!
Assert(bogusFlags == 0))
1249 {
1252 }
1253
1254
1257 }
1258
1259
1260
1262 {
1264
1266
1268 {
1271 }
1272
1275
1277 {
1280 }
1281
1284
1286 {
1289 }
1290
1291
1294 }
1295
1296
1297
1299 {
1301
1303
1304
1306 {
1309 }
1310
1312 {
1315 }
1316
1318 {
1321 }
1322
1323
1326 }
1327
1328
1329
1331 {
1332
1334
1335
1336 string nameOfCurrentModule =
Type().GetModule();
1337 if (!
Assert(nameOfCurrentModule !=
""))
1338 {
1340 }
1341
1342
1345 {
1347 }
1348
1349 if (!
Assert(currentModule == eptModule))
1350 {
1352 }
1353
1354
1357
1359 {
1362 }
1363
1364
1367
1368
1369
1371
1372
1375
1376
1378 float timeSlept =
Sleep(0.3);
1380 float diff = postTime - previousTime - timeSlept;
1381
1382
1384
1385
1386 if (!
Assert(postTime > 0))
1387 {
1389
1390 if (!wasEnabled)
1392
1394
1396 }
1397
1398 if (!
Assert(diff < 0.00001))
1399 {
1401
1402 if (!wasEnabled)
1404
1406
1408 }
1409
1410
1412
1413
1414 for (int i = 0; i < 1000; ++i)
1415 {
1417 }
1418
1419
1423
1424 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1425
1426 int funcCount = timePerFunc.Count();
1427 for (int j = 0; j < funcCount; ++j)
1428 {
1430 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1431
1432 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1433 {
1435
1436 if (!wasEnabled)
1438
1440
1442 }
1443 }
1444
1447
1448 int classCount = timePerClass.Count();
1449 for (int k = 0; k < classCount; ++k)
1450 {
1451 typename type = timePerClass[k].param2;
1454 {
1456
1457 if (!wasEnabled)
1459
1461
1463 }
1464
1465
1466 if (!
Assert(classModule == eptModule))
1467 {
1469
1470 if (!wasEnabled)
1472
1474
1476 }
1477 }
1478
1479
1482 timePerFunc.Clear();
1484
1485 bool found = false;
1486
1487 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1488
1489 funcCount = timePerFunc.Count();
1490 for (int l = 0; l < funcCount; ++l)
1491 {
1493 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1494
1495 if (tfpc.param2 == "EnumTools::StringToEnum")
1496 {
1497 found = true;
1498 break;
1499 }
1500 }
1501
1503
1504
1510
1513
1514 if (!wasEnabled)
1516
1517 return BTFR(success && found);
1518 }
1519
1520
1521
1523 {
1524
1527
1528
1530
1531
1532 EPTHelperClass clss = new EPTHelperClass();
1533
1534
1536 float timeStressed = clss.DoEverything();
1539 float timeProfiled = postTime - previousTime;
1540 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1541
1542 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1543
1544
1546 if (!wasEnabled)
1548
1549
1550 if (!
Assert(postTime > 0))
1551 {
1553 }
1554
1555 if (!
Assert(postTime == postTimeStatic))
1556 {
1558 }
1559
1560 if (!
Assert(diff < 0.001))
1561 {
1563 }
1564
1566 }
1567
1568
1569
1571 {
1572 const int allocAmount = 9;
1573 const int releaseAmount = 6;
1574 int remainingAmount = allocAmount - releaseAmount;
1575
1576
1578
1579
1582
1584 for (int i = 0; i < allocAmount; ++i)
1585 {
1586 instanceArr.Insert(new EPTHelperClass());
1587 }
1588
1589 for (int j = 0; j < releaseAmount; ++j)
1590 {
1591 delete instanceArr[j];
1592 }
1593
1596
1597 int alloced = postAlloc - previousAlloc;
1598 int instances = postInstances - previousInstances;
1599
1600 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1601
1602
1603 if (!wasEnabled)
1605
1606
1607 if (!
Assert(alloced == allocAmount))
1608 {
1610 }
1611
1612 if (!
Assert(instances == remainingAmount))
1613 {
1615 }
1616
1618 }
1619
1620
1621
1623 {
1624
1627
1628
1630
1631
1635 float timeProfiled = postTime - previousTime;
1636 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1637
1641 float timeProfiled2 = postTime2 - previousTime2;
1642 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1643
1644 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1645
1646
1648 if (!wasEnabled)
1649 {
1651 }
1652
1653
1654 if (!
Assert(postTime > 0))
1655 {
1657 }
1658
1659 if (!
Assert(diff < 0.001))
1660 {
1662 }
1663
1664 if (!
Assert(postTime2 > 0))
1665 {
1667 }
1668
1669 if (!
Assert(diff2 < 0.001))
1670 {
1672 }
1673
1674
1675 if (!
Assert(timeProfiled < timeProfiled2))
1676 {
1678 }
1679
1681 }
1682
1683
1684
1686 {
1687
1689
1690
1691
1692
1696
1697 int callCountCF = postCountCF - previousCountCF;
1698
1699
1703
1704 int callCountCFP = postCountCFP - previousCountCFP;
1705
1706
1710
1711 int callCountRG = postCountRG - previousCountRG;
1712
1713
1717
1718 int callCountC = postCountC - previousCountC;
1719
1720
1722
1723
1727
1728 int callCountS = postCountS - previousCountS;
1729
1730
1734
1735 int callCountG = postCountG - previousCountG;
1736
1737
1738
1741
1742
1743
1745
1746
1747
1750
1751
1752
1755
1756
1757
1760
1761
1762 if (!wasEnabled)
1763 {
1765 }
1766
1767
1768
1769
1770 if (!
Assert(callCountCF == 1))
1771 {
1773 }
1774
1775
1776 if (!
Assert(callCountCFP == 1))
1777 {
1779 }
1780
1781
1782 if (!
Assert(callCountRG == 1))
1783 {
1785 }
1786
1787
1788 if (!
Assert(callCountC == 1))
1789 {
1791 }
1792
1793
1794 if (!
Assert(callCountNon == -1))
1795 {
1797 }
1798
1799
1800 if (!
Assert(callCountS == 1))
1801 {
1803 }
1804
1805
1806 if (!
Assert(callCountG == 1))
1807 {
1809 }
1810
1811
1812 if (!
Assert(callCountGP == 0))
1813 {
1815 }
1816
1817
1818 if (!
Assert(callCountSP == 0))
1819 {
1821 }
1822
1823
1824 if (!
Assert(callCountP == 0))
1825 {
1827 }
1828
1829
1830 if (!
Assert(callCountPN == 0))
1831 {
1833 }
1834
1835
1836 if (!
Assert(callCountSPN == 0))
1837 {
1839 }
1840
1842 }
1843
1844
1845
1846
1847
1848 float Sleep(
float timeS)
1849 {
1851 while (
GetGame().GetTickTime() - startTime < timeS)
1852 {
1853
1854 }
1855
1857 }
1858
1859
1860
1862 {
1864
1865 for (int i = 0; i < 1000; ++i)
1866 {
1867 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
1868 }
1869
1871 }
1872
1873
1874
1876 {
1878
1879 for (int i = 0; i < 1000; ++i)
1880 {
1881 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
1882 }
1883
1885 }
1886
1887
1888
1890 {
1891 int dummy = 3;
1892 }
1893
1894
1895
1897 {
1898 int dummy = 3;
1899 }
1900}
1901
1902class EPTHelperClass
1903{
1904 float Sleep2(
float timeS)
1905 {
1907 while (
GetGame().GetTickTime() - startTime < timeS)
1908 {
1909
1910 }
1911
1913 }
1915 {
1917 while (
GetGame().GetTickTime() - startTime < timeS)
1918 {
1919
1920 }
1921
1923 }
1924
1926 {
1928
1931
1933 }
1934}
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.