DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ StringFormat()

float Sleep2::StringFormat ( )

См. определение в файле EnProfilerTests.c строка 1481

1482{
1485
1486 //---------------------------------------------------------------------------
1487 // Ctor - Decides the tests to run
1488 //---------------------------------------------------------------------------
1489 void EnProfilerTests()
1490 {
1492
1493 AddInitTest("TestToggling");
1494 AddInitTest("TestTogglingImmediate");
1495 AddInitTest("TestSetFlags");
1496 AddInitTest("TestClearFlags");
1497 AddInitTest("TestAddFlags");
1498 AddInitTest("TestModule");
1499 AddInitTest("TestClassTimeData");
1500 AddInitTest("TestClassCountData");
1501 AddInitTest("TestFuncTimeData");
1502 AddInitTest("TestFuncCountData");
1503 }
1504
1505 //---------------------------------------------------------------------------
1506 // Dtor
1507 //---------------------------------------------------------------------------
1508 void ~EnProfilerTests()
1509 {
1511 }
1512
1513 //---------------------------------------------------------------------------
1514 // Tests
1515 //---------------------------------------------------------------------------
1516 // Test toggling state
1518 {
1519 bool currentlyEnabled = EnProfiler.IsEnabledP();
1520 EnProfiler.Enable(!currentlyEnabled);
1521 if (Assert(currentlyEnabled != EnProfiler.IsEnabledP()))
1522 {
1523 EnProfiler.Enable(currentlyEnabled);
1524 return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledP()));
1525 }
1526
1527 return NTFR(TFR.FAIL);
1528 }
1529
1530 //---------------------------------------------------------------------------
1531 // Test toggling immediate state
1533 {
1534 bool currentlyEnabled = EnProfiler.IsEnabledC();
1535 EnProfiler.Enable(!currentlyEnabled, true);
1536 if (Assert(currentlyEnabled != EnProfiler.IsEnabledC()))
1537 {
1538 EnProfiler.Enable(currentlyEnabled, true);
1539 return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledC()));
1540 }
1541
1542 return NTFR(TFR.FAIL);
1543 }
1544
1545 //---------------------------------------------------------------------------
1546 // Test SetFlags/GetFlags
1548 {
1549 int currentFlags = EnProfiler.GetFlags();
1550
1551 for (int i = 0; i < EnumTools.GetEnumSize(EnProfilerFlags); ++i)
1552 {
1553 int flags = EnumTools.GetEnumValue(EnProfilerFlags, i);
1554 EnProfiler.SetFlags(flags);
1555
1556 if (!Assert(EnProfiler.GetFlags() == flags))
1557 {
1558 EnProfiler.SetFlags(currentFlags);
1559 return NTFR(TFR.FAIL);
1560 }
1561
1562 for (int j = 0; j < EnumTools.GetEnumSize(EnProfilerFlags); ++j)
1563 {
1565 EnProfiler.SetFlags(flags);
1566
1567 if (!Assert(EnProfiler.GetFlags() == flags))
1568 {
1569 EnProfiler.SetFlags(currentFlags);
1570 return NTFR(TFR.FAIL);
1571 }
1572 }
1573 }
1574
1575 // Let's test some bogus
1576 EnProfiler.SetFlags(-333);
1577 int bogusFlags = EnProfiler.GetFlags();
1578 bogusFlags &= ~EnProfilerFlags.ALL;
1579 if (!Assert(bogusFlags == 0))
1580 {
1581 EnProfiler.SetFlags(currentFlags);
1582 return NTFR(TFR.FAIL);
1583 }
1584
1585 bogusFlags = EnProfiler.SetFlags(6003);
1586 bogusFlags &= ~EnProfilerFlags.ALL;
1587 if (!Assert(bogusFlags == 0))
1588 {
1589 EnProfiler.SetFlags(currentFlags);
1590 return NTFR(TFR.FAIL);
1591 }
1592
1593 // Reset
1594 EnProfiler.SetFlags(currentFlags);
1595 return NTFR(TFR.SUCCESS);
1596 }
1597
1598 //---------------------------------------------------------------------------
1599 // Test removing of flags
1601 {
1602 int currentFlags = EnProfiler.GetFlags();
1603
1605
1607 {
1608 EnProfiler.SetFlags(currentFlags);
1609 return NTFR(TFR.FAIL);
1610 }
1611
1614
1615 if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
1616 {
1617 EnProfiler.SetFlags(currentFlags);
1618 return NTFR(TFR.FAIL);
1619 }
1620
1623
1624 if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
1625 {
1626 EnProfiler.SetFlags(currentFlags);
1627 return NTFR(TFR.FAIL);
1628 }
1629
1630 // Reset
1631 EnProfiler.SetFlags(currentFlags);
1632 return NTFR(TFR.SUCCESS);
1633 }
1634
1635 //---------------------------------------------------------------------------
1636 // Test adding of flags
1638 {
1639 int currentFlags = EnProfiler.GetFlags();
1640
1642
1643 // Return should match resulting flags
1645 {
1646 EnProfiler.SetFlags(currentFlags);
1647 return NTFR(TFR.FAIL);
1648 }
1649
1650 if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.RESET))
1651 {
1652 EnProfiler.SetFlags(currentFlags);
1653 return NTFR(TFR.FAIL);
1654 }
1655
1656 if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RECURSIVE) == (EnProfilerFlags.RESET | EnProfilerFlags.RECURSIVE)))
1657 {
1658 EnProfiler.SetFlags(currentFlags);
1659 return NTFR(TFR.FAIL);
1660 }
1661
1662 // Reset
1663 EnProfiler.SetFlags(currentFlags);
1664 return NTFR(TFR.SUCCESS);
1665 }
1666
1667 //---------------------------------------------------------------------------
1668 // Test module
1670 {
1671 // File lives in Game, use it while testing
1672 const EnProfilerModule eptModule = EnProfilerModule.GAME;
1673
1674 // This was added at the same time as this API, so check if it works as well
1675 string nameOfCurrentModule = Type().GetModule();
1676 if (!Assert(nameOfCurrentModule != ""))
1677 {
1678 return NTFR(TFR.FAIL);
1679 }
1680
1681 // We know we are in Game, so use it as a test
1682 EnProfilerModule currentModule;
1683 if (!Assert(EnProfiler.NameToModule(nameOfCurrentModule, currentModule)))
1684 {
1685 return NTFR(TFR.FAIL);
1686 }
1687
1688 if (!Assert(currentModule == eptModule))
1689 {
1690 return NTFR(TFR.FAIL);
1691 }
1692
1693 // Test if setting and getting works
1694 EnProfilerModule currentlyProfiledModule = EnProfiler.GetModule();
1695 EnProfiler.SetModule(eptModule);
1696
1697 if (!Assert(EnProfiler.GetModule() == eptModule))
1698 {
1699 EnProfiler.SetModule(currentlyProfiledModule);
1700 return NTFR(TFR.FAIL);
1701 }
1702
1703 // Data to restore
1704 int currentFlags = EnProfiler.GetFlags();
1705 bool wasEnabled = EnProfiler.RequestImmediateData();
1706
1707 // Make sure we are only profiling Game and that the data is clean
1708 // Only valid for the Get...Per... methods, as they need to be sorted
1710
1711 // GetTickTime() returns in seconds, so gather the results in seconds too
1712 int resolution = EnProfiler.GetTimeResolution();
1714
1715 // Time to sleeb
1716 float previousTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
1717 float timeSlept = Sleep(0.3);
1718 float postTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
1719 float diff = postTime - previousTime - timeSlept;
1720
1721 // Restore
1722 EnProfiler.SetTimeResolution(resolution);
1723
1724 // We called the function, so it must have some time
1725 if (!Assert(postTime > 0))
1726 {
1727 EnProfiler.SetFlags(currentFlags);
1728
1729 if (!wasEnabled)
1730 EnProfiler.Enable(false, true);
1731
1732 EnProfiler.SetModule(currentlyProfiledModule);
1733
1734 return NTFR(TFR.FAIL);
1735 }
1736
1737 if (!Assert(diff < 0.00001))
1738 {
1739 EnProfiler.SetFlags(currentFlags);
1740
1741 if (!wasEnabled)
1742 EnProfiler.Enable(false, true);
1743
1744 EnProfiler.SetModule(currentlyProfiledModule);
1745
1746 return NTFR(TFR.FAIL);
1747 }
1748
1749 // Clean the session
1751
1752 // Something from a different module should not get sorted, so just fire something from a different module
1753 for (int i = 0; i < 1000; ++i)
1754 {
1755 EnumTools.StringToEnum(EnProfilerModule, "MISSION_CUSTOM");
1756 }
1757
1758 // Sort and gather the data and validate if it is correct
1760 array<ref EnProfilerTimeFuncPair> timePerFunc = {};
1761 EnProfiler.GetTimePerFunc(timePerFunc);
1762
1763 Debug.TFLog("Game fncs:", this, "TestModule");
1764
1765 int funcCount = timePerFunc.Count();
1766 for (int j = 0; j < funcCount; ++j)
1767 {
1768 EnProfilerTimeFuncPair tfp = timePerFunc[j];
1769 Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfp.param1, tfp.param2), this, "TestModule");
1770 // We are currently profiling Game, so this Core function shouldn't be present
1771 if (!Assert(tfp.param2 != "EnumTools::StringToEnum"))
1772 {
1773 EnProfiler.SetFlags(currentFlags);
1774
1775 if (!wasEnabled)
1776 EnProfiler.Enable(false, true);
1777
1778 EnProfiler.SetModule(currentlyProfiledModule);
1779
1780 return NTFR(TFR.FAIL);
1781 }
1782 }
1783
1784 array<ref EnProfilerTimeClassPair> timePerClass = {};
1785 EnProfiler.GetTimePerClass(timePerClass);
1786
1787 int classCount = timePerClass.Count();
1788 for (int k = 0; k < classCount; ++k)
1789 {
1790 typename type = timePerClass[k].param2;
1791 EnProfilerModule classModule;
1792 if (!Assert(EnProfiler.NameToModule(type.GetModule(), classModule)))
1793 {
1794 EnProfiler.SetFlags(currentFlags);
1795
1796 if (!wasEnabled)
1797 EnProfiler.Enable(false, true);
1798
1799 EnProfiler.SetModule(currentlyProfiledModule);
1800
1801 return NTFR(TFR.FAIL);
1802 }
1803
1804 // Only classes from Game should be present
1805 if (!Assert(classModule == eptModule))
1806 {
1807 EnProfiler.SetFlags(currentFlags);
1808
1809 if (!wasEnabled)
1810 EnProfiler.Enable(false, true);
1811
1812 EnProfiler.SetModule(currentlyProfiledModule);
1813
1814 return NTFR(TFR.FAIL);
1815 }
1816 }
1817
1818 // Now let's check if we can gather the data of what we called earlier by switching the profiled module without resetting the session
1821 timePerFunc.Clear(); // Let's reuse the array, but the Get...Per... methods only appends to the array, clearing is our responsibility
1822 EnProfiler.GetTimePerFunc(timePerFunc);
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 {
1831 EnProfilerTimeFuncPair tfpc = timePerFunc[l];
1832 Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfpc.param1, tfpc.param2), this, "TestModule");
1833 // We are currently profiling Core, so this Core function should be present
1834 if (tfpc.param2 == "EnumTools::StringToEnum")
1835 {
1836 found = true;
1837 break;
1838 }
1839 }
1840
1841 Assert(found);
1842
1843 // Test some bogus
1845 EnProfiler.SetModule(-333);
1846 bool success = Assert(EnProfiler.GetModule() == mod);
1847 EnProfiler.SetModule(6003);
1848 success &= Assert(EnProfiler.GetModule() == mod);
1849
1850 EnProfiler.SetFlags(currentFlags);
1851 EnProfiler.SetModule(currentlyProfiledModule);
1852
1853 if (!wasEnabled)
1854 EnProfiler.Enable(false, true);
1855
1856 return BTFR(success && found);
1857 }
1858
1859 //---------------------------------------------------------------------------
1860 // Test to see if class time data is correct
1862 {
1863 // We should restore this when done
1864 int resolution = EnProfiler.GetTimeResolution();
1865 bool wasEnabled = EnProfiler.RequestImmediateData();
1866
1867 // GetTickTime() returns in seconds, so gather the results in seconds too
1869
1870 // Create the classes
1871 EPTHelperClass clss = new EPTHelperClass();
1872
1873 // Time to stress
1874 float previousTime = EnProfiler.GetTimeOfClass(clss.Type(), true);
1875 float timeStressed = clss.DoEverything();
1876 float postTime = EnProfiler.GetTimeOfClass(clss.Type(), true);
1877 float postTimeStatic = EnProfiler.GetTimeOfClass(StaticGetType(EPTHelperClass), true);
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 // Restore
1884 EnProfiler.SetTimeResolution(resolution);
1885 if (!wasEnabled)
1886 EnProfiler.Enable(false, true);
1887
1888 // We called the function, so it must have some time
1889 if (!Assert(postTime > 0))
1890 {
1891 return NTFR(TFR.FAIL);
1892 }
1893
1894 if (!Assert(postTime == postTimeStatic))
1895 {
1896 return NTFR(TFR.FAIL);
1897 }
1898
1899 if (!Assert(diff < 0.001))
1900 {
1901 return NTFR(TFR.FAIL);
1902 }
1903
1904 return NTFR(TFR.SUCCESS);
1905 }
1906
1907 //---------------------------------------------------------------------------
1908 // Test to see if class count data is correct
1910 {
1911 const int allocAmount = 9;
1912 const int releaseAmount = 6;
1913 int remainingAmount = allocAmount - releaseAmount;
1914
1915 // We should restore this when done
1916 bool wasEnabled = EnProfiler.RequestImmediateData();
1917
1918 // Time to test
1919 int previousAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
1920 int previousInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
1921
1922 array<ref EPTHelperClass> instanceArr = {};
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
1933 int postAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
1934 int postInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
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 // Restore
1942 if (!wasEnabled)
1943 EnProfiler.Enable(false, true);
1944
1945 // Time to check
1946 if (!Assert(alloced == allocAmount))
1947 {
1948 return NTFR(TFR.FAIL);
1949 }
1950
1951 if (!Assert(instances == remainingAmount))
1952 {
1953 return NTFR(TFR.FAIL);
1954 }
1955
1956 return NTFR(TFR.SUCCESS);
1957 }
1958
1959 //---------------------------------------------------------------------------
1960 // Test to see if func time data is correct
1962 {
1963 // We should restore this when done
1964 int resolution = EnProfiler.GetTimeResolution();
1965 bool wasEnabled = EnProfiler.RequestImmediateData();
1966
1967 // GetTickTime() returns in seconds, so gather the results in seconds too
1969
1970 // Time to stress
1971 float previousTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
1972 float timeStressed = StringFormat();
1973 float postTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
1974 float timeProfiled = postTime - previousTime;
1975 float diff = Math.AbsFloat(timeProfiled - timeStressed);
1976
1977 float previousTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
1978 float timeStressed2 = StringConcat();
1979 float postTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
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 // Restore
1986 EnProfiler.SetTimeResolution(resolution);
1987 if (!wasEnabled)
1988 {
1989 EnProfiler.Enable(false, true);
1990 }
1991
1992 // We called the function, so it must have some time
1993 if (!Assert(postTime > 0))
1994 {
1995 return NTFR(TFR.FAIL);
1996 }
1997
1998 if (!Assert(diff < 0.001))
1999 {
2000 return NTFR(TFR.FAIL);
2001 }
2002
2003 if (!Assert(postTime2 > 0))
2004 {
2005 return NTFR(TFR.FAIL);
2006 }
2007
2008 if (!Assert(diff2 < 0.001))
2009 {
2010 return NTFR(TFR.FAIL);
2011 }
2012
2013 // I know that string.Format is faster than additive concatenation
2014 if (!Assert(timeProfiled < timeProfiled2))
2015 {
2016 return NTFR(TFR.FAIL);
2017 }
2018
2019 return NTFR(TFR.SUCCESS);
2020 }
2021
2022 //---------------------------------------------------------------------------
2023 // Test to see if func count data is correct
2025 {
2026 // We should restore this when done
2027 bool wasEnabled = EnProfiler.RequestImmediateData();
2028
2029 // Time to count
2030
2031 // - CallFunction
2032 int previousCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
2033 GetGame().GameScript.CallFunction(this, "TestFuncCountDataHelper", null, 0);
2034 int postCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
2035
2036 int callCountCF = postCountCF - previousCountCF;
2037
2038 // - CallFunctionParams
2039 int previousCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
2040 GetGame().GameScript.CallFunctionParams(this, "TestFuncCountDataHelper", null, null);
2041 int postCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
2042
2043 int callCountCFP = postCountCFP - previousCountCFP;
2044
2045 // - Regular call
2046 int previousCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
2048 int postCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
2049
2050 int callCountRG = postCountRG - previousCountRG;
2051
2052 // - Call
2053 int previousCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
2054 GetGame().GameScript.Call(this, "TestFuncCountDataHelper", 0);
2055 int postCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
2056
2057 int callCountC = postCountC - previousCountC;
2058
2059 // - Garbage
2060 int callCountNon = EnProfiler.GetCountOfFunc("Non Existing Method", Type(), true);
2061
2062 // - Static
2063 int previousCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
2065 int postCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
2066
2067 int callCountS = postCountS - previousCountS;
2068
2069 // - Global
2070 int previousCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
2071 GetDayZGame();
2072 int postCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
2073
2074 int callCountG = postCountG - previousCountG;
2075
2076 // - Global proto
2077 // Not tracked, so don't need to compare before and after, should always be 0
2078 ErrorEx("Testing global proto call", ErrorExSeverity.INFO);
2079 int callCountGP = EnProfiler.GetCountOfFuncG("ErrorEx", true);
2080
2081 // - Static proto
2082 // Not tracked, so don't need to compare before and after, should always be 0
2083 int callCountSP = EnProfiler.GetCountOfFunc("GetCountOfFunc", StaticGetType(EnProfiler), true);
2084
2085 // - proto
2086 // Not tracked, so don't need to compare before and after, should always be 0
2087 GetGame().GetHostName();
2088 int callCountP = EnProfiler.GetCountOfFunc("GetHostName", GetGame().Type(), true);
2089
2090 // - proto native
2091 // Not tracked, so don't need to compare before and after, should always be 0
2092 GetGame().IsServer();
2093 int callCountPN = EnProfiler.GetCountOfFunc("IsServer", GetGame().Type(), true);
2094
2095 // - static proto native
2096 // Not tracked, so don't need to compare before and after, should always be 0
2098 int callCountSPN = EnProfiler.GetCountOfFunc("GetInstance", StaticGetType(ErrorModuleHandler), true);
2099
2100 // Restore
2101 if (!wasEnabled)
2102 {
2103 EnProfiler.Enable(false, true);
2104 }
2105
2106 // Do the checks
2107
2108 // - CallFunction
2109 if (!Assert(callCountCF == 1))
2110 {
2111 return NTFR(TFR.FAIL);
2112 }
2113
2114 // - CallFunctionParams
2115 if (!Assert(callCountCFP == 1))
2116 {
2117 return NTFR(TFR.FAIL);
2118 }
2119
2120 // - Regular call
2121 if (!Assert(callCountRG == 1))
2122 {
2123 return NTFR(TFR.FAIL);
2124 }
2125
2126 // - Call
2127 if (!Assert(callCountC == 1))
2128 {
2129 return NTFR(TFR.FAIL);
2130 }
2131
2132 // - Garbage
2133 if (!Assert(callCountNon == -1))
2134 {
2135 return NTFR(TFR.FAIL);
2136 }
2137
2138 // - Static
2139 if (!Assert(callCountS == 1))
2140 {
2141 return NTFR(TFR.FAIL);
2142 }
2143
2144 // - Global
2145 if (!Assert(callCountG == 1))
2146 {
2147 return NTFR(TFR.FAIL);
2148 }
2149
2150 // - Global proto
2151 if (!Assert(callCountGP == 0))
2152 {
2153 return NTFR(TFR.FAIL);
2154 }
2155
2156 // - Static proto
2157 if (!Assert(callCountSP == 0))
2158 {
2159 return NTFR(TFR.FAIL);
2160 }
2161
2162 // - proto
2163 if (!Assert(callCountP == 0))
2164 {
2165 return NTFR(TFR.FAIL);
2166 }
2167
2168 // - proto native
2169 if (!Assert(callCountPN == 0))
2170 {
2171 return NTFR(TFR.FAIL);
2172 }
2173
2174 // - static proto native
2175 if (!Assert(callCountSPN == 0))
2176 {
2177 return NTFR(TFR.FAIL);
2178 }
2179
2180 return NTFR(TFR.SUCCESS);
2181 }
2182
2183 //---------------------------------------------------------------------------
2184 // Helpers
2185 //---------------------------------------------------------------------------
2186 // Snore
2187 float Sleep(float timeS)
2188 {
2189 float startTime = GetGame().GetTickTime();
2190 while (GetGame().GetTickTime() - startTime < timeS)
2191 {
2192 // Zzz
2193 }
2194
2195 return GetGame().GetTickTime() - startTime;
2196 }
2197
2198 //---------------------------------------------------------------------------
2199 // Example stress method
2200 float StringFormat()
2201 {
2202 float startTime = GetGame().GetTickTime();
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
2209 return GetGame().GetTickTime() - startTime;
2210 }
2211
2212 //---------------------------------------------------------------------------
2213 // Example stress method 2
2214 float StringConcat()
2215 {
2216 float startTime = GetGame().GetTickTime();
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
2223 return GetGame().GetTickTime() - startTime;
2224 }
2225
2226 //---------------------------------------------------------------------------
2227 // To make sure it is only ever called in that test
2229 {
2230 int dummy = 3;
2231 }
2232
2233 //---------------------------------------------------------------------------
2234 // To make sure it is only ever called in that test
2235 static void TestFuncCountDataHelperStatic()
2236 {
2237 int dummy = 3;
2238 }
2239}
2240
2241class EPTHelperClass
2242{
2243 float Sleep2(float timeS)
2244 {
2245 float startTime = GetGame().GetTickTime();
2246 while (GetGame().GetTickTime() - startTime < timeS)
2247 {
2248 // Zzz
2249 }
2250
2251 return GetGame().GetTickTime() - startTime;
2252 }
2253 float SleepAgain(float timeS)
2254 {
2255 float startTime = GetGame().GetTickTime();
2256 while (GetGame().GetTickTime() - startTime < timeS)
2257 {
2258 // Zzz
2259 }
2260
2261 return GetGame().GetTickTime() - startTime;
2262 }
2263
2264 float DoEverything()
2265 {
2266 float startTime = GetGame().GetTickTime();
2267
2268 Sleep2(3);
2269 SleepAgain(3);
2270
2271 return GetGame().GetTickTime() - startTime;
2272 }
2273}
DayZGame GetDayZGame()
Определения DayZGame.c:3870
float StringConcat()
Определения EnProfilerTests.c:1495
float SleepAgain(float timeS)
Определения EnProfilerTests.c:773
float Sleep(float timeS)
Определения EnProfilerTests.c:1468
void TestFuncCountDataHelper()
Определения EnProfilerTests.c:1509
void EnProfilerTests()
Определения EnProfilerTests.c:770
TFResult TestModule()
Определения EnProfilerTests.c:950
float DoEverything()
Определения EnProfilerTests.c:784
TFResult TestClearFlags()
Определения EnProfilerTests.c:881
void ~EnProfilerTests()
Определения EnProfilerTests.c:789
TFResult TestTogglingImmediate()
Определения EnProfilerTests.c:813
TFResult TestFuncCountData()
Определения EnProfilerTests.c:1305
EnProfilerTests TestFramework Sleep2(float timeS)
Определения EnProfilerTests.c:763
TFResult TestClassTimeData()
Определения EnProfilerTests.c:1142
static void TestFuncCountDataHelperStatic()
Определения EnProfilerTests.c:1516
float StringFormat()
Определения EnProfilerTests.c:1481
TFResult TestClassCountData()
Определения EnProfilerTests.c:1190
TFResult TestAddFlags()
Определения EnProfilerTests.c:918
bool m_bWasProfilerEnabled
Remember this, so we can restore the previous state before the test!
Определения EnProfilerTests.c:765
TFResult TestFuncTimeData()
Определения EnProfilerTests.c:1242
TFResult TestSetFlags()
Определения EnProfilerTests.c:828
TFResult TestToggling()
Определения EnProfilerTests.c:798
string Type
Определения JsonDataContaminatedArea.c:11
void TestFramework()
Определения TestFramework.c:217
TFResult NTFR(TFR result)
Определения TestFramework.c:273
bool Assert(bool condition)
Определения TestFramework.c:262
void TFResult(TFR result)
Определения TestFramework.c:12
TFR
Определения TestFramework.c:2
void AddInitTest(string test)
Определения TestFramework.c:249
TFResult BTFR(bool result)
Определения TestFramework.c:278
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()
ScriptModule GameScript
Определения Game.c:12
static void TFLog(string message=LOG_DEFAULT, TestFramework caller=null, string function="")
Определения Debug.c:177
Определения Debug.c:2
Set of methods for accessing script profiling data.
Определения EnProfiler.c:73
static int GetEnumSize(typename e)
Return amount of values in enum.
Определения EnConvert.c:623
static int GetEnumValue(typename e, int idx)
Return the nth value in the enum.
Определения EnConvert.c:634
static int StringToEnum(typename e, string enumName)
Return enum value from string name.
Определения EnConvert.c:612
Определения EnConvert.c:590
static proto native ErrorModuleHandler GetInstance()
Gets the EMH Instance.
The error handler itself, for managing and distributing errors to modules Manages the ErrorHandlerMod...
Определения ErrorModuleHandler.c:29
Определения EnMath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
ErrorExSeverity
Определения EnDebug.c:62
enum ShapeType ErrorEx
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
Определения EnProfiler.c:58
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.
Определения EnProfiler.c:138
static bool IsEnabledC()
Return if script profiling is actually turned on inside of the script context.
Определения EnProfiler.c:152
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.
Определения EnProfiler.c:9
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.
Определения EnProfiler.c:22
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.
Определения EnProfiler.c:745
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.