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.
#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
- Import the module as a client in manual mode. Pass
USE_GRAPHICS = falseif you do not want the overlay. - Call
Prof_init_highlevel()once. - Give each zone a slot in
zones(up toMAX_PROFILING_ZONES_FOR_MANUAL_MODE): set itsnameandinitted = true. A zone that is not initted is refused at run time and left out of reports. - Wrap the code with
zone_begin(index)andzone_end(). Zones nest, and a zone may nest in itself. - Call
update(true)once per frame. It closes the frame and files the times away. - Read the result with
create_report(), thenlog_text_report(report)orsave_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.
#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#
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#
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#
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.