829{
  832    
  833    
  834    
  835    
  837    {
  839        
  850    }
  851    
  852    
  853    
  854    
  856    {
  858    }
  859    
  860    
  861    
  862    
  863    
  865    {
  869        {
  872        }
  873        
  875    }
  876    
  877    
  878    
  880    {
  884        {
  887        }
  888        
  890    }
  891    
  892    
  893    
  895    {
  897        
  899        {
  902            
  904            {
  907            }
  908            
  910            {
  913                
  915                {
  918                }
  919            }
  920        }
  921        
  922        
  926        if (!
Assert(bogusFlags == 0))
 
  927        {
  930        }
  931        
  934        if (!
Assert(bogusFlags == 0))
 
  935        {
  938        }
  939        
  940        
  943    }
  944    
  945    
  946    
  948    {
  950                        
  952        
  954        {
  957        }
  958        
  961        
  963        {
  966        }
  967        
  970        
  972        {
  975        }
  976        
  977        
  980    }
  981    
  982    
  983    
  985    {
  987                        
  989        
  990        
  992        {
  995        }
  996        
  998        {
 1001        }
 1002        
 1004        {
 1007        }
 1008        
 1009        
 1012    }
 1013    
 1014    
 1015    
 1017    {
 1018        
 1020        
 1021        
 1022        string nameOfCurrentModule = 
Type().GetModule();
 
 1023        if (!
Assert(nameOfCurrentModule != 
""))
 
 1024        {
 1026        }
 1027        
 1028        
 1031        {
 1033        }
 1034        
 1035        if (!
Assert(currentModule == eptModule))
 
 1036        {
 1038        }
 1039        
 1040        
 1043        
 1045        {
 1048        }
 1049        
 1050        
 1053        
 1054        
 1055        
 1057        
 1058        
 1061        
 1062        
 1064        float timeSlept = 
Sleep(0.3);
 
 1066        float diff = postTime - previousTime - timeSlept;
 1067        
 1068        
 1070        
 1071        
 1072        if (!
Assert(postTime > 0))
 
 1073        {
 1075            
 1076            if (!wasEnabled)
 1078            
 1080            
 1082        }
 1083        
 1084        if (!
Assert(diff < 0.00001))
 
 1085        {
 1087            
 1088            if (!wasEnabled)
 1090            
 1092            
 1094        }
 1095        
 1096        
 1098        
 1099        
 1100        for (int i = 0; i < 1000; ++i)
 1101        {
 1103        }
 1104        
 1105        
 1109        
 1110        Debug.
TFLog(
"Game fncs:", 
this, 
"TestModule");
 
 1111        
 1112        int funcCount = timePerFunc.Count();
 1113        for (int j = 0; j < funcCount; ++j)
 1114        {
 1116            Debug.
TFLog(
string.Format(
"   time: %1 | fnc: %2", tfp.param1, tfp.param2), 
this, 
"TestModule");
 
 1117            
 1118            if (!
Assert(tfp.param2 != 
"EnumTools::StringToEnum"))
 
 1119            {
 1121                
 1122                if (!wasEnabled)
 1124                
 1126                
 1128            }
 1129        }
 1130        
 1133        
 1134        int classCount = timePerClass.Count();
 1135        for (int k = 0; k < classCount; ++k)
 1136        {
 1137            typename type = timePerClass[k].param2;
 1140            {
 1142                
 1143                if (!wasEnabled)
 1145                
 1147                
 1149            }
 1150            
 1151            
 1152            if (!
Assert(classModule == eptModule))
 
 1153            {
 1155                
 1156                if (!wasEnabled)
 1158                
 1160                
 1162            }
 1163        }
 1164        
 1165        
 1168        timePerFunc.Clear(); 
 1170        
 1171        bool found = false;
 1172        
 1173        Debug.
TFLog(
"Core fncs:", 
this, 
"TestModule");
 
 1174        
 1175        funcCount = timePerFunc.Count();
 1176        for (int l = 0; l < funcCount; ++l)
 1177        {
 1179            Debug.
TFLog(
string.Format(
"   time: %1 | fnc: %2", tfpc.param1, tfpc.param2), 
this, 
"TestModule");
 
 1180            
 1181            if (tfpc.param2 == "EnumTools::StringToEnum")
 1182            {
 1183                found = true;
 1184                break;
 1185            }
 1186        }
 1187        
 1189        
 1190        
 1196        
 1199        
 1200        if (!wasEnabled)
 1202        
 1203        return BTFR(success && found);
 
 1204    }
 1205    
 1206    
 1207    
 1209    {
 1210        
 1213        
 1214        
 1216        
 1217        
 1218        EPTHelperClass clss = new EPTHelperClass();
 1219        
 1220        
 1222        float timeStressed = clss.DoEverything();
 1225        float timeProfiled = postTime - previousTime;
 1226        float diff = 
Math.
AbsFloat(timeProfiled - timeStressed);
 
 1227        
 1228        Debug.
TFLog(
string.Format(
"Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff), 
this, 
"TestClassTimeData");
 
 1229        
 1230        
 1232        if (!wasEnabled)
 1234        
 1235        
 1236        if (!
Assert(postTime > 0))
 
 1237        {
 1239        }
 1240        
 1241        if (!
Assert(postTime == postTimeStatic))
 
 1242        {
 1244        }
 1245        
 1246        if (!
Assert(diff < 0.001))
 
 1247        {
 1249        }
 1250        
 1252    }
 1253    
 1254    
 1255    
 1257    {
 1258        const int allocAmount = 9;
 1259        const int releaseAmount = 6;
 1260        int remainingAmount = allocAmount - releaseAmount;
 1261        
 1262        
 1264        
 1265        
 1268 
 1270        for (int i = 0; i < allocAmount; ++i)
 1271        {
 1272            instanceArr.Insert(new EPTHelperClass());
 1273        }
 1274        
 1275        for (int j = 0; j < releaseAmount; ++j)
 1276        {
 1277            delete instanceArr[j];
 1278        }
 1279        
 1282        
 1283        int alloced = postAlloc - previousAlloc;
 1284        int instances = postInstances - previousInstances;
 1285        
 1286        Debug.
TFLog(
string.Format(
"Profiling result: alloc: %1 | instances: %2", alloced, instances), 
this, 
"TestClassCountData");
 
 1287        
 1288        
 1289        if (!wasEnabled)
 1291        
 1292        
 1293        if (!
Assert(alloced == allocAmount))
 
 1294        {
 1296        }
 1297        
 1298        if (!
Assert(instances == remainingAmount))
 
 1299        {
 1301        }
 1302        
 1304    }
 1305    
 1306    
 1307    
 1309    {
 1310        
 1313        
 1314        
 1316        
 1317        
 1321        float timeProfiled = postTime - previousTime;
 1322        float diff = 
Math.
AbsFloat(timeProfiled - timeStressed);
 
 1323        
 1327        float timeProfiled2 = postTime2 - previousTime2;
 1328        float diff2 = 
Math.
AbsFloat(timeProfiled2 - timeStressed2);
 
 1329        
 1330        Debug.
TFLog(
string.Format(
"Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2), 
this, 
"TestFuncTimeData");
 
 1331        
 1332        
 1334        if (!wasEnabled)
 1335        {
 1337        }
 1338        
 1339        
 1340        if (!
Assert(postTime > 0))
 
 1341        {
 1343        }
 1344        
 1345        if (!
Assert(diff < 0.001))
 
 1346        {
 1348        }
 1349        
 1350        if (!
Assert(postTime2 > 0))
 
 1351        {
 1353        }
 1354        
 1355        if (!
Assert(diff2 < 0.001))
 
 1356        {
 1358        }
 1359        
 1360        
 1361        if (!
Assert(timeProfiled < timeProfiled2))
 
 1362        {
 1364        }
 1365        
 1367    }
 1368    
 1369    
 1370    
 1372    {
 1373        
 1375        
 1376        
 1377        
 1378        
 1382        
 1383        int callCountCF = postCountCF - previousCountCF;
 1384        
 1385        
 1389        
 1390        int callCountCFP = postCountCFP - previousCountCFP;
 1391        
 1392        
 1396        
 1397        int callCountRG = postCountRG - previousCountRG;
 1398        
 1399        
 1403        
 1404        int callCountC = postCountC - previousCountC;
 1405        
 1406        
 1408        
 1409        
 1413        
 1414        int callCountS = postCountS - previousCountS;
 1415        
 1416        
 1420    
 1421        int callCountG = postCountG - previousCountG;
 1422        
 1423        
 1424        
 1427        
 1428        
 1429        
 1431        
 1432        
 1433        
 1436        
 1437        
 1438        
 1441        
 1442        
 1443        
 1446        
 1447        
 1448        if (!wasEnabled)
 1449        {
 1451        }
 1452        
 1453        
 1454        
 1455        
 1456        if (!
Assert(callCountCF == 1))
 
 1457        {
 1459        }
 1460        
 1461        
 1462        if (!
Assert(callCountCFP == 1))
 
 1463        {
 1465        }
 1466        
 1467        
 1468        if (!
Assert(callCountRG == 1))
 
 1469        {
 1471        }
 1472        
 1473        
 1474        if (!
Assert(callCountC == 1))
 
 1475        {
 1477        }
 1478        
 1479        
 1480        if (!
Assert(callCountNon == -1))
 
 1481        {
 1483        }
 1484        
 1485        
 1486        if (!
Assert(callCountS == 1))
 
 1487        {
 1489        }
 1490        
 1491        
 1492        if (!
Assert(callCountG == 1))
 
 1493        {
 1495        }
 1496        
 1497        
 1498        if (!
Assert(callCountGP == 0))
 
 1499        {
 1501        }
 1502        
 1503        
 1504        if (!
Assert(callCountSP == 0))
 
 1505        {
 1507        }
 1508        
 1509        
 1510        if (!
Assert(callCountP == 0))
 
 1511        {
 1513        }
 1514        
 1515        
 1516        if (!
Assert(callCountPN == 0))
 
 1517        {
 1519        }
 1520        
 1521        
 1522        if (!
Assert(callCountSPN == 0))
 
 1523        {
 1525        }
 1526        
 1528    }
 1529    
 1530    
 1531    
 1532    
 1533    
 1534    float Sleep(
float timeS)
 
 1535    {       
 1537        while (
GetGame().GetTickTime() - startTime < timeS)
 
 1538        {
 1539            
 1540        }       
 1541        
 1543    }
 1544    
 1545    
 1546    
 1548    {       
 1550        
 1551        for (int i = 0; i < 1000; ++i)
 1552        {
 1553            string example = 
string.Format(
"This %1 is %2 just %3 an %4 example %5", i, 
Type(), 
this, startTime, 
"lorem ipsum 1 2 3");
 
 1554        }   
 1555        
 1557    }
 1558    
 1559    
 1560    
 1562    {       
 1564        
 1565        for (int i = 0; i < 1000; ++i)
 1566        {
 1567            string example = 
"This " + i + 
" is " + 
Type() + 
" just " + 
this + 
" an " + startTime + 
" example " + 
"lorem ipsum 1 2 3";
 
 1568        }
 1569        
 1571    }
 1572    
 1573    
 1574    
 1576    {
 1577        int dummy = 3;
 1578    }
 1579    
 1580    
 1581    
 1583    {
 1584        int dummy = 3;
 1585    }
 1586}
 1587 
 1588class EPTHelperClass
 1589{
 1590    float Sleep2(
float timeS)
 
 1591    {       
 1593        while (
GetGame().GetTickTime() - startTime < timeS)
 
 1594        {
 1595            
 1596        }       
 1597        
 1599    }
 1601    {       
 1603        while (
GetGame().GetTickTime() - startTime < timeS)
 
 1604        {
 1605            
 1606        }       
 1607        
 1609    }
 1610    
 1612    {
 1614        
 1617        
 1619    }
 1620}
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.