1510{
1513
1514
1515
1516
1518 {
1520
1531 }
1532
1533
1534
1535
1537 {
1539 }
1540
1541
1542
1543
1544
1546 {
1550 {
1553 }
1554
1556 }
1557
1558
1559
1561 {
1565 {
1568 }
1569
1571 }
1572
1573
1574
1576 {
1578
1580 {
1583
1585 {
1588 }
1589
1591 {
1594
1596 {
1599 }
1600 }
1601 }
1602
1603
1607 if (!
Assert(bogusFlags == 0))
1608 {
1611 }
1612
1615 if (!
Assert(bogusFlags == 0))
1616 {
1619 }
1620
1621
1624 }
1625
1626
1627
1629 {
1631
1633
1635 {
1638 }
1639
1642
1644 {
1647 }
1648
1651
1653 {
1656 }
1657
1658
1661 }
1662
1663
1664
1666 {
1668
1670
1671
1673 {
1676 }
1677
1679 {
1682 }
1683
1685 {
1688 }
1689
1690
1693 }
1694
1695
1696
1698 {
1699
1701
1702
1703 string nameOfCurrentModule =
Type().GetModule();
1704 if (!
Assert(nameOfCurrentModule !=
""))
1705 {
1707 }
1708
1709
1712 {
1714 }
1715
1716 if (!
Assert(currentModule == eptModule))
1717 {
1719 }
1720
1721
1724
1726 {
1729 }
1730
1731
1734
1735
1736
1738
1739
1742
1743
1745 float timeSlept =
Sleep(0.3);
1747 float diff = postTime - previousTime - timeSlept;
1748
1749
1751
1752
1753 if (!
Assert(postTime > 0))
1754 {
1756
1757 if (!wasEnabled)
1759
1761
1763 }
1764
1765 if (!
Assert(diff < 0.00001))
1766 {
1768
1769 if (!wasEnabled)
1771
1773
1775 }
1776
1777
1779
1780
1781 for (int i = 0; i < 1000; ++i)
1782 {
1784 }
1785
1786
1790
1791 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1792
1793 int funcCount = timePerFunc.Count();
1794 for (int j = 0; j < funcCount; ++j)
1795 {
1797 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1798
1799 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1800 {
1802
1803 if (!wasEnabled)
1805
1807
1809 }
1810 }
1811
1814
1815 int classCount = timePerClass.Count();
1816 for (int k = 0; k < classCount; ++k)
1817 {
1818 typename type = timePerClass[k].param2;
1821 {
1823
1824 if (!wasEnabled)
1826
1828
1830 }
1831
1832
1833 if (!
Assert(classModule == eptModule))
1834 {
1836
1837 if (!wasEnabled)
1839
1841
1843 }
1844 }
1845
1846
1849 timePerFunc.Clear();
1851
1852 bool found = false;
1853
1854 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1855
1856 funcCount = timePerFunc.Count();
1857 for (int l = 0; l < funcCount; ++l)
1858 {
1860 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1861
1862 if (tfpc.param2 == "EnumTools::StringToEnum")
1863 {
1864 found = true;
1865 break;
1866 }
1867 }
1868
1870
1871
1877
1880
1881 if (!wasEnabled)
1883
1884 return BTFR(success && found);
1885 }
1886
1887
1888
1890 {
1891
1894
1895
1897
1898
1899 EPTHelperClass clss = new EPTHelperClass();
1900
1901
1903 float timeStressed = clss.DoEverything();
1906 float timeProfiled = postTime - previousTime;
1907 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1908
1909 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1910
1911
1913 if (!wasEnabled)
1915
1916
1917 if (!
Assert(postTime > 0))
1918 {
1920 }
1921
1922 if (!
Assert(postTime == postTimeStatic))
1923 {
1925 }
1926
1927 if (!
Assert(diff < 0.001))
1928 {
1930 }
1931
1933 }
1934
1935
1936
1938 {
1939 const int allocAmount = 9;
1940 const int releaseAmount = 6;
1941 int remainingAmount = allocAmount - releaseAmount;
1942
1943
1945
1946
1949
1951 for (int i = 0; i < allocAmount; ++i)
1952 {
1953 instanceArr.Insert(new EPTHelperClass());
1954 }
1955
1956 for (int j = 0; j < releaseAmount; ++j)
1957 {
1958 delete instanceArr[j];
1959 }
1960
1963
1964 int alloced = postAlloc - previousAlloc;
1965 int instances = postInstances - previousInstances;
1966
1967 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1968
1969
1970 if (!wasEnabled)
1972
1973
1974 if (!
Assert(alloced == allocAmount))
1975 {
1977 }
1978
1979 if (!
Assert(instances == remainingAmount))
1980 {
1982 }
1983
1985 }
1986
1987
1988
1990 {
1991
1994
1995
1997
1998
2002 float timeProfiled = postTime - previousTime;
2003 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
2004
2008 float timeProfiled2 = postTime2 - previousTime2;
2009 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
2010
2011 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
2012
2013
2015 if (!wasEnabled)
2016 {
2018 }
2019
2020
2021 if (!
Assert(postTime > 0))
2022 {
2024 }
2025
2026 if (!
Assert(diff < 0.001))
2027 {
2029 }
2030
2031 if (!
Assert(postTime2 > 0))
2032 {
2034 }
2035
2036 if (!
Assert(diff2 < 0.001))
2037 {
2039 }
2040
2041
2042 if (!
Assert(timeProfiled < timeProfiled2))
2043 {
2045 }
2046
2048 }
2049
2050
2051
2053 {
2054
2056
2057
2058
2059
2063
2064 int callCountCF = postCountCF - previousCountCF;
2065
2066
2070
2071 int callCountCFP = postCountCFP - previousCountCFP;
2072
2073
2077
2078 int callCountRG = postCountRG - previousCountRG;
2079
2080
2084
2085 int callCountC = postCountC - previousCountC;
2086
2087
2089
2090
2094
2095 int callCountS = postCountS - previousCountS;
2096
2097
2101
2102 int callCountG = postCountG - previousCountG;
2103
2104
2105
2108
2109
2110
2112
2113
2114
2117
2118
2119
2122
2123
2124
2127
2128
2129 if (!wasEnabled)
2130 {
2132 }
2133
2134
2135
2136
2137 if (!
Assert(callCountCF == 1))
2138 {
2140 }
2141
2142
2143 if (!
Assert(callCountCFP == 1))
2144 {
2146 }
2147
2148
2149 if (!
Assert(callCountRG == 1))
2150 {
2152 }
2153
2154
2155 if (!
Assert(callCountC == 1))
2156 {
2158 }
2159
2160
2161 if (!
Assert(callCountNon == -1))
2162 {
2164 }
2165
2166
2167 if (!
Assert(callCountS == 1))
2168 {
2170 }
2171
2172
2173 if (!
Assert(callCountG == 1))
2174 {
2176 }
2177
2178
2179 if (!
Assert(callCountGP == 0))
2180 {
2182 }
2183
2184
2185 if (!
Assert(callCountSP == 0))
2186 {
2188 }
2189
2190
2191 if (!
Assert(callCountP == 0))
2192 {
2194 }
2195
2196
2197 if (!
Assert(callCountPN == 0))
2198 {
2200 }
2201
2202
2203 if (!
Assert(callCountSPN == 0))
2204 {
2206 }
2207
2209 }
2210
2211
2212
2213
2214
2215 float Sleep(
float timeS)
2216 {
2218 while (
GetGame().GetTickTime() - startTime < timeS)
2219 {
2220
2221 }
2222
2224 }
2225
2226
2227
2229 {
2231
2232 for (int i = 0; i < 1000; ++i)
2233 {
2234 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
2235 }
2236
2238 }
2239
2240
2241
2243 {
2245
2246 for (int i = 0; i < 1000; ++i)
2247 {
2248 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
2249 }
2250
2252 }
2253
2254
2255
2257 {
2258 int dummy = 3;
2259 }
2260
2261
2262
2264 {
2265 int dummy = 3;
2266 }
2267}
2268
2269class EPTHelperClass
2270{
2271 float Sleep2(
float timeS)
2272 {
2274 while (
GetGame().GetTickTime() - startTime < timeS)
2275 {
2276
2277 }
2278
2280 }
2282 {
2284 while (
GetGame().GetTickTime() - startTime < timeS)
2285 {
2286
2287 }
2288
2290 }
2291
2293 {
2295
2298
2300 }
2301}
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.