class EnProfilerSource
Part of Enforce Script profiling API
Set of methods for accessing script profiling data
Methods 42
Enable the gathering of script profiling data
enableboolWhether to enable or disable, if it was previously not enabled, it will cause [SR]immediateboolWhen true will instantly start/stop profiling, otherwise it will apply it at the end of the frame (to have one stable point in time)sessionResetboolWhen set to false, no [SR] will trigger, regardless of situation
// Simple enable, will start profiling the next frame
// Will cause [SR] if !IsEnabledP() before this call
EnProfiler.Enable(true);
// Immediate enable, will start profiling immediately
// Will cause [SR] if !IsEnabledP() before this call
EnProfiler.Enable(true, true);
// Immediate disable, will stop profiling immediately
// Disabling will never cause [SR], preserving data
EnProfiler.Enable(false, true);
// Simple disable, will not profile the next frame (but still finish profiling the current one)
// Disabling will never cause [SR], preserving data
EnProfiler.Enable(false);static proto int IsEnabled()Return if script profiling is enabled
Returns: int Flags regarding the current state
int isScriptProfilingEnabled = EnProfiler.IsEnabled();static bool IsEnabledD()Return if script profiling is enabled through [DM]
Returns: bool Whether script profiling is enabled through [DM]
bool isScriptProfilingDiagEnabled = EnProfiler.IsEnabledD();static bool IsEnabledP()Return if script profiling is enabled through EnProfiler
Returns: bool Whether script profiling is enabled through script profiler
bool isScriptProfilingToggleEnabled = EnProfiler.IsEnabledP();static bool IsEnabledC()Return if script profiling is actually turned on inside of the script context
Returns: bool Whether script is being profiled as of this moment
bool isScriptProfilingEnabled = EnProfiler.IsEnabledC();static proto void SortData()The internal sorting that happens at the end of the frame (so it is NOT necessary to call this manually) to supply Get...Per... functions
// Sorting all the currently available [PD], populating [SD]
EnProfiler.SortData();
// If flag EnProfilerFlags.RESET is enabled, then this will return 0 now even if it has been called, as [PD] has been cleared
// This goes for any Get...Of... function (Except for [CI], the counter persists)
EnProfiler.GetTimeOfFunc("Sleep", EnProfilerTests, true);static proto void ResetSession(bool fullReset = false)Perform [SR], clearing SessionFrame, ProfiledSessionFrames, [SD] and [PD] (except for [CI])
fullResetboolWhether to clear [PD] of all modules, when false it will only clear the [PD] according to current settings
// Considering the settings: SetFlags(EnProfilerFlags.NONE) and SetModule(EnProfilerModule.GAME)
// The following call will only clear [PD] of 3_Game
EnProfiler.ResetSession();
// Considering the settings: SetFlags(EnProfilerFlags.RECURSIVE) and SetModule(EnProfilerModule.WORLD)
// The following call will clear [PD] of 3_Game, 4_World, 5_Mission and their children
EnProfiler.ResetSession();
// The following call resets [PD] across all modules
EnProfiler.ResetSession(true);Override the currently used set of EnProfilerFlags across the API
flagsintThe combination of desired EnProfilerFlags to override the currently used setsessionResetboolWhen set to false, no [SR] will trigger, regardless of situation
Returns: int The currently used set of EnProfilerFlags after the function call
// No RESET flag, [PD] will be accumulated across frames
// No RECURSIVE flag, only the curently profiled module will be sorted
EnProfiler.SetFlags(EnProfilerFlags.NONE);
// RESET flag, [PD] will be reset after sorting
// No RECURSIVE flag, only the curently profiled module will be sorted
EnProfiler.SetFlags(EnProfilerFlags.RESET);
// RESET flag, [PD] will be reset after sorting
// RECURSIVE flag, all modules will be sorted
EnProfiler.SetFlags(EnProfilerFlags.ALL);Show 1 more
, EnProfilerTests.TestSetFlags()static proto int GetFlags()Get the currently used flags across the API
Returns: int The currently used set of EnProfilerFlags
int flags = EnProfiler.GetFlags();
if (flags & EnProfilerFlags.RECURSIVE)
{
Print("Currently profiling all modules.");
}Show 1 more
, EnProfilerTests.TestSetFlags()Check if the flags are set
flagsintThe combination of EnProfilerFlags to check if present
Returns: bool If the flags are set
if (EnProfiler.IsFlagsSet(EnProfilerFlags.ALL))
{
Print("Currently all flags are enabled.");
}
if (EnProfiler.IsFlagsSet(EnProfilerFlags.RECURSIVE))
{
Print("Currently profiling all modules.");
}Add flags to the currently used set of EnProfilerFlags across the API
flagsintThe combination of desired EnProfilerFlags to be added to the currently used setsessionResetboolWhen set to false, no [SR] will trigger, regardless of situation
Returns: int The currently used set of EnProfilerFlags after the function call
// In the case where the current set of EnProfilerFlags is EnProfilerFlags.RESET
EnProfiler.AddFlags(EnProfilerFlags.RECURSIVE);
// The resulting set of flags now will be EnProfilerFlags.RESET | EnProfilerFlags.RECURSIVE
// As the above is pretty much the same as the following
// EnProfiler.SetFlags(EnProfiler.GetFlags() | EnProfilerFlags.RECURSIVE);
// But a much cleaner and faster alternative (bitwise operations in script is ~10x slower than C++)Remove flags from the currently used set of EnProfilerFlags across the API
flagsintThe combination of desired EnProfilerFlags to be added to the currently used setsessionResetboolWhen set to false, no [SR] will trigger, regardless of situation
Returns: int The currently used set of EnProfilerFlags after the function call
// In the case where the current set of EnProfilerFlags is EnProfilerFlags.RESET
EnProfiler.RemoveFlags(EnProfilerFlags.RESET);
// The resulting set of flags now will be EnProfilerFlags.NONE
// As the above is pretty much the same as the following
// EnProfiler.SetFlags(EnProfiler.GetFlags() & ~EnProfilerFlags.RECURSIVE);
// But a much cleaner and faster alternative (bitwise operations in script is ~10x slower than C++)Remove all flags from the currently used set of EnProfilerFlags across the API
sessionResetboolWhen set to false, no [SR] will trigger, regardless of situation
Returns: int The currently used set of EnProfilerFlags after the function call
// In the case where the current set of EnProfilerFlags is EnProfilerFlags.RESET
EnProfiler.ClearFlags();
// The resulting set of flags now will be EnProfilerFlags.NONE
// As the above is pretty much the same as the following
// EnProfiler.SetFlags(EnProfilerFlags.NONE);
// But a much cleaner and implicit alternativestatic proto void SetModule(EnProfilerModule module, bool sessionReset = true)Set the module to be profiled
moduleEnProfilerModuleThe module to profilesessionResetboolWhen set to false, no [SR] will trigger, regardless of situation
EnProfiler.SetModule(EnProfilerModule.WORLD);static proto EnProfilerModule GetModule()Get the currently profiled module
Returns: EnProfilerModule The currently profiled module
EnProfilerModule module = EnProfiler.GetModule();static proto owned string ModuleToName(EnProfilerModule module)Helper to convert EnProfilerModule to string
moduleEnProfilerModuleThe module to get the name of
Returns: string The name of the module
string moduleName = EnProfiler.ModuleToName(EnProfilerModule.GAME);static proto bool NameToModule(string moduleName, out EnProfilerModule module)Convert string to EnProfilerModule
moduleNamestringThe name of the modulemoduleEnProfilerModuleThe enum value of the module or EnProfilerModule.ERROR if not found
Returns: bool Whether the module was found
// Get the name of the module of the current class
string nameOfCurrentModule = Type().GetModule();
EnProfilerModule module;
// Convert it to the enum value
if (EnProfiler.NameToModule(nameOfCurrentModule, module))
{
EnProfiler.SetModule(module);
}
else
{
ErrorEx(string.Format("Could not find EnProfilerModule: %1", nameOfCurrentModule));
}Set the interval for the [SD] to update
intervalintAmount of frames to wait before [SD] is updatedsessionResetboolWhen set to false, no [SR] will trigger, regardless of situation
// This will make it so that [SD] is updated every 60 frames
EnProfiler.SetInterval(60);static proto int GetInterval()Get the currently set interval
Returns: int The currently set interval
int currentInterval = EnProfiler.GetInterval();static proto void SetTimeResolution(int resolution)Set the resolution of the fetched Time data
resolutionintThe nth resolution of a second
// Have all time being reported in 1 second
EnProfiler.SetTimeResolution(1);
// Have all time being reported in 1000th of a second (ms)
EnProfiler.SetTimeResolution(1000);static proto int GetTimeResolution()Get the currently set time resolution
Returns: int The currently set resolution
int currentTimeResolution = EnProfiler.GetTimeResolution();static proto void EnableAverage(bool enable)Enable/disable returning calculated averages
enableboolWhether to enable or disable
// For example, take the situation where we only reset every 60 frames
EnProfiler.AddFlags(EnProfilerFlags.RESET);
EnProfiler.SetInterval(60);
EnProfiler.EnableAverage(true);
// And a method is called once per frame, gathering the count of that function will be 1
// Or if a method is called twice per frame, gathering the count of that function will be 2
// Or if a method is 3 times every 3 frames, gathering the count of that function will be 1
// ...
// So you get the average amount of times the method is called per frame, out of the sample of 60 framesstatic proto bool IsAverage()Check if returning of average data is enabled
Returns: bool Whether returning of average data is enabled
bool isDataAverage = EnProfiler.IsAverage();static proto void Dump()Print out [SD] to script log
EnProfiler.Dump();static proto int GetGameFrame()Get the total amount of frames passed
Returns: int The total amount of frames passed
int gameFrame = EnProfiler.GetGameFrame();static proto int GetSessionFrame()Get the total amount of frames in this profiling session
Returns: int The total amount of frames in this profiling session
int sessionFrame = EnProfiler.GetSessionFrame();static proto int GetTotalFrames()Get the total amount of frames across all profiling session
Returns: int The total amount of frames across all profiling session
int totalFrames = EnProfiler.GetTotalFrames();static proto int GetProfiledSessionFrames()Get the total amount of frames profiled in this profiling session
Returns: int The total amount of frames profiled in this profiling session
int profiledSessionFrames = EnProfiler.GetProfiledSessionFrames();static proto int GetProfiledFrames()Get the total amount of frames profiled across all profiling session
Returns: int The total amount of frames profiled across all profiling session
int totalProfiledFrames = EnProfiler.GetProfiledFrames();static proto void GetTimePerClass(notnull out array<ref EnProfilerTimeClassPair> outArr, int count = int.MAX)Obtain [SD] for Time Per Class
outArrarray<refEnProfilerTimeClassPair> Array sorted by time consumed by a classcountintThe maximum amount of entries wanted
// In this example the array will be filled with the 20 most time intensive classes
// If there are less than 20 classes which consumed time, it will output that number of classes instead
array<ref EnProfilerTimeClassPair> timePerClass = {};
EnProfiler.GetTimePerClass(timePerClass, 20);
// In this example the array will be filled with all classes sorted by time
array<ref EnProfilerTimeClassPair> timePerClass2 = {};
EnProfiler.GetTimePerClass(timePerClass2);static proto void GetAllocationsPerClass(notnull out array<ref EnProfilerCountClassPair> outArr, int count = int.MAX)Obtain [SD] for Allocations Per Class
outArrarray<refEnProfilerCountClassPair> Array sorted by number of allocations of a classcountintThe maximum amount of entries wanted
array<ref EnProfilerCountClassPair> allocPerClass = {};
EnProfiler.GetAllocationsPerClass(allocPerClass, 20);static proto void GetInstancesPerClass(notnull out array<ref EnProfilerCountClassPair> outArr, int count = int.MAX)Obtain [SD] for Instances Per Class
outArrarray<refEnProfilerCountClassPair> Array sorted by number of instances of a classcountintThe maximum amount of entries wanted
array<ref EnProfilerCountClassPair> instancesPerClass = {};
EnProfiler.GetInstancesPerClass(instancesPerClass, 20);static proto void GetTimePerFunc(notnull out array<ref EnProfilerTimeFuncPair> outArr, int count = int.MAX)Obtain [SD] for Time Per Function
outArrarray<refEnProfilerTimeFuncPair> Array sorted by time consumed by a functioncountintThe maximum amount of entries wanted
array<ref EnProfilerTimeFuncPair> timePerFunc = {};
EnProfiler.GetTimePerFunc(timePerFunc, 20);static proto void GetCountPerFunc(notnull out array<ref EnProfilerCountFuncPair> outArr, int count = int.MAX)Obtain [SD] for Count Per Function
outArrarray<refEnProfilerCountFuncPair> Array sorted by amount of times a function was calledcountintThe maximum amount of entries wanted
array<ref EnProfilerCountFuncPair> countPerFunc = {};
EnProfiler.GetCountPerFunc(countPerFunc, 20);Obtain [SD] or [PD] regarding the time a specific class consumed
clsstypenameTypename of desired classimmediateboolWhen true, it will pull from [SD], when false it will pull from [PD]
Returns: float Time consumed by the specified class
// Consider the class
EPTHelperClass clss = new EPTHelperClass();
// Some functions being called here...
// Gathering of data can be done through
float timeOfClass = EnProfiler.GetTimeOfClass(clss.Type(), true);
// Or when you have no variable/reference
float timeOfClass2 = EnProfiler.GetTimeOfClass(StaticGetType(EPTHelperClass), true);Obtain [SD] or [PD] regarding the allocations of a specific class
clsstypenameTypename of desired classimmediateboolWhen true, it will pull from [SD], when false it will pull from [PD]
Returns: int Allocations of the specified class
int allocationsOfClass = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);Obtain [SD] or [PD] regarding the [CI] of a specific class
clsstypenameTypename of desired classimmediateboolWhen true, it will pull from [SD], when false it will pull from [PD]
Returns: int [CI] of the specified class
int instancesOfClass = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);Obtain [SD] or [PD] regarding the time consumed by a specific function
functstringFunction nameclsstypenameTypename of class the function belongs toimmediateboolWhen true, it will pull from [SD], when false it will pull from [PD]
Returns: float Time consumed by the specified function or -1 when function was not found
float timeOfFunc = EnProfiler.GetTimeOfFunc("StringFormat", StaticGetType(EnProfilerTests), true);Obtain [SD] or [PD] regarding the time consumed by a specific global function
functstringFunction nameimmediateboolWhen true, it will pull from [SD], when false it will pull from [PD]
Returns: float Time consumed by the specified function or -1 when function was not found
float timeOfFunc = EnProfiler.GetTimeOfFuncG("ErrorEx", true);Obtain [SD] or [PD] regarding the amount of times a specific function was called
functstringFunction nameclsstypenameTypename of class the function belongs toimmediateboolWhen true, it will pull from [SD], when false it will pull from [PD]
Returns: int Amount of calls to the specified function or -1 when function was not found
int callCountOfFunc = EnProfiler.GetCountOfFunc("StringFormat", StaticGetType(EnProfilerTests), true);Obtain [SD] or [PD] regarding the amount of times a specific function was called
functstringFunction nameimmediateboolWhen true, it will pull from [SD], when false it will pull from [PD]
Returns: int Amount of calls to the specified function or -1 when function was not found
int callCountOfFunc = EnProfiler.GetCountOfFuncG("ErrorEx", true);static bool RequestImmediateData()Helper method to ascertain the profiler will record [PD] right after this call
Returns: bool Whether it was enabled before or not
bool wasEnabled = EnProfiler.RequestImmediateData();