1496{
 1499    
 1500    
 1501    
 1502    
 1504    {
 1506        
 1517    }
 1518    
 1519    
 1520    
 1521    
 1523    {
 1525    }
 1526    
 1527    
 1528    
 1529    
 1530    
 1532    {
 1536        {
 1539        }
 1540        
 1542    }
 1543    
 1544    
 1545    
 1547    {
 1551        {
 1554        }
 1555        
 1557    }
 1558    
 1559    
 1560    
 1562    {
 1564        
 1566        {
 1569            
 1571            {
 1574            }
 1575            
 1577            {
 1580                
 1582                {
 1585                }
 1586            }
 1587        }
 1588        
 1589        
 1593        if (!
Assert(bogusFlags == 0))
 
 1594        {
 1597        }
 1598        
 1601        if (!
Assert(bogusFlags == 0))
 
 1602        {
 1605        }
 1606        
 1607        
 1610    }
 1611    
 1612    
 1613    
 1615    {
 1617                        
 1619        
 1621        {
 1624        }
 1625        
 1628        
 1630        {
 1633        }
 1634        
 1637        
 1639        {
 1642        }
 1643        
 1644        
 1647    }
 1648    
 1649    
 1650    
 1652    {
 1654                        
 1656        
 1657        
 1659        {
 1662        }
 1663        
 1665        {
 1668        }
 1669        
 1671        {
 1674        }
 1675        
 1676        
 1679    }
 1680    
 1681    
 1682    
 1684    {
 1685        
 1687        
 1688        
 1689        string nameOfCurrentModule = 
Type().GetModule();
 
 1690        if (!
Assert(nameOfCurrentModule != 
""))
 
 1691        {
 1693        }
 1694        
 1695        
 1698        {
 1700        }
 1701        
 1702        if (!
Assert(currentModule == eptModule))
 
 1703        {
 1705        }
 1706        
 1707        
 1710        
 1712        {
 1715        }
 1716        
 1717        
 1720        
 1721        
 1722        
 1724        
 1725        
 1728        
 1729        
 1731        float timeSlept = 
Sleep(0.3);
 
 1733        float diff = postTime - previousTime - timeSlept;
 1734        
 1735        
 1737        
 1738        
 1739        if (!
Assert(postTime > 0))
 
 1740        {
 1742            
 1743            if (!wasEnabled)
 1745            
 1747            
 1749        }
 1750        
 1751        if (!
Assert(diff < 0.00001))
 
 1752        {
 1754            
 1755            if (!wasEnabled)
 1757            
 1759            
 1761        }
 1762        
 1763        
 1765        
 1766        
 1767        for (int i = 0; i < 1000; ++i)
 1768        {
 1770        }
 1771        
 1772        
 1776        
 1777        Debug.
TFLog(
"Game fncs:", 
this, 
"TestModule");
 
 1778        
 1779        int funcCount = timePerFunc.Count();
 1780        for (int j = 0; j < funcCount; ++j)
 1781        {
 1783            Debug.
TFLog(
string.Format(
"   time: %1 | fnc: %2", tfp.param1, tfp.param2), 
this, 
"TestModule");
 
 1784            
 1785            if (!
Assert(tfp.param2 != 
"EnumTools::StringToEnum"))
 
 1786            {
 1788                
 1789                if (!wasEnabled)
 1791                
 1793                
 1795            }
 1796        }
 1797        
 1800        
 1801        int classCount = timePerClass.Count();
 1802        for (int k = 0; k < classCount; ++k)
 1803        {
 1804            typename type = timePerClass[k].param2;
 1807            {
 1809                
 1810                if (!wasEnabled)
 1812                
 1814                
 1816            }
 1817            
 1818            
 1819            if (!
Assert(classModule == eptModule))
 
 1820            {
 1822                
 1823                if (!wasEnabled)
 1825                
 1827                
 1829            }
 1830        }
 1831        
 1832        
 1835        timePerFunc.Clear(); 
 1837        
 1838        bool found = false;
 1839        
 1840        Debug.
TFLog(
"Core fncs:", 
this, 
"TestModule");
 
 1841        
 1842        funcCount = timePerFunc.Count();
 1843        for (int l = 0; l < funcCount; ++l)
 1844        {
 1846            Debug.
TFLog(
string.Format(
"   time: %1 | fnc: %2", tfpc.param1, tfpc.param2), 
this, 
"TestModule");
 
 1847            
 1848            if (tfpc.param2 == "EnumTools::StringToEnum")
 1849            {
 1850                found = true;
 1851                break;
 1852            }
 1853        }
 1854        
 1856        
 1857        
 1863        
 1866        
 1867        if (!wasEnabled)
 1869        
 1870        return BTFR(success && found);
 
 1871    }
 1872    
 1873    
 1874    
 1876    {
 1877        
 1880        
 1881        
 1883        
 1884        
 1885        EPTHelperClass clss = new EPTHelperClass();
 1886        
 1887        
 1889        float timeStressed = clss.DoEverything();
 1892        float timeProfiled = postTime - previousTime;
 1893        float diff = 
Math.
AbsFloat(timeProfiled - timeStressed);
 
 1894        
 1895        Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff), 
this, 
"TestClassTimeData");
 
 1896        
 1897        
 1899        if (!wasEnabled)
 1901        
 1902        
 1903        if (!
Assert(postTime > 0))
 
 1904        {
 1906        }
 1907        
 1908        if (!
Assert(postTime == postTimeStatic))
 
 1909        {
 1911        }
 1912        
 1913        if (!
Assert(diff < 0.001))
 
 1914        {
 1916        }
 1917        
 1919    }
 1920    
 1921    
 1922    
 1924    {
 1925        const int allocAmount = 9;
 1926        const int releaseAmount = 6;
 1927        int remainingAmount = allocAmount - releaseAmount;
 1928        
 1929        
 1931        
 1932        
 1935 
 1937        for (int i = 0; i < allocAmount; ++i)
 1938        {
 1939            instanceArr.Insert(new EPTHelperClass());
 1940        }
 1941        
 1942        for (int j = 0; j < releaseAmount; ++j)
 1943        {
 1944            delete instanceArr[j];
 1945        }
 1946        
 1949        
 1950        int alloced = postAlloc - previousAlloc;
 1951        int instances = postInstances - previousInstances;
 1952        
 1953        Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances), 
