VariableRange

Light-weight range that iterates over variables in profile data.

Constructed from a ForwardRange of Event (e.g. EventRange or a std.algorithm wrapper around an EventRange). Can also be constructed from raw profile data using variableRange().

More...

Constructors

this
this(ERange events)

Construct a VariableRange processing events from a range of Events.

Members

Functions

empty
bool empty()

Are there no more variables?

front
NamedVariable front()

Get the current variable.

popFront
void popFront()

Go to the next variable.

Properties

save
VariableRange save [@property getter]

Get a copy of the range in its current state.

Detailed Description

ForwardRange of NamedVariable ordered by time. Doesn't allocate any heap memory.

If profile data is incomplete (e.g. because the Profiler ran out of assigned memory in the middle of profiling), the last recorded variable may be ignored.

Ignores any variable events not followed by an info event (this may happen e.g. if a Profiler runs out of memory when recording a variable event).

Examples

// Print names and values of all recorded variables (once for each time they were
// recorded).

import tharsis.prof;

auto storage  = new ubyte[Profiler.maxEventBytes + 2048];
auto profiler = new Profiler(storage);

// Simulate 16 'frames'
foreach(frame; 0 .. 16)
{
    Zone topLevel = Zone(profiler, "frame");

    topLevel.variableEvent!"frame"(cast(uint)frame);
    topLevel.variableEvent!"frame2"(cast(uint)frame);
    // Simulate frame overhead. Replace this with your frame code.
    {
        import std.random;
        const random = uniform(1.0f, 5.0f);
        import std.stdio;
        writeln(random);
        topLevel.variableEvent!"somethingRandom"(random);
        Zone nested1 = Zone(profiler, "frameStart");
        foreach(i; 0 .. 1000) { continue; }
    }
    {
        Zone nested2 = Zone(profiler, "frameCore");
        foreach(i; 0 .. 10000) { continue; }
    }
}

import std.algorithm;

size_t i = 0;
ulong lastTime = 0;
// Write duration of each instance of the "frameCore" zone.
foreach(var; profiler.profileData.variableRange)
{
    assert(var.time >= lastTime);
    lastTime = var.time;

    if(i % 3 == 0)      { assert(var.name == "frame"); }
    else if(i % 3 == 1) { assert(var.name == "frame2"); }
    else if(i % 3 == 2) { assert(var.name == "somethingRandom"); }

    import std.stdio;
    writefln("%s: %s == %s", var.time, var.name, var.variable);
    ++i;
}

Meta