| class EnProfilerTests : TestFramework |
| { |
| |
| bool m_bWasProfilerEnabled; |
| |
| |
| |
| |
| void EnProfilerTests() |
| { |
| m_bWasProfilerEnabled = EnProfiler.IsEnabledC(); |
| |
| AddInitTest("TestToggling"); |
| AddInitTest("TestTogglingImmediate"); |
| AddInitTest("TestSetFlags"); |
| AddInitTest("TestClearFlags"); |
| AddInitTest("TestAddFlags"); |
| AddInitTest("TestModule"); |
| AddInitTest("TestClassTimeData"); |
| AddInitTest("TestClassCountData"); |
| AddInitTest("TestFuncTimeData"); |
| AddInitTest("TestFuncCountData"); |
| } |
| |
| |
| |
| |
| void ~EnProfilerTests() |
| { |
| EnProfiler.Enable(m_bWasProfilerEnabled, true); |
| } |
| |
| |
| |
| |
| |
| TFResult TestToggling() |
| { |
| bool currentlyEnabled = EnProfiler.IsEnabledP(); |
| EnProfiler.Enable(!currentlyEnabled); |
| if (Assert(currentlyEnabled != EnProfiler.IsEnabledP())) |
| { |
| EnProfiler.Enable(currentlyEnabled); |
| return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledP())); |
| } |
| |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| |
| TFResult TestTogglingImmediate() |
| { |
| bool currentlyEnabled = EnProfiler.IsEnabledC(); |
| EnProfiler.Enable(!currentlyEnabled, true); |
| if (Assert(currentlyEnabled != EnProfiler.IsEnabledC())) |
| { |
| EnProfiler.Enable(currentlyEnabled, true); |
| return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledC())); |
| } |
| |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| |
| TFResult TestSetFlags() |
| { |
| int currentFlags = EnProfiler.GetFlags(); |
| |
| for (int i = 0; i < EnumTools.GetEnumSize(EnProfilerFlags); ++i) |
| { |
| int flags = EnumTools.GetEnumValue(EnProfilerFlags, i); |
| EnProfiler.SetFlags(flags); |
| |
| if (!Assert(EnProfiler.GetFlags() == flags)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| |
| for (int j = 0; j < EnumTools.GetEnumSize(EnProfilerFlags); ++j) |
| { |
| flags |= EnumTools.GetEnumValue(EnProfilerFlags, j); |
| EnProfiler.SetFlags(flags); |
| |
| if (!Assert(EnProfiler.GetFlags() == flags)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| } |
| } |
| |
| |
| EnProfiler.SetFlags(-333); |
| int bogusFlags = EnProfiler.GetFlags(); |
| bogusFlags &= ~EnProfilerFlags.ALL; |
| if (!Assert(bogusFlags == 0)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| |
| bogusFlags = EnProfiler.SetFlags(6003); |
| bogusFlags &= ~EnProfilerFlags.ALL; |
| if (!Assert(bogusFlags == 0)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.SUCCESS); |
| } |
| |
| |
| |
| TFResult TestClearFlags() |
| { |
| int currentFlags = EnProfiler.GetFlags(); |
| |
| EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE); |
| |
| if (!Assert(EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE) == EnProfilerFlags.NONE)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| |
| EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET); |
| EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET); |
| |
| if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| |
| EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET); |
| EnProfiler.ClearFlags(); |
| |
| if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.SUCCESS); |
| } |
| |
| |
| |
| TFResult TestAddFlags() |
| { |
| int currentFlags = EnProfiler.GetFlags(); |
| |
| EnProfiler.ClearFlags(); |
| |
| |
| if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RESET) == EnProfiler.GetFlags())) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.RESET)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RECURSIVE) == (EnProfilerFlags.RESET | EnProfilerFlags.RECURSIVE))) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| EnProfiler.SetFlags(currentFlags); |
| return NTFR(TFR.SUCCESS); |
| } |
| |
| |
| |
| TFResult TestModule() |
| { |
| |
| const EnProfilerModule eptModule = EnProfilerModule.GAME; |
| |
| |
| string nameOfCurrentModule = Type().GetModule(); |
| if (!Assert(nameOfCurrentModule != "")) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| EnProfilerModule currentModule; |
| if (!Assert(EnProfiler.NameToModule(nameOfCurrentModule, currentModule))) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(currentModule == eptModule)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| EnProfilerModule currentlyProfiledModule = EnProfiler.GetModule(); |
| EnProfiler.SetModule(eptModule); |
| |
| if (!Assert(EnProfiler.GetModule() == eptModule)) |
| { |
| EnProfiler.SetModule(currentlyProfiledModule); |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| int currentFlags = EnProfiler.GetFlags(); |
| bool wasEnabled = EnProfiler.RequestImmediateData(); |
| |
| |
| |
| EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE); |
| |
| |
| int resolution = EnProfiler.GetTimeResolution(); |
| EnProfiler.SetTimeResolution(1); |
| |
| |
| float previousTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true); |
| float timeSlept = Sleep(0.3); |
| float postTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true); |
| float diff = postTime - previousTime - timeSlept; |
| |
| |
| EnProfiler.SetTimeResolution(resolution); |
| |
| |
| if (!Assert(postTime > 0)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| |
| if (!wasEnabled) |
| EnProfiler.Enable(false, true); |
| |
| EnProfiler.SetModule(currentlyProfiledModule); |
| |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(diff < 0.00001)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| |
| if (!wasEnabled) |
| EnProfiler.Enable(false, true); |
| |
| EnProfiler.SetModule(currentlyProfiledModule); |
| |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| EnProfiler.ResetSession(true); |
| |
| |
| for (int i = 0; i < 1000; ++i) |
| { |
| EnumTools.StringToEnum(EnProfilerModule, "MISSION_CUSTOM"); |
| } |
| |
| |
| EnProfiler.SortData(); |
| array<ref EnProfilerTimeFuncPair> timePerFunc = {}; |
| EnProfiler.GetTimePerFunc(timePerFunc); |
| |
| Debug.TFLog("Game fncs:", this, "TestModule"); |
| |
| int funcCount = timePerFunc.Count(); |
| for (int j = 0; j < funcCount; ++j) |
| { |
| EnProfilerTimeFuncPair tfp = timePerFunc[j]; |
| Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfp.param1, tfp.param2), this, "TestModule"); |
| |
| if (!Assert(tfp.param2 != "EnumTools::StringToEnum")) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| |
| if (!wasEnabled) |
| EnProfiler.Enable(false, true); |
| |
| EnProfiler.SetModule(currentlyProfiledModule); |
| |
| return NTFR(TFR.FAIL); |
| } |
| } |
| |
| array<ref EnProfilerTimeClassPair> timePerClass = {}; |
| EnProfiler.GetTimePerClass(timePerClass); |
| |
| int classCount = timePerClass.Count(); |
| for (int k = 0; k < classCount; ++k) |
| { |
| typename type = timePerClass[k].param2; |
| EnProfilerModule classModule; |
| if (!Assert(EnProfiler.NameToModule(type.GetModule(), classModule))) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| |
| if (!wasEnabled) |
| EnProfiler.Enable(false, true); |
| |
| EnProfiler.SetModule(currentlyProfiledModule); |
| |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(classModule == eptModule)) |
| { |
| EnProfiler.SetFlags(currentFlags); |
| |
| if (!wasEnabled) |
| EnProfiler.Enable(false, true); |
| |
| EnProfiler.SetModule(currentlyProfiledModule); |
| |
| return NTFR(TFR.FAIL); |
| } |
| } |
| |
| |
| EnProfiler.SetModule(EnProfilerModule.CORE, false); |
| EnProfiler.SortData(); |
| timePerFunc.Clear(); |
| EnProfiler.GetTimePerFunc(timePerFunc); |
| |
| bool found = false; |
| |
| Debug.TFLog("Core fncs:", this, "TestModule"); |
| |
| funcCount = timePerFunc.Count(); |
| for (int l = 0; l < funcCount; ++l) |
| { |
| EnProfilerTimeFuncPair tfpc = timePerFunc[l]; |
| Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfpc.param1, tfpc.param2), this, "TestModule"); |
| |
| if (tfpc.param2 == "EnumTools::StringToEnum") |
| { |
| found = true; |
| break; |
| } |
| } |
| |
| Assert(found); |
| |
| |
| EnProfilerModule mod = EnProfiler.GetModule(); |
| EnProfiler.SetModule(-333); |
| bool success = Assert(EnProfiler.GetModule() == mod); |
| EnProfiler.SetModule(6003); |
| success &= Assert(EnProfiler.GetModule() == mod); |
| |
| EnProfiler.SetFlags(currentFlags); |
| EnProfiler.SetModule(currentlyProfiledModule); |
| |
| if (!wasEnabled) |
| EnProfiler.Enable(false, true); |
| |
| return BTFR(success && found); |
| } |
| |
| |
| |
| TFResult TestClassTimeData() |
| { |
| |
| int resolution = EnProfiler.GetTimeResolution(); |
| bool wasEnabled = EnProfiler.RequestImmediateData(); |
| |
| |
| EnProfiler.SetTimeResolution(1); |
| |
| |
| EPTHelperClass clss = new EPTHelperClass(); |
| |
| |
| float previousTime = EnProfiler.GetTimeOfClass(clss.Type(), true); |
| float timeStressed = clss.DoEverything(); |
| float postTime = EnProfiler.GetTimeOfClass(clss.Type(), true); |
| float postTimeStatic = EnProfiler.GetTimeOfClass(StaticGetType(EPTHelperClass), true); |
| float timeProfiled = postTime - previousTime; |
| float diff = Math.AbsFloat(timeProfiled - timeStressed); |
| |
| Debug.TFLog(string.Format("Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff), this, "TestClassTimeData"); |
| |
| |
| EnProfiler.SetTimeResolution(resolution); |
| if (!wasEnabled) |
| EnProfiler.Enable(false, true); |
| |
| |
| if (!Assert(postTime > 0)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(postTime == postTimeStatic)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(diff < 0.001)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| return NTFR(TFR.SUCCESS); |
| } |
| |
| |
| |
| TFResult TestClassCountData() |
| { |
| const int allocAmount = 9; |
| const int releaseAmount = 6; |
| int remainingAmount = allocAmount - releaseAmount; |
| |
| |
| bool wasEnabled = EnProfiler.RequestImmediateData(); |
| |
| |
| int previousAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true); |
| int previousInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true); |
|
|
| array<ref EPTHelperClass> instanceArr = {}; |
| for (int i = 0; i < allocAmount; ++i) |
| { |
| instanceArr.Insert(new EPTHelperClass()); |
| } |
| |
| for (int j = 0; j < releaseAmount; ++j) |
| { |
| delete instanceArr[j]; |
| } |
| |
| int postAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true); |
| int postInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true); |
| |
| int alloced = postAlloc - previousAlloc; |
| int instances = postInstances - previousInstances; |
| |
| Debug.TFLog(string.Format("Profiling result: alloc: %1 | instances: %2", alloced, instances), this, "TestClassCountData"); |
| |
| |
| if (!wasEnabled) |
| EnProfiler.Enable(false, true); |
| |
| |
| if (!Assert(alloced == allocAmount)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(instances == remainingAmount)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| return NTFR(TFR.SUCCESS); |
| } |
| |
| |
| |
| TFResult TestFuncTimeData() |
| { |
| |
| int resolution = EnProfiler.GetTimeResolution(); |
| bool wasEnabled = EnProfiler.RequestImmediateData(); |
| |
| |
| EnProfiler.SetTimeResolution(1); |
| |
| |
| float previousTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true); |
| float timeStressed = StringFormat(); |
| float postTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true); |
| float timeProfiled = postTime - previousTime; |
| float diff = Math.AbsFloat(timeProfiled - timeStressed); |
| |
| float previousTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true); |
| float timeStressed2 = StringConcat(); |
| float postTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true); |
| float timeProfiled2 = postTime2 - previousTime2; |
| float diff2 = Math.AbsFloat(timeProfiled2 - timeStressed2); |
| |
| Debug.TFLog(string.Format("Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2), this, "TestFuncTimeData"); |
| |
| |
| EnProfiler.SetTimeResolution(resolution); |
| if (!wasEnabled) |
| { |
| EnProfiler.Enable(false, true); |
| } |
| |
| |
| if (!Assert(postTime > 0)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(diff < 0.001)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(postTime2 > 0)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| if (!Assert(diff2 < 0.001)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(timeProfiled < timeProfiled2)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| return NTFR(TFR.SUCCESS); |
| } |
| |
| |
| |
| TFResult TestFuncCountData() |
| { |
| |
| bool wasEnabled = EnProfiler.RequestImmediateData(); |
| |
| |
| |
| |
| int previousCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true); |
| GetGame().GameScript.CallFunction(this, "TestFuncCountDataHelper", null, 0); |
| int postCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true); |
| |
| int callCountCF = postCountCF - previousCountCF; |
| |
| |
| int previousCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true); |
| GetGame().GameScript.CallFunctionParams(this, "TestFuncCountDataHelper", null, null); |
| int postCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true); |
| |
| int callCountCFP = postCountCFP - previousCountCFP; |
| |
| |
| int previousCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true); |
| TestFuncCountDataHelper(); |
| int postCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true); |
| |
| int callCountRG = postCountRG - previousCountRG; |
| |
| |
| int previousCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true); |
| GetGame().GameScript.Call(this, "TestFuncCountDataHelper", 0); |
| int postCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true); |
| |
| int callCountC = postCountC - previousCountC; |
| |
| |
| int callCountNon = EnProfiler.GetCountOfFunc("Non Existing Method", Type(), true); |
| |
| |
| int previousCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true); |
| TestFuncCountDataHelperStatic(); |
| int postCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true); |
| |
| int callCountS = postCountS - previousCountS; |
| |
| |
| int previousCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true); |
| GetDayZGame(); |
| int postCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true); |
| |
| int callCountG = postCountG - previousCountG; |
| |
| |
| |
| ErrorEx("Testing global proto call", ErrorExSeverity.INFO); |
| int callCountGP = EnProfiler.GetCountOfFuncG("ErrorEx", true); |
| |
| |
| |
| int callCountSP = EnProfiler.GetCountOfFunc("GetCountOfFunc", StaticGetType(EnProfiler), true); |
| |
| |
| |
| GetGame().GetHostName(); |
| int callCountP = EnProfiler.GetCountOfFunc("GetHostName", GetGame().Type(), true); |
| |
| |
| |
| GetGame().IsServer(); |
| int callCountPN = EnProfiler.GetCountOfFunc("IsServer", GetGame().Type(), true); |
| |
| |
| |
| ErrorModuleHandler.GetInstance(); |
| int callCountSPN = EnProfiler.GetCountOfFunc("GetInstance", StaticGetType(ErrorModuleHandler), true); |
| |
| |
| if (!wasEnabled) |
| { |
| EnProfiler.Enable(false, true); |
| } |
| |
| |
| |
| |
| if (!Assert(callCountCF == 1)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountCFP == 1)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountRG == 1)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountC == 1)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountNon == -1)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountS == 1)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountG == 1)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountGP == 0)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountSP == 0)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountP == 0)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountPN == 0)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| |
| if (!Assert(callCountSPN == 0)) |
| { |
| return NTFR(TFR.FAIL); |
| } |
| |
| return NTFR(TFR.SUCCESS); |
| } |
| |
| |
| |
| |
| |
| float Sleep(float timeS) |
| { |
| float startTime = GetGame().GetTickTime(); |
| while (GetGame().GetTickTime() - startTime < timeS) |
| { |
| |
| } |
| |
| return GetGame().GetTickTime() - startTime; |
| } |
| |
| |
| |
| float StringFormat() |
| { |
| float startTime = GetGame().GetTickTime(); |
| |
| for (int i = 0; i < 1000; ++i) |
| { |
| string example = string.Format("This %1 is %2 just %3 an %4 example %5", i, Type(), this, startTime, "lorem ipsum 1 2 3"); |
| } |
| |
| return GetGame().GetTickTime() - startTime; |
| } |
| |
| |
| |
| float StringConcat() |
| { |
| float startTime = GetGame().GetTickTime(); |
| |
| for (int i = 0; i < 1000; ++i) |
| { |
| string example = "This " + i + " is " + Type() + " just " + this + " an " + startTime + " example " + "lorem ipsum 1 2 3"; |
| } |
| |
| return GetGame().GetTickTime() - startTime; |
| } |
| |
| |
| |
| void TestFuncCountDataHelper() |
| { |
| int dummy = 3; |
| } |
| |
| |
| |
| static void TestFuncCountDataHelperStatic() |
| { |
| int dummy = 3; |
| } |
| } |
|
|
| class EPTHelperClass |
| { |
| float Sleep2(float timeS) |
| { |
| float startTime = GetGame().GetTickTime(); |
| while (GetGame().GetTickTime() - startTime < timeS) |
| { |
| |
| } |
| |
| return GetGame().GetTickTime() - startTime; |
| } |
| float SleepAgain(float timeS) |
| { |
| float startTime = GetGame().GetTickTime(); |
| while (GetGame().GetTickTime() - startTime < timeS) |
| { |
| |
| } |
| |
| return GetGame().GetTickTime() - startTime; |
| } |
| |
| float DoEverything() |
| { |
| float startTime = GetGame().GetTickTime(); |
| |
| Sleep2(3); |
| SleepAgain(3); |
| |
| return GetGame().GetTickTime() - startTime; |
| } |
| } |