this, 
"TestClassCountData");
 
 1954        
 1955        
 1956        if (!wasEnabled)
 1958        
 1959        
 1960        if (!
Assert(alloced == allocAmount))
 
 1961        {
 1963        }
 1964        
 1965        if (!
Assert(instances == remainingAmount))
 
 1966        {
 1968        }
 1969        
 1971    }
 1972    
 1973    
 1974    
 1976    {
 1977        
 1980        
 1981        
 1983        
 1984        
 1988        float timeProfiled = postTime - previousTime;
 1989        float diff = 
Math.
AbsFloat(timeProfiled - timeStressed);
 
 1990        
 1994        float timeProfiled2 = postTime2 - previousTime2;
 1995        float diff2 = 
Math.
AbsFloat(timeProfiled2 - timeStressed2);
 
 1996        
 1997        Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2), 
this, 
"TestFuncTimeData");
 
 1998        
 1999        
 2001        if (!wasEnabled)
 2002        {
 2004        }
 2005        
 2006        
 2007        if (!
Assert(postTime > 0))
 
 2008        {
 2010        }
 2011        
 2012        if (!
Assert(diff < 0.001))
 
 2013        {
 2015        }
 2016        
 2017        if (!
Assert(postTime2 > 0))
 
 2018        {
 2020        }
 2021        
 2022        if (!
Assert(diff2 < 0.001))
 
 2023        {
 2025        }
 2026        
 2027        
 2028        if (!
Assert(timeProfiled < timeProfiled2))
 
 2029        {
 2031        }
 2032        
 2034    }
 2035    
 2036    
 2037    
 2039    {
 2040        
 2042        
 2043        
 2044        
 2045        
 2049        
 2050        int callCountCF = postCountCF - previousCountCF;
 2051        
 2052        
 2056        
 2057        int callCountCFP = postCountCFP - previousCountCFP;
 2058        
 2059        
 2063        
 2064        int callCountRG = postCountRG - previousCountRG;
 2065        
 2066        
 2070        
 2071        int callCountC = postCountC - previousCountC;
 2072        
 2073        
 2075        
 2076        
 2080        
 2081        int callCountS = postCountS - previousCountS;
 2082        
 2083        
 2087    
 2088        int callCountG = postCountG - previousCountG;
 2089        
 2090        
 2091        
 2094        
 2095        
 2096        
 2098        
 2099        
 2100        
 2103        
 2104        
 2105        
 2108        
 2109        
 2110        
 2113        
 2114        
 2115        if (!wasEnabled)
 2116        {
 2118        }
 2119        
 2120        
 2121        
 2122        
 2123        if (!
Assert(callCountCF == 1))
 
 2124        {
 2126        }
 2127        
 2128        
 2129        if (!
Assert(callCountCFP == 1))
 
 2130        {
 2132        }
 2133        
 2134        
 2135        if (!
Assert(callCountRG == 1))
 
 2136        {
 2138        }
 2139        
 2140        
 2141        if (!
Assert(callCountC == 1))
 
 2142        {
 2144        }
 2145        
 2146        
 2147        if (!
Assert(callCountNon == -1))
 
 2148        {
 2150        }
 2151        
 2152        
 2153        if (!
Assert(callCountS == 1))
 
 2154        {
 2156        }
 2157        
 2158        
 2159        if (!
Assert(callCountG == 1))
 
 2160        {
 2162        }
 2163        
 2164        
 2165        if (!
Assert(callCountGP == 0))
 
 2166        {
 2168        }
 2169        
 2170        
 2171        if (!
Assert(callCountSP == 0))
 
 2172        {
 2174        }
 2175        
 2176        
 2177        if (!
Assert(callCountP == 0))
 
 2178        {
 2180        }
 2181        
 2182        
 2183        if (!
Assert(callCountPN == 0))
 
 2184        {
 2186        }
 2187        
 2188        
 2189        if (!
Assert(callCountSPN == 0))
 
 2190        {
 2192        }
 2193        
 2195    }
 2196    
 2197    
 2198    
 2199    
 2200    
 2201    float Sleep(
float timeS)
 
 2202    {       
 2204        while (
GetGame().GetTickTime() - startTime < timeS)
 
 2205        {
 2206            
 2207        }       
 2208        
 2210    }
 2211    
 2212    
 2213    
 2215    {       
 2217        
 2218        for (int i = 0; i < 1000; ++i)
 2219        {
 2220            string example = 
string.Format(
"This %1 is %2 just %3 an %4 example %5", i, 
Type(), 
this, startTime, 
"lorem ipsum 1 2 3");
 
 2221        }   
 2222        
 2224    }
 2225    
 2226    
 2227    
 2229    {       
 2231        
 2232        for (int i = 0; i < 1000; ++i)
 2233        {
 2234            string example = 
"This " + i + 
" is " + 
Type() + 
" just " + 
this + 
" an " + startTime + 
" example " + 
"lorem ipsum 1 2 3";
 
 2235        }
 2236        
 2238    }
 2239    
 2240    
 2241    
 2243    {
 2244        int dummy = 3;
 2245    }
 2246    
 2247    
 2248    
 2250    {
 2251        int dummy = 3;
 2252    }
 2253}
 2254 
 2255class EPTHelperClass
 2256{
 2257    float Sleep2(
float timeS)
 
 2258    {       
 2260        while (
GetGame().GetTickTime() - startTime < timeS)
 
 2261        {
 2262            
 2263        }       
 2264        
 2266    }
 2268    {       
 2270        while (
GetGame().GetTickTime() - startTime < timeS)
 
 2271        {
 2272            
 2273        }       
 2274        
 2276    }
 2277    
 2279    {
 2281        
 2284        
 2286    }
 2287}
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.