Module Utilities.Profiler
Utils - Lua Profiler.
Find out how many times functions are called and how much real time it costs.
Author: TAW CougarNL, funkyfranky
Global(s)
Global PROFILER |
The emperor counsels simplicity. *First principles. |
The emperor counsels simplicity. *First principles.
Of each particular thing, ask: What is it in itself, in its own constitution? What is its causal nature?*
The PROFILER Concept
Profile your lua code. This tells you, which functions are called very often and which consume most real time. With this information you can optimize the performance of your code.
Prerequisites
The modules os, io and lfs need to be de-sanitized. Comment out the lines
--sanitizeModule('os')
--sanitizeModule('io')
--sanitizeModule('lfs')
in your "DCS World OpenBeta/Scripts/MissionScripting.lua" file.
But be aware that these changes can make you system vulnerable to attacks.
Disclaimer
Profiling itself is CPU expensive! Don't use this when you want to fly or host a mission.
Start
The profiler can simply be started with the PROFILER.Start(Delay, Duration) function
PROFILER.Start()
The optional parameter Delay can be used to delay the start by a certain amount of seconds and the optional parameter Duration can be used to stop the profiler after a certain amount of seconds.
Stop
The profiler automatically stops when the mission ends. But it can be stopped any time with the PROFILER.Stop(Delay) function
PROFILER.Stop()
The optional parameter Delay can be used to specify a delay after which the profiler is stopped.
When the profiler is stopped, the output is written to a file.
Output
The profiler output is written to a file in your DCS home folder
X:\User\<Your User Name>\Saved Games\DCS OpenBeta\Logs
The default file name is "MooseProfiler.txt". If that file exists, the file name is "MooseProfiler-001.txt" etc.
Data
The data in the output file provides information on the functions that were called in the mission.
It will tell you how many times a function was called in total, how many times per second, how much time in total and the percentage of time.
If you only want output for functions that are called more than X times per second, you can set
PROFILER.ThreshCPS=1.5
With this setting, only functions which are called more than 1.5 times per second are displayed. The default setting is PROFILER.ThreshCPS=0.0 (no threshold).
Furthermore, you can limit the output for functions that consumed a certain amount of CPU time in total by
PROFILER.ThreshTtot=0.005
With this setting, which is also the default, only functions which in total used more than 5 milliseconds CPU time.
Type(s)
Fields and Methods inherited from PROFILER | Description |
---|---|
Name of the class. |
|
Function counters. |
|
Start profiler. |
|
Stop profiler. |
|
Low calls per second threshold. Only write output if function has more calls per second than this value. |
|
Total time threshold. Only write output if total function CPU time is more than this value. |
|
Game start time timer.getTime(). |
|
OS real start time os.clock. |
|
Write text to log file. |
|
Info. |
|
Event handler to get mission end event. |
|
Function time. |
|
Total function time. |
|
Output file name prefix, e.g. "MooseProfiler". |
|
Output file name prefix, e.g. "txt" |
|
Get data. |
|
Write info to output file. |
|
Debug hook. |
|
Log unknown functions. Default is off. |
|
Print csv file. |
|
Write info to output file. |
|
Show table. |
Fields and Methods inherited from PROFILER.Data | Description |
---|---|
Number of function calls. |
|
The function name. |
|
The line number |
|
The source file. |
|
Total time in seconds. |
PROFILER class.
Field(s)
Name of the class.
Function counters.
Low calls per second threshold. Only write output if function has more calls per second than this value.
Total time threshold. Only write output if total function CPU time is more than this value.
Game start time timer.getTime().
OS real start time os.clock.
Info.
Event handler to get mission end event.
Function time.
Total function time.
Output file name prefix, e.g. "MooseProfiler".
Output file name prefix, e.g. "txt"
Log unknown functions. Default is off.
Function(s)
Start profiler.
Defined in:
PROFILER
Parameters:
#number Delay
Delay in seconds before profiler is stated. Default is immediately.
#number Duration
Duration in (game) seconds before the profiler is stopped. Default is when mission ends.
Stop profiler.
Defined in:
PROFILER
Parameter:
#number Delay
Delay before stop in seconds.
Write text to log file.
Defined in:
PROFILER
Parameters:
#function f
The file.
#string txt
The text.
Get data.
Defined in:
PROFILER
Parameter:
#function func
Function.
Return values:
#string:
Function name.
#string:
Source file name.
#string:
Line number.
#number:
Function time in seconds.
Write info to output file.
Defined in:
PROFILER
Parameter:
#string ext
Extension.
Return value:
#string:
File name.
Print csv file.
Defined in:
PROFILER
Parameters:
#table data
Data table.
#number runTimeGame
Game run time in seconds.
Write info to output file.
Defined in:
PROFILER
Parameters:
#number runTimeGame
Game time in seconds.
#number runTimeOS
OS time in seconds.
Show table.
Defined in:
PROFILER
Parameters:
#table data
Data table.
#function f
The file.
#number runTimeGame
Game run time in seconds.
Waypoint data.
Field(s)
Number of function calls.
The function name.
The line number
The source file.
Total time in seconds.