Modules

Iprof

moduleSource
macOSLinuxWindowswasm

#import "Iprof";

Iprof: a frame profiler with a text report and an optional overlay.

As a metaprogram plugin (+Iprof) it adds zones to your procedures for you. Manual mode (MANUAL_MODE = true) leaves that to you: you name the zones and open and close each one.

Show moreShow less
  1. Import the module as a client in manual mode. Pass USE_GRAPHICS = false if you do not want the overlay.
  2. Call Prof_init_highlevel() once.
  3. Give each zone a slot in zones (up to MAX_PROFILING_ZONES_FOR_MANUAL_MODE): set its name and initted = true. A zone that is not initted is refused at run time and left out of reports.
  4. Wrap the code with zone_begin(index) and zone_end(). Zones nest, and a zone may nest in itself.
  5. Call update(true) once per frame. It closes the frame and files the times away.
  6. Read the result with create_report(), then log_text_report(report) or save_csv_report(report, path).

The zones, the open-zone stack and the history are globals of the process, so zones cannot be opened from several threads, such as a job system's workers.

Example
#import "Iprof"(IMPORT_MODE = .CLIENT, MANUAL_MODE = true, USE_GRAPHICS = false, DO_HISTORY = false);

ZONE_FRAME :: 0;
ZONE_WORK :: 1;

main :: () {
    Prof_init_highlevel();
    zones[ZONE_FRAME].name = "frame";
    zones[ZONE_FRAME].initted = true;
    zones[ZONE_WORK].name = "work";
    zones[ZONE_WORK].initted = true;

    for 1..3 {
        zone_begin(ZONE_FRAME);
        zone_begin(ZONE_WORK);
        zone_end();
        zone_end();
        update(true);
    }

    report := create_report();
    assert(report.records.count == 2);
    log_text_report(report);
}

Doesn't run in the browser (skipped on wasm).

Procedures#

Iprof report#

(report: *Report, min_self_time := 0., min_hier_time := 0.)

Logs a report as text: a title line, a header, then one line per zone with its self time and hierarchical time in milliseconds, its call count and its heat. Rows below min_self_time or min_hier_time (milliseconds, 0 for all) are skipped.

(report: *Report, filename: string)

Writes a report to filename as CSV: the command line, then name,self (ms),hier (ms),calls per zone. A name with a quote or a comma is quoted. A failed write logs an error.

Iprof history values#

Iprof public state#

Iprof stack inspection#

Runtime zones#

(zone_index: s64)

Opens the zone in slot zone_index of zones (manual mode). Close it with zone_end(). The slot needs a name and initted = true first. Time until the matching zone_end counts toward the zone, and toward its parent for the hierarchical time.

()

Closes the zone most recently opened with zone_begin. Calling it with no zone open fails an assert.

Client setup#

Runtime traversal#

Frame history#

()

Sets up the frame history and the report state. Call it once before the first update. update and create_report call it too, so calling it twice is fine.

Frame report#

(variance: float64, value: float64) -> float64
() -> *Report

Builds a report of the frames recorded by update: one row per zone, in the current Report_Mode. The report lives in temporary storage, so print or save it before the next reset_temporary_storage. Rows of zones that were never called, or never initted in manual mode, are left out when printed.

Automatic zones#

Instrumentation#

(w: Workspace, iprof_hook_name: string, iprof_hook_args: string, user_hook_name: string, user_hook_args: string)

Graphics#

(x: float, y: float, full_width: float, requested_height: float, config: *Config)
(sx: float, sy: float, requested_width: float, requested_height: float, config: *Config)

Types#

Zonestruct
:: struct

Constants#

:: #string PROFILE_CLIENT_SETUP #scope_file Independent_Profile_Client :: #import "Iprof"(IMPORT_MODE = .CLIENT, MANUAL_MODE = false, USE_GRAPHICS = false, DO_HIST ...
:: "Iprof: -csv <filename>, -min_size <integer> (default 30), -modules\n"