1517{
1520
1521
1522
1523
1525 {
1527
1538 }
1539
1540
1541
1542
1544 {
1546 }
1547
1548
1549
1550
1551
1553 {
1557 {
1560 }
1561
1563 }
1564
1565
1566
1568 {
1572 {
1575 }
1576
1578 }
1579
1580
1581
1583 {
1585
1587 {
1590
1592 {
1595 }
1596
1598 {
1601
1603 {
1606 }
1607 }
1608 }
1609
1610
1614 if (!
Assert(bogusFlags == 0))
1615 {
1618 }
1619
1622 if (!
Assert(bogusFlags == 0))
1623 {
1626 }
1627
1628
1631 }
1632
1633
1634
1636 {
1638
1640
1642 {
1645 }
1646
1649
1651 {
1654 }
1655
1658
1660 {
1663 }
1664
1665
1668 }
1669
1670
1671
1673 {
1675
1677
1678
1680 {
1683 }
1684
1686 {
1689 }
1690
1692 {
1695 }
1696
1697
1700 }
1701
1702
1703
1705 {
1706
1708
1709
1710 string nameOfCurrentModule =
Type().GetModule();
1711 if (!
Assert(nameOfCurrentModule !=
""))
1712 {
1714 }
1715
1716
1719 {
1721 }
1722
1723 if (!
Assert(currentModule == eptModule))
1724 {
1726 }
1727
1728
1731
1733 {
1736 }
1737
1738
1741
1742
1743
1745
1746
1749
1750
1752 float timeSlept =
Sleep(0.3);
1754 float diff = postTime - previousTime - timeSlept;
1755
1756
1758
1759
1760 if (!
Assert(postTime > 0))
1761 {
1763
1764 if (!wasEnabled)
1766
1768
1770 }
1771
1772 if (!
Assert(diff < 0.00001))
1773 {
1775
1776 if (!wasEnabled)
1778
1780
1782 }
1783
1784
1786
1787
1788 for (int i = 0; i < 1000; ++i)
1789 {
1791 }
1792
1793
1797
1798 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1799
1800 int funcCount = timePerFunc.Count();
1801 for (int j = 0; j < funcCount; ++j)
1802 {
1804 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1805
1806 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1807 {
1809
1810 if (!wasEnabled)
1812
1814
1816 }
1817 }
1818
1821
1822 int classCount = timePerClass.Count();
1823 for (int k = 0; k < classCount; ++k)
1824 {
1825 typename type = timePerClass[k].param2;
1828 {
1830
1831 if (!wasEnabled)
1833
1835
1837 }
1838
1839
1840 if (!
Assert(classModule == eptModule))
1841 {
1843
1844 if (!wasEnabled)
1846
1848
1850 }
1851 }
1852
1853
1856 timePerFunc.Clear();
1858
1859 bool found = false;
1860
1861 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1862
1863 funcCount = timePerFunc.Count();
1864 for (int l = 0; l < funcCount; ++l)
1865 {
1867 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1868
1869 if (tfpc.param2 == "EnumTools::StringToEnum")
1870 {
1871 found = true;
1872 break;
1873 }
1874 }
1875
1877
1878
1884
1887
1888 if (!wasEnabled)
1890
1891 return BTFR(success && found);
1892 }
1893
1894
1895
1897 {
1898
1901
1902
1904
1905
1906 EPTHelperClass clss = new EPTHelperClass();
1907
1908
1910 float timeStressed = clss.DoEverything();
1913 float timeProfiled = postTime - previousTime;
1914 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1915
1916 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1917
1918
1920 if (!wasEnabled)
1922
1923
1924 if (!
Assert(postTime > 0))
1925 {
1927 }
1928
1929 if (!
Assert(postTime == postTimeStatic))
1930 {
1932 }
1933
1934 if (!
Assert(diff < 0.001))
1935 {
1937 }
1938
1940 }
1941
1942
1943
1945 {
1946 const int allocAmount = 9;
1947 const int releaseAmount = 6;
1948 int remainingAmount = allocAmount - releaseAmount;
1949
1950
1952
1953
1956
1958 for (int i = 0; i < allocAmount; ++i)
1959 {
1960 instanceArr.Insert(new EPTHelperClass());
1961 }
1962
1963 for (int j = 0; j < releaseAmount; ++j)
1964 {
1965 delete instanceArr[j];
1966 }
1967
1970
1971 int alloced = postAlloc - previousAlloc;
1972 int instances = postInstances - previousInstances;
1973
1974 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1975
1976
1977 if (!wasEnabled)
1979
1980
1981 if (!
Assert(alloced == allocAmount))
1982 {
1984 }
1985
1986 if (!
Assert(instances == remainingAmount))
1987 {
1989 }
1990
1992 }
1993
1994
1995
1997 {
1998
2001
2002
2004
2005
2009 float timeProfiled = postTime - previousTime;
2010 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
2011
2015 float timeProfiled2 = postTime2 - previousTime2;
2016 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
2017
2018 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
2019
2020
2022 if (!wasEnabled)
2023 {
2025 }
2026
2027
2028 if (!
Assert(postTime > 0))
2029 {
2031 }
2032
2033 if (!
Assert(diff < 0.001))
2034 {
2036 }
2037
2038 if (!
Assert(postTime2 > 0))
2039 {
2041 }
2042
2043 if (!
Assert(diff2 < 0.001))
2044 {
2046 }
2047
2048
2049 if (!
Assert(timeProfiled < timeProfiled2))
2050 {
2052 }
2053
2055 }
2056
2057
2058
2060 {
2061
2063
2064
2065
2066
2070
2071 int callCountCF = postCountCF - previousCountCF;
2072
2073
2077
2078 int callCountCFP = postCountCFP - previousCountCFP;
2079
2080
2084
2085 int callCountRG = postCountRG - previousCountRG;
2086
2087
2091
2092 int callCountC = postCountC - previousCountC;
2093
2094
2096
2097
2101
2102 int callCountS = postCountS - previousCountS;
2103
2104
2108
2109 int callCountG = postCountG - previousCountG;
2110
2111
2112
2115
2116
2117
2119
2120
2121
2124
2125
2126
2129
2130
2131
2134
2135
2136 if (!wasEnabled)
2137 {
2139 }
2140
2141
2142
2143
2144 if (!
Assert(callCountCF == 1))
2145 {
2147 }
2148
2149
2150 if (!
Assert(callCountCFP == 1))
2151 {
2153 }
2154
2155
2156 if (!
Assert(callCountRG == 1))
2157 {
2159 }
2160
2161
2162 if (!
Assert(callCountC == 1))
2163 {
2165 }
2166
2167
2168 if (!
Assert(callCountNon == -1))
2169 {
2171 }
2172
2173
2174 if (!
Assert(callCountS == 1))
2175 {
2177 }
2178
2179
2180 if (!
Assert(callCountG == 1))
2181 {
2183 }
2184
2185
2186 if (!
Assert(callCountGP == 0))
2187 {
2189 }
2190
2191
2192 if (!
Assert(callCountSP == 0))
2193 {
2195 }
2196
2197
2198 if (!
Assert(callCountP == 0))
2199 {
2201 }
2202
2203
2204 if (!
Assert(callCountPN == 0))
2205 {
2207 }
2208
2209
2210 if (!
Assert(callCountSPN == 0))
2211 {
2213 }
2214
2216 }
2217
2218
2219
2220
2221
2222 float Sleep(
float timeS)
2223 {
2225 while (
GetGame().GetTickTime() - startTime < timeS)
2226 {
2227
2228 }
2229
2231 }
2232
2233
2234
2236 {
2238
2239 for (int i = 0; i < 1000; ++i)
2240 {
2241 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
2242 }
2243
2245 }
2246
2247
2248
2250 {
2252
2253 for (int i = 0; i < 1000; ++i)
2254 {
2255 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
2256 }
2257
2259 }
2260
2261
2262
2264 {
2265 int dummy = 3;
2266 }
2267
2268
2269
2271 {
2272 int dummy = 3;
2273 }
2274}
2275
2276class EPTHelperClass
2277{
2278 float Sleep2(
float timeS)
2279 {
2281 while (
GetGame().GetTickTime() - startTime < timeS)
2282 {
2283
2284 }
2285
2287 }
2289 {
2291 while (
GetGame().GetTickTime() - startTime < timeS)
2292 {
2293
2294 }
2295
2297 }
2298
2300 {
2302
2305
2307 }
2308}
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.