1306{
1309
1310
1311
1312
1314 {
1316
1327 }
1328
1329
1330
1331
1333 {
1335 }
1336
1337
1338
1339
1340
1342 {
1346 {
1349 }
1350
1352 }
1353
1354
1355
1357 {
1361 {
1364 }
1365
1367 }
1368
1369
1370
1372 {
1374
1376 {
1379
1381 {
1384 }
1385
1387 {
1390
1392 {
1395 }
1396 }
1397 }
1398
1399
1403 if (!
Assert(bogusFlags == 0))
1404 {
1407 }
1408
1411 if (!
Assert(bogusFlags == 0))
1412 {
1415 }
1416
1417
1420 }
1421
1422
1423
1425 {
1427
1429
1431 {
1434 }
1435
1438
1440 {
1443 }
1444
1447
1449 {
1452 }
1453
1454
1457 }
1458
1459
1460
1462 {
1464
1466
1467
1469 {
1472 }
1473
1475 {
1478 }
1479
1481 {
1484 }
1485
1486
1489 }
1490
1491
1492
1494 {
1495
1497
1498
1499 string nameOfCurrentModule =
Type().GetModule();
1500 if (!
Assert(nameOfCurrentModule !=
""))
1501 {
1503 }
1504
1505
1508 {
1510 }
1511
1512 if (!
Assert(currentModule == eptModule))
1513 {
1515 }
1516
1517
1520
1522 {
1525 }
1526
1527
1530
1531
1532
1534
1535
1538
1539
1541 float timeSlept =
Sleep(0.3);
1543 float diff = postTime - previousTime - timeSlept;
1544
1545
1547
1548
1549 if (!
Assert(postTime > 0))
1550 {
1552
1553 if (!wasEnabled)
1555
1557
1559 }
1560
1561 if (!
Assert(diff < 0.00001))
1562 {
1564
1565 if (!wasEnabled)
1567
1569
1571 }
1572
1573
1575
1576
1577 for (int i = 0; i < 1000; ++i)
1578 {
1580 }
1581
1582
1586
1587 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1588
1589 int funcCount = timePerFunc.Count();
1590 for (int j = 0; j < funcCount; ++j)
1591 {
1593 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1594
1595 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1596 {
1598
1599 if (!wasEnabled)
1601
1603
1605 }
1606 }
1607
1610
1611 int classCount = timePerClass.Count();
1612 for (int k = 0; k < classCount; ++k)
1613 {
1614 typename type = timePerClass[k].param2;
1617 {
1619
1620 if (!wasEnabled)
1622
1624
1626 }
1627
1628
1629 if (!
Assert(classModule == eptModule))
1630 {
1632
1633 if (!wasEnabled)
1635
1637
1639 }
1640 }
1641
1642
1645 timePerFunc.Clear();
1647
1648 bool found = false;
1649
1650 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1651
1652 funcCount = timePerFunc.Count();
1653 for (int l = 0; l < funcCount; ++l)
1654 {
1656 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1657
1658 if (tfpc.param2 == "EnumTools::StringToEnum")
1659 {
1660 found = true;
1661 break;
1662 }
1663 }
1664
1666
1667
1673
1676
1677 if (!wasEnabled)
1679
1680 return BTFR(success && found);
1681 }
1682
1683
1684
1686 {
1687
1690
1691
1693
1694
1695 EPTHelperClass clss = new EPTHelperClass();
1696
1697
1699 float timeStressed = clss.DoEverything();
1702 float timeProfiled = postTime - previousTime;
1703 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1704
1705 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1706
1707
1709 if (!wasEnabled)
1711
1712
1713 if (!
Assert(postTime > 0))
1714 {
1716 }
1717
1718 if (!
Assert(postTime == postTimeStatic))
1719 {
1721 }
1722
1723 if (!
Assert(diff < 0.001))
1724 {
1726 }
1727
1729 }
1730
1731
1732
1734 {
1735 const int allocAmount = 9;
1736 const int releaseAmount = 6;
1737 int remainingAmount = allocAmount - releaseAmount;
1738
1739
1741
1742
1745
1747 for (int i = 0; i < allocAmount; ++i)
1748 {
1749 instanceArr.Insert(new EPTHelperClass());
1750 }
1751
1752 for (int j = 0; j < releaseAmount; ++j)
1753 {
1754 delete instanceArr[j];
1755 }
1756
1759
1760 int alloced = postAlloc - previousAlloc;
1761 int instances = postInstances - previousInstances;
1762
1763 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1764
1765
1766 if (!wasEnabled)
1768
1769
1770 if (!
Assert(alloced == allocAmount))
1771 {
1773 }
1774
1775 if (!
Assert(instances == remainingAmount))
1776 {
1778 }
1779
1781 }
1782
1783
1784
1786 {
1787
1790
1791
1793
1794
1798 float timeProfiled = postTime - previousTime;
1799 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1800
1804 float timeProfiled2 = postTime2 - previousTime2;
1805 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1806
1807 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1808
1809
1811 if (!wasEnabled)
1812 {
1814 }
1815
1816
1817 if (!
Assert(postTime > 0))
1818 {
1820 }
1821
1822 if (!
Assert(diff < 0.001))
1823 {
1825 }
1826
1827 if (!
Assert(postTime2 > 0))
1828 {
1830 }
1831
1832 if (!
Assert(diff2 < 0.001))
1833 {
1835 }
1836
1837
1838 if (!
Assert(timeProfiled < timeProfiled2))
1839 {
1841 }
1842
1844 }
1845
1846
1847
1849 {
1850
1852
1853
1854
1855
1859
1860 int callCountCF = postCountCF - previousCountCF;
1861
1862
1866
1867 int callCountCFP = postCountCFP - previousCountCFP;
1868
1869
1873
1874 int callCountRG = postCountRG - previousCountRG;
1875
1876
1880
1881 int callCountC = postCountC - previousCountC;
1882
1883
1885
1886
1890
1891 int callCountS = postCountS - previousCountS;
1892
1893
1897
1898 int callCountG = postCountG - previousCountG;
1899
1900
1901
1904
1905
1906
1908
1909
1910
1913
1914
1915
1918
1919
1920
1923
1924
1925 if (!wasEnabled)
1926 {
1928 }
1929
1930
1931
1932
1933 if (!
Assert(callCountCF == 1))
1934 {
1936 }
1937
1938
1939 if (!
Assert(callCountCFP == 1))
1940 {
1942 }
1943
1944
1945 if (!
Assert(callCountRG == 1))
1946 {
1948 }
1949
1950
1951 if (!
Assert(callCountC == 1))
1952 {
1954 }
1955
1956
1957 if (!
Assert(callCountNon == -1))
1958 {
1960 }
1961
1962
1963 if (!
Assert(callCountS == 1))
1964 {
1966 }
1967
1968
1969 if (!
Assert(callCountG == 1))
1970 {
1972 }
1973
1974
1975 if (!
Assert(callCountGP == 0))
1976 {
1978 }
1979
1980
1981 if (!
Assert(callCountSP == 0))
1982 {
1984 }
1985
1986
1987 if (!
Assert(callCountP == 0))
1988 {
1990 }
1991
1992
1993 if (!
Assert(callCountPN == 0))
1994 {
1996 }
1997
1998
1999 if (!
Assert(callCountSPN == 0))
2000 {
2002 }
2003
2005 }
2006
2007
2008
2009
2010
2011 float Sleep(
float timeS)
2012 {
2014 while (
GetGame().GetTickTime() - startTime < timeS)
2015 {
2016
2017 }
2018
2020 }
2021
2022
2023
2025 {
2027
2028 for (int i = 0; i < 1000; ++i)
2029 {
2030 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
2031 }
2032
2034 }
2035
2036
2037
2039 {
2041
2042 for (int i = 0; i < 1000; ++i)
2043 {
2044 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
2045 }
2046
2048 }
2049
2050
2051
2053 {
2054 int dummy = 3;
2055 }
2056
2057
2058
2060 {
2061 int dummy = 3;
2062 }
2063}
2064
2065class EPTHelperClass
2066{
2067 float Sleep2(
float timeS)
2068 {
2070 while (
GetGame().GetTickTime() - startTime < timeS)
2071 {
2072
2073 }
2074
2076 }
2078 {
2080 while (
GetGame().GetTickTime() - startTime < timeS)
2081 {
2082
2083 }
2084
2086 }
2087
2089 {
2091
2094
2096 }
2097}
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.