1482{
1485
1486
1487
1488
1490 {
1492
1503 }
1504
1505
1506
1507
1509 {
1511 }
1512
1513
1514
1515
1516
1518 {
1522 {
1525 }
1526
1528 }
1529
1530
1531
1533 {
1537 {
1540 }
1541
1543 }
1544
1545
1546
1548 {
1550
1552 {
1555
1557 {
1560 }
1561
1563 {
1566
1568 {
1571 }
1572 }
1573 }
1574
1575
1579 if (!
Assert(bogusFlags == 0))
1580 {
1583 }
1584
1587 if (!
Assert(bogusFlags == 0))
1588 {
1591 }
1592
1593
1596 }
1597
1598
1599
1601 {
1603
1605
1607 {
1610 }
1611
1614
1616 {
1619 }
1620
1623
1625 {
1628 }
1629
1630
1633 }
1634
1635
1636
1638 {
1640
1642
1643
1645 {
1648 }
1649
1651 {
1654 }
1655
1657 {
1660 }
1661
1662
1665 }
1666
1667
1668
1670 {
1671
1673
1674
1675 string nameOfCurrentModule =
Type().GetModule();
1676 if (!
Assert(nameOfCurrentModule !=
""))
1677 {
1679 }
1680
1681
1684 {
1686 }
1687
1688 if (!
Assert(currentModule == eptModule))
1689 {
1691 }
1692
1693
1696
1698 {
1701 }
1702
1703
1706
1707
1708
1710
1711
1714
1715
1717 float timeSlept =
Sleep(0.3);
1719 float diff = postTime - previousTime - timeSlept;
1720
1721
1723
1724
1725 if (!
Assert(postTime > 0))
1726 {
1728
1729 if (!wasEnabled)
1731
1733
1735 }
1736
1737 if (!
Assert(diff < 0.00001))
1738 {
1740
1741 if (!wasEnabled)
1743
1745
1747 }
1748
1749
1751
1752
1753 for (int i = 0; i < 1000; ++i)
1754 {
1756 }
1757
1758
1762
1763 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1764
1765 int funcCount = timePerFunc.Count();
1766 for (int j = 0; j < funcCount; ++j)
1767 {
1769 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1770
1771 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1772 {
1774
1775 if (!wasEnabled)
1777
1779
1781 }
1782 }
1783
1786
1787 int classCount = timePerClass.Count();
1788 for (int k = 0; k < classCount; ++k)
1789 {
1790 typename type = timePerClass[k].param2;
1793 {
1795
1796 if (!wasEnabled)
1798
1800
1802 }
1803
1804
1805 if (!
Assert(classModule == eptModule))
1806 {
1808
1809 if (!wasEnabled)
1811
1813
1815 }
1816 }
1817
1818
1821 timePerFunc.Clear();
1823
1824 bool found = false;
1825
1826 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1827
1828 funcCount = timePerFunc.Count();
1829 for (int l = 0; l < funcCount; ++l)
1830 {
1832 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1833
1834 if (tfpc.param2 == "EnumTools::StringToEnum")
1835 {
1836 found = true;
1837 break;
1838 }
1839 }
1840
1842
1843
1849
1852
1853 if (!wasEnabled)
1855
1856 return BTFR(success && found);
1857 }
1858
1859
1860
1862 {
1863
1866
1867
1869
1870
1871 EPTHelperClass clss = new EPTHelperClass();
1872
1873
1875 float timeStressed = clss.DoEverything();
1878 float timeProfiled = postTime - previousTime;
1879 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1880
1881 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1882
1883
1885 if (!wasEnabled)
1887
1888
1889 if (!
Assert(postTime > 0))
1890 {
1892 }
1893
1894 if (!
Assert(postTime == postTimeStatic))
1895 {
1897 }
1898
1899 if (!
Assert(diff < 0.001))
1900 {
1902 }
1903
1905 }
1906
1907
1908
1910 {
1911 const int allocAmount = 9;
1912 const int releaseAmount = 6;
1913 int remainingAmount = allocAmount - releaseAmount;
1914
1915
1917
1918
1921
1923 for (int i = 0; i < allocAmount; ++i)
1924 {
1925 instanceArr.Insert(new EPTHelperClass());
1926 }
1927
1928 for (int j = 0; j < releaseAmount; ++j)
1929 {
1930 delete instanceArr[j];
1931 }
1932
1935
1936 int alloced = postAlloc - previousAlloc;
1937 int instances = postInstances - previousInstances;
1938
1939 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1940
1941
1942 if (!wasEnabled)
1944
1945
1946 if (!
Assert(alloced == allocAmount))
1947 {
1949 }
1950
1951 if (!
Assert(instances == remainingAmount))
1952 {
1954 }
1955
1957 }
1958
1959
1960
1962 {
1963
1966
1967
1969
1970
1974 float timeProfiled = postTime - previousTime;
1975 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1976
1980 float timeProfiled2 = postTime2 - previousTime2;
1981 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1982
1983 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1984
1985
1987 if (!wasEnabled)
1988 {
1990 }
1991
1992
1993 if (!
Assert(postTime > 0))
1994 {
1996 }
1997
1998 if (!
Assert(diff < 0.001))
1999 {
2001 }
2002
2003 if (!
Assert(postTime2 > 0))
2004 {
2006 }
2007
2008 if (!
Assert(diff2 < 0.001))
2009 {
2011 }
2012
2013
2014 if (!
Assert(timeProfiled < timeProfiled2))
2015 {
2017 }
2018
2020 }
2021
2022
2023
2025 {
2026
2028
2029
2030
2031
2035
2036 int callCountCF = postCountCF - previousCountCF;
2037
2038
2042
2043 int callCountCFP = postCountCFP - previousCountCFP;
2044
2045
2049
2050 int callCountRG = postCountRG - previousCountRG;
2051
2052
2056
2057 int callCountC = postCountC - previousCountC;
2058
2059
2061
2062
2066
2067 int callCountS = postCountS - previousCountS;
2068
2069
2073
2074 int callCountG = postCountG - previousCountG;
2075
2076
2077
2080
2081
2082
2084
2085
2086
2089
2090
2091
2094
2095
2096
2099
2100
2101 if (!wasEnabled)
2102 {
2104 }
2105
2106
2107
2108
2109 if (!
Assert(callCountCF == 1))
2110 {
2112 }
2113
2114
2115 if (!
Assert(callCountCFP == 1))
2116 {
2118 }
2119
2120
2121 if (!
Assert(callCountRG == 1))
2122 {
2124 }
2125
2126
2127 if (!
Assert(callCountC == 1))
2128 {
2130 }
2131
2132
2133 if (!
Assert(callCountNon == -1))
2134 {
2136 }
2137
2138
2139 if (!
Assert(callCountS == 1))
2140 {
2142 }
2143
2144
2145 if (!
Assert(callCountG == 1))
2146 {
2148 }
2149
2150
2151 if (!
Assert(callCountGP == 0))
2152 {
2154 }
2155
2156
2157 if (!
Assert(callCountSP == 0))
2158 {
2160 }
2161
2162
2163 if (!
Assert(callCountP == 0))
2164 {
2166 }
2167
2168
2169 if (!
Assert(callCountPN == 0))
2170 {
2172 }
2173
2174
2175 if (!
Assert(callCountSPN == 0))
2176 {
2178 }
2179
2181 }
2182
2183
2184
2185
2186
2187 float Sleep(
float timeS)
2188 {
2190 while (
GetGame().GetTickTime() - startTime < timeS)
2191 {
2192
2193 }
2194
2196 }
2197
2198
2199
2201 {
2203
2204 for (int i = 0; i < 1000; ++i)
2205 {
2206 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
2207 }
2208
2210 }
2211
2212
2213
2215 {
2217
2218 for (int i = 0; i < 1000; ++i)
2219 {
2220 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
2221 }
2222
2224 }
2225
2226
2227
2229 {
2230 int dummy = 3;
2231 }
2232
2233
2234
2236 {
2237 int dummy = 3;
2238 }
2239}
2240
2241class EPTHelperClass
2242{
2243 float Sleep2(
float timeS)
2244 {
2246 while (
GetGame().GetTickTime() - startTime < timeS)
2247 {
2248
2249 }
2250
2252 }
2254 {
2256 while (
GetGame().GetTickTime() - startTime < timeS)
2257 {
2258
2259 }
2260
2262 }
2263
2265 {
2267
2270
2272 }
2273}
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.