util.frameprofiler

Records which parts of a frame took how much time.

void frameProfilerPause();

Pause recording of profiling data.

Frames after this call won't be recorded - but their IDs (frame numbers) will still be incremented.
This can only be called outside of a frame.

void frameProfilerResume();

Resume recording of profiling data.

This can only be called outside of a frame.

struct Frame;

Single frame during a game run. Records time at construction and destruction. Keeps track of all zones within a frame, and frame number.

this(string frameInfo);

Construct a frame, recording its start time, ID, etc.

If frameProfilerInit has not been called, this is a noop.

Parameters:
string frameInfo String with information (e.g. name) about the frame. This is useful when parsing profile dumps later.
struct Zone;

Zone in profiled code. Records high precision time at construction and destruction. Zones can also be nested.

A zone must be fully contained within either a frame or a parent zone. I.e. it must be destroyed before its parent is destroyed.

this(string zoneInfo);

Construct a zone, recording its start time.

If frameProfilerInit has not been called this is a noop.

Parameters:
string zoneInfo String with information (e.g. name) about the zone. This is useful when parsing profile dumps later.
void frameProfilerInit(ubyte[] storage, const uint frameSkip = 0);

Initialize/enable frame profiler, provifing memory to store profile data.

If this is not called, any Zones/Frames and other frame profiler calls are noops, except for frameProfilerDump(), which must not be called.

Parameters:
ubyte[] storage Memory for the profiler to use to accumulate profile data. This must NOT be deallocated for as long as any FrameProfiler functions/classes are being used. When FrameProfiler runs out of this space, it stops recording profile data.
uint frameSkip Number of frames to skip between each recorded frame. For example, frameSkip 1 will result in every second frame being recorded. Can be used to limit profiler overhead and memory usage.
void frameProfilerDump(void delegate(string) dumpLine);

Dump recorded profile data.

This will dump in a human-readable YAML based format.
Can only be called if frameProfilerInit was called before.

Parameters:
void delegate(string) dumpLine This is called once for every output line. The passed string will NOT end with a newline - the function will have to add it itself, if needed.

Example:

 // Dump into stdout
 frameProfilerDump(void(string str){writeln(str);});

void frameProfilerEnd();

End frame profiler execution, returning it to state before frameProfilerInit().

The user is responsible for deleting any storage it passed to the frame profiler.