1191{
1194
1195
1196
1197
1199 {
1201
1212 }
1213
1214
1215
1216
1218 {
1220 }
1221
1222
1223
1224
1225
1227 {
1231 {
1234 }
1235
1237 }
1238
1239
1240
1242 {
1246 {
1249 }
1250
1252 }
1253
1254
1255
1257 {
1259
1261 {
1264
1266 {
1269 }
1270
1272 {
1275
1277 {
1280 }
1281 }
1282 }
1283
1284
1288 if (!
Assert(bogusFlags == 0))
1289 {
1292 }
1293
1296 if (!
Assert(bogusFlags == 0))
1297 {
1300 }
1301
1302
1305 }
1306
1307
1308
1310 {
1312
1314
1316 {
1319 }
1320
1323
1325 {
1328 }
1329
1332
1334 {
1337 }
1338
1339
1342 }
1343
1344
1345
1347 {
1349
1351
1352
1354 {
1357 }
1358
1360 {
1363 }
1364
1366 {
1369 }
1370
1371
1374 }
1375
1376
1377
1379 {
1380
1382
1383
1384 string nameOfCurrentModule =
Type().GetModule();
1385 if (!
Assert(nameOfCurrentModule !=
""))
1386 {
1388 }
1389
1390
1393 {
1395 }
1396
1397 if (!
Assert(currentModule == eptModule))
1398 {
1400 }
1401
1402
1405
1407 {
1410 }
1411
1412
1415
1416
1417
1419
1420
1423
1424
1426 float timeSlept =
Sleep(0.3);
1428 float diff = postTime - previousTime - timeSlept;
1429
1430
1432
1433
1434 if (!
Assert(postTime > 0))
1435 {
1437
1438 if (!wasEnabled)
1440
1442
1444 }
1445
1446 if (!
Assert(diff < 0.00001))
1447 {
1449
1450 if (!wasEnabled)
1452
1454
1456 }
1457
1458
1460
1461
1462 for (int i = 0; i < 1000; ++i)
1463 {
1465 }
1466
1467
1471
1472 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1473
1474 int funcCount = timePerFunc.Count();
1475 for (int j = 0; j < funcCount; ++j)
1476 {
1478 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1479
1480 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1481 {
1483
1484 if (!wasEnabled)
1486
1488
1490 }
1491 }
1492
1495
1496 int classCount = timePerClass.Count();
1497 for (int k = 0; k < classCount; ++k)
1498 {
1499 typename type = timePerClass[k].param2;
1502 {
1504
1505 if (!wasEnabled)
1507
1509
1511 }
1512
1513
1514 if (!
Assert(classModule == eptModule))
1515 {
1517
1518 if (!wasEnabled)
1520
1522
1524 }
1525 }
1526
1527
1530 timePerFunc.Clear();
1532
1533 bool found = false;
1534
1535 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1536
1537 funcCount = timePerFunc.Count();
1538 for (int l = 0; l < funcCount; ++l)
1539 {
1541 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1542
1543 if (tfpc.param2 == "EnumTools::StringToEnum")
1544 {
1545 found = true;
1546 break;
1547 }
1548 }
1549
1551
1552
1558
1561
1562 if (!wasEnabled)
1564
1565 return BTFR(success && found);
1566 }
1567
1568
1569
1571 {
1572
1575
1576
1578
1579
1580 EPTHelperClass clss = new EPTHelperClass();
1581
1582
1584 float timeStressed = clss.DoEverything();
1587 float timeProfiled = postTime - previousTime;
1588 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1589
1590 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1591
1592
1594 if (!wasEnabled)
1596
1597
1598 if (!
Assert(postTime > 0))
1599 {
1601 }
1602
1603 if (!
Assert(postTime == postTimeStatic))
1604 {
1606 }
1607
1608 if (!
Assert(diff < 0.001))
1609 {
1611 }
1612
1614 }
1615
1616
1617
1619 {
1620 const int allocAmount = 9;
1621 const int releaseAmount = 6;
1622 int remainingAmount = allocAmount - releaseAmount;
1623
1624
1626
1627
1630
1632 for (int i = 0; i < allocAmount; ++i)
1633 {
1634 instanceArr.Insert(new EPTHelperClass());
1635 }
1636
1637 for (int j = 0; j < releaseAmount; ++j)
1638 {
1639 delete instanceArr[j];
1640 }
1641
1644
1645 int alloced = postAlloc - previousAlloc;
1646 int instances = postInstances - previousInstances;
1647
1648 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1649
1650
1651 if (!wasEnabled)
1653
1654
1655 if (!
Assert(alloced == allocAmount))
1656 {
1658 }
1659
1660 if (!
Assert(instances == remainingAmount))
1661 {
1663 }
1664
1666 }
1667
1668
1669
1671 {
1672
1675
1676
1678
1679
1683 float timeProfiled = postTime - previousTime;
1684 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1685
1689 float timeProfiled2 = postTime2 - previousTime2;
1690 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1691
1692 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1693
1694
1696 if (!wasEnabled)
1697 {
1699 }
1700
1701
1702 if (!
Assert(postTime > 0))
1703 {
1705 }
1706
1707 if (!
Assert(diff < 0.001))
1708 {
1710 }
1711
1712 if (!
Assert(postTime2 > 0))
1713 {
1715 }
1716
1717 if (!
Assert(diff2 < 0.001))
1718 {
1720 }
1721
1722
1723 if (!
Assert(timeProfiled < timeProfiled2))
1724 {
1726 }
1727
1729 }
1730
1731
1732
1734 {
1735
1737
1738
1739
1740
1744
1745 int callCountCF = postCountCF - previousCountCF;
1746
1747
1751
1752 int callCountCFP = postCountCFP - previousCountCFP;
1753
1754
1758
1759 int callCountRG = postCountRG - previousCountRG;
1760
1761
1765
1766 int callCountC = postCountC - previousCountC;
1767
1768
1770
1771
1775
1776 int callCountS = postCountS - previousCountS;
1777
1778
1782
1783 int callCountG = postCountG - previousCountG;
1784
1785
1786
1789
1790
1791
1793
1794
1795
1798
1799
1800
1803
1804
1805
1808
1809
1810 if (!wasEnabled)
1811 {
1813 }
1814
1815
1816
1817
1818 if (!
Assert(callCountCF == 1))
1819 {
1821 }
1822
1823
1824 if (!
Assert(callCountCFP == 1))
1825 {
1827 }
1828
1829
1830 if (!
Assert(callCountRG == 1))
1831 {
1833 }
1834
1835
1836 if (!
Assert(callCountC == 1))
1837 {
1839 }
1840
1841
1842 if (!
Assert(callCountNon == -1))
1843 {
1845 }
1846
1847
1848 if (!
Assert(callCountS == 1))
1849 {
1851 }
1852
1853
1854 if (!
Assert(callCountG == 1))
1855 {
1857 }
1858
1859
1860 if (!
Assert(callCountGP == 0))
1861 {
1863 }
1864
1865
1866 if (!
Assert(callCountSP == 0))
1867 {
1869 }
1870
1871
1872 if (!
Assert(callCountP == 0))
1873 {
1875 }
1876
1877
1878 if (!
Assert(callCountPN == 0))
1879 {
1881 }
1882
1883
1884 if (!
Assert(callCountSPN == 0))
1885 {
1887 }
1888
1890 }
1891
1892
1893
1894
1895
1896 float Sleep(
float timeS)
1897 {
1899 while (
GetGame().GetTickTime() - startTime < timeS)
1900 {
1901
1902 }
1903
1905 }
1906
1907
1908
1910 {
1912
1913 for (int i = 0; i < 1000; ++i)
1914 {
1915 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
1916 }
1917
1919 }
1920
1921
1922
1924 {
1926
1927 for (int i = 0; i < 1000; ++i)
1928 {
1929 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
1930 }
1931
1933 }
1934
1935
1936
1938 {
1939 int dummy = 3;
1940 }
1941
1942
1943
1945 {
1946 int dummy = 3;
1947 }
1948}
1949
1950class EPTHelperClass
1951{
1952 float Sleep2(
float timeS)
1953 {
1955 while (
GetGame().GetTickTime() - startTime < timeS)
1956 {
1957
1958 }
1959
1961 }
1963 {
1965 while (
GetGame().GetTickTime() - startTime < timeS)
1966 {
1967
1968 }
1969
1971 }
1972
1974 {
1976
1979
1981 }
1982}
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.