Banner Image

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.

#PROFILER PROFILER

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?*


Banner Image

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 perfomance of your code.

Prerequisites

The modules os, io and lfs need to be desanizied. 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

PROFILER.ClassName

Name of the class.

PROFILER.Counters

Function counters.

PROFILER.Start(Delay, Duration)

Start profiler.

PROFILER.Stop(Delay)

Stop profiler.

PROFILER.ThreshCPS

Low calls per second threshold. Only write output if function has more calls per second than this value.

PROFILER.ThreshTtot

Total time threshold. Only write output if total function CPU time is more than this value.

PROFILER.TstartGame

Game start time timer.getTime().

PROFILER.TstartOS

OS real start time os.clock.

PROFILER._flog(f, txt)

Write text to log file.

PROFILER.dInfo

Info.

PROFILER.eventhandler

Event handler to get mission end event.

PROFILER.fTime

Function time.

PROFILER.fTimeTotal

Total function time.

PROFILER.fileNamePrefix

Output file name prefix, e.g. "MooseProfiler".

PROFILER.fileNameSuffix

Output file name prefix, e.g. "txt"

PROFILER.getData(func)

Get data.

PROFILER.getfilename(ext)

Write info to output file.

PROFILER.hook(event)

Debug hook.

PROFILER.logUnknown

Log unknown functions. Default is off.

PROFILER.printCSV(data, runTimeGame)

Print csv file.

PROFILER.showInfo(runTimeGame, runTimeOS)

Write info to output file.

PROFILER.showTable(data, f, runTimeGame)

Show table.

Fields and Methods inherited from PROFILER.Data Description

PROFILER.Data.count

Number of function calls.

PROFILER.Data.func

The function name.

PROFILER.Data.line

The line number

PROFILER.Data.src

The source file.

PROFILER.Data.tm

Total time in seconds.

PROFILER class.

Field(s)

#string PROFILER.ClassName

Name of the class.

#table PROFILER.Counters

Function counters.

#number PROFILER.ThreshCPS

Low calls per second threshold. Only write output if function has more calls per second than this value.

#number PROFILER.ThreshTtot

Total time threshold. Only write output if total function CPU time is more than this value.

#number PROFILER.TstartGame

Game start time timer.getTime().

#number PROFILER.TstartOS

OS real start time os.clock.

#table PROFILER.dInfo

Info.

#table PROFILER.eventhandler

Event handler to get mission end event.

#table PROFILER.fTime

Function time.

#table PROFILER.fTimeTotal

Total function time.

#string PROFILER.fileNamePrefix

Output file name prefix, e.g. "MooseProfiler".

#string PROFILER.fileNameSuffix

Output file name prefix, e.g. "txt"

#boolean PROFILER.logUnknown

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.

Debug hook.

Defined in:

PROFILER

Parameter:

#table event

Event.

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 PROFILER.Data.count

Number of function calls.

#string PROFILER.Data.func

The function name.

#number PROFILER.Data.line

The line number

#string PROFILER.Data.src

The source file.

#number PROFILER.Data.tm

Total time in seconds.

Function(s)