1243{
1246
1247
1248
1249
1251 {
1253
1264 }
1265
1266
1267
1268
1270 {
1272 }
1273
1274
1275
1276
1277
1279 {
1283 {
1286 }
1287
1289 }
1290
1291
1292
1294 {
1298 {
1301 }
1302
1304 }
1305
1306
1307
1309 {
1311
1313 {
1316
1318 {
1321 }
1322
1324 {
1327
1329 {
1332 }
1333 }
1334 }
1335
1336
1340 if (!
Assert(bogusFlags == 0))
1341 {
1344 }
1345
1348 if (!
Assert(bogusFlags == 0))
1349 {
1352 }
1353
1354
1357 }
1358
1359
1360
1362 {
1364
1366
1368 {
1371 }
1372
1375
1377 {
1380 }
1381
1384
1386 {
1389 }
1390
1391
1394 }
1395
1396
1397
1399 {
1401
1403
1404
1406 {
1409 }
1410
1412 {
1415 }
1416
1418 {
1421 }
1422
1423
1426 }
1427
1428
1429
1431 {
1432
1434
1435
1436 string nameOfCurrentModule =
Type().GetModule();
1437 if (!
Assert(nameOfCurrentModule !=
""))
1438 {
1440 }
1441
1442
1445 {
1447 }
1448
1449 if (!
Assert(currentModule == eptModule))
1450 {
1452 }
1453
1454
1457
1459 {
1462 }
1463
1464
1467
1468
1469
1471
1472
1475
1476
1478 float timeSlept =
Sleep(0.3);
1480 float diff = postTime - previousTime - timeSlept;
1481
1482
1484
1485
1486 if (!
Assert(postTime > 0))
1487 {
1489
1490 if (!wasEnabled)
1492
1494
1496 }
1497
1498 if (!
Assert(diff < 0.00001))
1499 {
1501
1502 if (!wasEnabled)
1504
1506
1508 }
1509
1510
1512
1513
1514 for (int i = 0; i < 1000; ++i)
1515 {
1517 }
1518
1519
1523
1524 Debug.
TFLog(
"Game fncs:",
this,
"TestModule");
1525
1526 int funcCount = timePerFunc.Count();
1527 for (int j = 0; j < funcCount; ++j)
1528 {
1530 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfp.param1, tfp.param2),
this,
"TestModule");
1531
1532 if (!
Assert(tfp.param2 !=
"EnumTools::StringToEnum"))
1533 {
1535
1536 if (!wasEnabled)
1538
1540
1542 }
1543 }
1544
1547
1548 int classCount = timePerClass.Count();
1549 for (int k = 0; k < classCount; ++k)
1550 {
1551 typename type = timePerClass[k].param2;
1554 {
1556
1557 if (!wasEnabled)
1559
1561
1563 }
1564
1565
1566 if (!
Assert(classModule == eptModule))
1567 {
1569
1570 if (!wasEnabled)
1572
1574
1576 }
1577 }
1578
1579
1582 timePerFunc.Clear();
1584
1585 bool found = false;
1586
1587 Debug.
TFLog(
"Core fncs:",
this,
"TestModule");
1588
1589 funcCount = timePerFunc.Count();
1590 for (int l = 0; l < funcCount; ++l)
1591 {
1593 Debug.
TFLog(
string.Format(
" time: %1 | fnc: %2", tfpc.param1, tfpc.param2),
this,
"TestModule");
1594
1595 if (tfpc.param2 == "EnumTools::StringToEnum")
1596 {
1597 found = true;
1598 break;
1599 }
1600 }
1601
1603
1604
1610
1613
1614 if (!wasEnabled)
1616
1617 return BTFR(success && found);
1618 }
1619
1620
1621
1623 {
1624
1627
1628
1630
1631
1632 EPTHelperClass clss = new EPTHelperClass();
1633
1634
1636 float timeStressed = clss.DoEverything();
1639 float timeProfiled = postTime - previousTime;
1640 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1641
1642 Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff),
this,
"TestClassTimeData");
1643
1644
1646 if (!wasEnabled)
1648
1649
1650 if (!
Assert(postTime > 0))
1651 {
1653 }
1654
1655 if (!
Assert(postTime == postTimeStatic))
1656 {
1658 }
1659
1660 if (!
Assert(diff < 0.001))
1661 {
1663 }
1664
1666 }
1667
1668
1669
1671 {
1672 const int allocAmount = 9;
1673 const int releaseAmount = 6;
1674 int remainingAmount = allocAmount - releaseAmount;
1675
1676
1678
1679
1682
1684 for (int i = 0; i < allocAmount; ++i)
1685 {
1686 instanceArr.Insert(new EPTHelperClass());
1687 }
1688
1689 for (int j = 0; j < releaseAmount; ++j)
1690 {
1691 delete instanceArr[j];
1692 }
1693
1696
1697 int alloced = postAlloc - previousAlloc;
1698 int instances = postInstances - previousInstances;
1699
1700 Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances),
this,
"TestClassCountData");
1701
1702
1703 if (!wasEnabled)
1705
1706
1707 if (!
Assert(alloced == allocAmount))
1708 {
1710 }
1711
1712 if (!
Assert(instances == remainingAmount))
1713 {
1715 }
1716
1718 }
1719
1720
1721
1723 {
1724
1727
1728
1730
1731
1735 float timeProfiled = postTime - previousTime;
1736 float diff =
Math.
AbsFloat(timeProfiled - timeStressed);
1737
1741 float timeProfiled2 = postTime2 - previousTime2;
1742 float diff2 =
Math.
AbsFloat(timeProfiled2 - timeStressed2);
1743
1744 Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2),
this,
"TestFuncTimeData");
1745
1746
1748 if (!wasEnabled)
1749 {
1751 }
1752
1753
1754 if (!
Assert(postTime > 0))
1755 {
1757 }
1758
1759 if (!
Assert(diff < 0.001))
1760 {
1762 }
1763
1764 if (!
Assert(postTime2 > 0))
1765 {
1767 }
1768
1769 if (!
Assert(diff2 < 0.001))
1770 {
1772 }
1773
1774
1775 if (!
Assert(timeProfiled < timeProfiled2))
1776 {
1778 }
1779
1781 }
1782
1783
1784
1786 {
1787
1789
1790
1791
1792
1796
1797 int callCountCF = postCountCF - previousCountCF;
1798
1799
1803
1804 int callCountCFP = postCountCFP - previousCountCFP;
1805
1806
1810
1811 int callCountRG = postCountRG - previousCountRG;
1812
1813
1817
1818 int callCountC = postCountC - previousCountC;
1819
1820
1822
1823
1827
1828 int callCountS = postCountS - previousCountS;
1829
1830
1834
1835 int callCountG = postCountG - previousCountG;
1836
1837
1838
1841
1842
1843
1845
1846
1847
1850
1851
1852
1855
1856
1857
1860
1861
1862 if (!wasEnabled)
1863 {
1865 }
1866
1867
1868
1869
1870 if (!
Assert(callCountCF == 1))
1871 {
1873 }
1874
1875
1876 if (!
Assert(callCountCFP == 1))
1877 {
1879 }
1880
1881
1882 if (!
Assert(callCountRG == 1))
1883 {
1885 }
1886
1887
1888 if (!
Assert(callCountC == 1))
1889 {
1891 }
1892
1893
1894 if (!
Assert(callCountNon == -1))
1895 {
1897 }
1898
1899
1900 if (!
Assert(callCountS == 1))
1901 {
1903 }
1904
1905
1906 if (!
Assert(callCountG == 1))
1907 {
1909 }
1910
1911
1912 if (!
Assert(callCountGP == 0))
1913 {
1915 }
1916
1917
1918 if (!
Assert(callCountSP == 0))
1919 {
1921 }
1922
1923
1924 if (!
Assert(callCountP == 0))
1925 {
1927 }
1928
1929
1930 if (!
Assert(callCountPN == 0))
1931 {
1933 }
1934
1935
1936 if (!
Assert(callCountSPN == 0))
1937 {
1939 }
1940
1942 }
1943
1944
1945
1946
1947
1948 float Sleep(
float timeS)
1949 {
1951 while (
GetGame().GetTickTime() - startTime < timeS)
1952 {
1953
1954 }
1955
1957 }
1958
1959
1960
1962 {
1964
1965 for (int i = 0; i < 1000; ++i)
1966 {
1967 string example =
string.Format(
"This %1 is %2 just %3 an %4 example %5", i,
Type(),
this, startTime,
"lorem ipsum 1 2 3");
1968 }
1969
1971 }
1972
1973
1974
1976 {
1978
1979 for (int i = 0; i < 1000; ++i)
1980 {
1981 string example =
"This " + i +
" is " +
Type() +
" just " +
this +
" an " + startTime +
" example " +
"lorem ipsum 1 2 3";
1982 }
1983
1985 }
1986
1987
1988
1990 {
1991 int dummy = 3;
1992 }
1993
1994
1995
1997 {
1998 int dummy = 3;
1999 }
2000}
2001
2002class EPTHelperClass
2003{
2004 float Sleep2(
float timeS)
2005 {
2007 while (
GetGame().GetTickTime() - startTime < timeS)
2008 {
2009
2010 }
2011
2013 }
2015 {
2017 while (
GetGame().GetTickTime() - startTime < timeS)
2018 {
2019
2020 }
2021
2023 }
2024
2026 {
2028
2031
2033 }
2034}
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.