1469{
1472
1473
1474
1475
1477 {
1479
1490 }
1491
1492
1493
1494
1496 {
1498 }
1499
1500
1501
1502
1503
1505 {
1509 {
1512 }
1513
1515 }
1516
1517
1518
1520 {
1524 {
1527 }
1528
1530 }
1531
1532
1533
1535 {
1537
1539 {
1542
1544 {
1547 }
1548
1550 {
1553
1555 {
1558 }
1559 }
1560 }
1561
1562
1566 if (!
Assert(bogusFlags == 0))
1567 {
1570 }
1571
1574 if (!
Assert(bogusFlags == 0))
1575 {
1578 }
1579
1580
1583 }
1584
1585
1586
1588 {
1590
1592
1594 {
1597 }
1598
1601
1603 {
1606 }
1607
1610
1612 {
1615 }
1616
1617
1620 }
1621
1622
1623
1625 {
1627
1629
1630
1632 {
1635 }
1636
1638 {
1641 }
1642
1644 {
1647 }
1648
1649
1652 }
1653
1654
1655
1657 {
1658
1660
1661
1662 string nameOfCurrentModule =
Type().GetModule();
1663 if (!
Assert(nameOfCurrentModule !=
""))
1664 {
1666 }
1667
1668
1671 {
1673 }
1674
1675 if (!
Assert(currentModule == eptModule))
1676 {
1678 }
1679
1680
1683
1685 {
1688 }
1689
1690
1693
1694
1695
1697
1698
1701
1702
1704 float timeSlept =
Sleep(0.3);
1706 float diff = postTime - previousTime - timeSlept;
1707
1708
1710
1711
1712 if (!
Assert(postTime > 0))
1713 {
1715
1716 if (!wasEnabled)
1718
1720
1722 }
1723
1724 if (!
Assert(diff < 0.00001))
1725 {
1727
1728 if (!wasEnabled)
1730
1732
1734 }
1735
1736
1738
1739
1740 for (int i = 0; i < 1000; ++i)
1741 {
1743 }
1744
1745
1749
1750 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1751
1752 int funcCount = timePerFunc.Count();
1753 for (int j = 0; j < funcCount; ++j)
1754 {
1756 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1757
1758 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1759 {
1761
1762 if (!wasEnabled)
1764
1766
1768 }
1769 }
1770
1773
1774 int classCount = timePerClass.Count();
1775 for (int k = 0; k < classCount; ++k)
1776 {
1777 typename type = timePerClass[k].param2;
1780 {
1782
1783 if (!wasEnabled)
1785
1787
1789 }
1790
1791
1792 if (!
Assert(classModule == eptModule))
1793 {
1795
1796 if (!wasEnabled)
1798
1800
1802 }
1803 }
1804
1805
1808 timePerFunc.Clear();
1810
1811 bool found = false;
1812
1813 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1814
1815 funcCount = timePerFunc.Count();
1816 for (int l = 0; l < funcCount; ++l)
1817 {
1819 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1820
1821 if (tfpc.param2 == "EnumTools::StringToEnum")
1822 {
1823 found = true;
1824 break;
1825 }
1826 }
1827
1829
1830
1836
1839
1840 if (!wasEnabled)
1842
1843 return BTFR(success && found);
1844 }
1845
1846
1847
1849 {
1850
1853
1854
1856
1857
1858 EPTHelperClass clss = new EPTHelperClass();
1859
1860
1862 float timeStressed = clss.DoEverything();
1865 float timeProfiled = postTime - previousTime;
1866 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1867
1868 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1869
1870
1872 if (!wasEnabled)
1874
1875
1876 if (!
Assert(postTime > 0))
1877 {
1879 }
1880
1881 if (!
Assert(postTime == postTimeStatic))
1882 {
1884 }
1885
1886 if (!
Assert(diff < 0.001))
1887 {
1889 }
1890
1892 }
1893
1894
1895
1897 {
1898 const int allocAmount = 9;
1899 const int releaseAmount = 6;
1900 int remainingAmount = allocAmount - releaseAmount;
1901
1902
1904
1905
1908
1910 for (int i = 0; i < allocAmount; ++i)
1911 {
1912 instanceArr.Insert(new EPTHelperClass());
1913 }
1914
1915 for (int j = 0; j < releaseAmount; ++j)
1916 {
1917 delete instanceArr[j];
1918 }
1919
1922
1923 int alloced = postAlloc - previousAlloc;
1924 int instances = postInstances - previousInstances;
1925
1926 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1927
1928
1929 if (!wasEnabled)
1931
1932
1933 if (!
Assert(alloced == allocAmount))
1934 {
1936 }
1937
1938 if (!
Assert(instances == remainingAmount))
1939 {
1941 }
1942
1944 }
1945
1946
1947
1949 {
1950
1953
1954
1956
1957
1961 float timeProfiled = postTime - previousTime;
1962 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1963
1967 float timeProfiled2 = postTime2 - previousTime2;
1968 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1969
1970 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1971
1972
1974 if (!wasEnabled)
1975 {
1977 }
1978
1979
1980 if (!
Assert(postTime > 0))
1981 {
1983 }
1984
1985 if (!
Assert(diff < 0.001))
1986 {
1988 }
1989
1990 if (!
Assert(postTime2 > 0))
1991 {
1993 }
1994
1995 if (!
Assert(diff2 < 0.001))
1996 {
1998 }
1999
2000
2001 if (!
Assert(timeProfiled < timeProfiled2))
2002 {
2004 }
2005
2007 }
2008
2009
2010
2012 {
2013
2015
2016
2017
2018
2022
2023 int callCountCF = postCountCF - previousCountCF;
2024
2025
2029
2030 int callCountCFP = postCountCFP - previousCountCFP;
2031
2032
2036
2037 int callCountRG = postCountRG - previousCountRG;
2038
2039
2043
2044 int callCountC = postCountC - previousCountC;
2045
2046
2048
2049
2053
2054 int callCountS = postCountS - previousCountS;
2055
2056
2060
2061 int callCountG = postCountG - previousCountG;
2062
2063
2064
2067
2068
2069
2071
2072
2073
2076
2077
2078
2081
2082
2083
2086
2087
2088 if (!wasEnabled)
2089 {
2091 }
2092
2093
2094
2095
2096 if (!
Assert(callCountCF == 1))
2097 {
2099 }
2100
2101
2102 if (!
Assert(callCountCFP == 1))
2103 {
2105 }
2106
2107
2108 if (!
Assert(callCountRG == 1))
2109 {
2111 }
2112
2113
2114 if (!
Assert(callCountC == 1))
2115 {
2117 }
2118
2119
2120 if (!
Assert(callCountNon == -1))
2121 {
2123 }
2124
2125
2126 if (!
Assert(callCountS == 1))
2127 {
2129 }
2130
2131
2132 if (!
Assert(callCountG == 1))
2133 {
2135 }
2136
2137
2138 if (!
Assert(callCountGP == 0))
2139 {
2141 }
2142
2143
2144 if (!
Assert(callCountSP == 0))
2145 {
2147 }
2148
2149
2150 if (!
Assert(callCountP == 0))
2151 {
2153 }
2154
2155
2156 if (!
Assert(callCountPN == 0))
2157 {
2159 }
2160
2161
2162 if (!
Assert(callCountSPN == 0))
2163 {
2165 }
2166
2168 }
2169
2170
2171
2172
2173
2174 float Sleep(
float timeS)
2175 {
2177 while (
GetGame().GetTickTime() - startTime < timeS)
2178 {
2179
2180 }
2181
2183 }
2184
2185
2186
2188 {
2190
2191 for (int i = 0; i < 1000; ++i)
2192 {
2193 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
2194 }
2195
2197 }
2198
2199
2200
2202 {
2204
2205 for (int i = 0; i < 1000; ++i)
2206 {
2207 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
2208 }
2209
2211 }
2212
2213
2214
2216 {
2217 int dummy = 3;
2218 }
2219
2220
2221
2223 {
2224 int dummy = 3;
2225 }
2226}
2227
2228class EPTHelperClass
2229{
2230 float Sleep2(
float timeS)
2231 {
2233 while (
GetGame().GetTickTime() - startTime < timeS)
2234 {
2235
2236 }
2237
2239 }
2241 {
2243 while (
GetGame().GetTickTime() - startTime < timeS)
2244 {
2245
2246 }
2247
2249 }
2250
2252 {
2254
2257
2259 }
2260}
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.