package profile import "core:fmt" import "core:strings" import "core:time" Counters :: struct { frame_count: u64, app_frame_count: u64, app_wall_seconds: f64, frame_begin_ns: i64, frame_end_ns: i64, render_pass_begin_ns: i64, ir2d_lower_ns: i64, ir3d_lower_ns: i64, compute_lower_ns: i64, ir2d_commands: u64, ir3d_commands: u64, compute_dispatches: u64, batch_flushes: u64, queue3d_flushes: u64, draw_indexed_calls: u64, dispatch_calls: u64, pipeline_binds: u64, descriptor_binds: u64, descriptor_updates: u64, push_constants: u64, vertices_submitted: u64, indices_submitted: u64, } now :: proc() -> time.Time { return time.now() } elapsed_ns :: proc(start, stop: time.Time) -> i64 { return time.duration_nanoseconds(time.diff(start, stop)) } to_json :: proc(c: Counters, allocator := context.allocator) -> string { buf := strings.builder_make(allocator) strings.write_string(&buf, "{") fmt.sbprintf(&buf, "\"frame_count\":%d", c.frame_count) fmt.sbprintf(&buf, ",\"app_frame_count\":%d", c.app_frame_count) fmt.sbprintf(&buf, ",\"app_wall_seconds\":%.9f", c.app_wall_seconds) fmt.sbprintf(&buf, ",\"frame_begin_ns\":%d", c.frame_begin_ns) fmt.sbprintf(&buf, ",\"frame_end_ns\":%d", c.frame_end_ns) fmt.sbprintf(&buf, ",\"render_pass_begin_ns\":%d", c.render_pass_begin_ns) fmt.sbprintf(&buf, ",\"ir2d_lower_ns\":%d", c.ir2d_lower_ns) fmt.sbprintf(&buf, ",\"ir3d_lower_ns\":%d", c.ir3d_lower_ns) fmt.sbprintf(&buf, ",\"compute_lower_ns\":%d", c.compute_lower_ns) fmt.sbprintf(&buf, ",\"ir2d_commands\":%d", c.ir2d_commands) fmt.sbprintf(&buf, ",\"ir3d_commands\":%d", c.ir3d_commands) fmt.sbprintf(&buf, ",\"compute_dispatches\":%d", c.compute_dispatches) fmt.sbprintf(&buf, ",\"batch_flushes\":%d", c.batch_flushes) fmt.sbprintf(&buf, ",\"queue3d_flushes\":%d", c.queue3d_flushes) fmt.sbprintf(&buf, ",\"draw_indexed_calls\":%d", c.draw_indexed_calls) fmt.sbprintf(&buf, ",\"dispatch_calls\":%d", c.dispatch_calls) fmt.sbprintf(&buf, ",\"pipeline_binds\":%d", c.pipeline_binds) fmt.sbprintf(&buf, ",\"descriptor_binds\":%d", c.descriptor_binds) fmt.sbprintf(&buf, ",\"descriptor_updates\":%d", c.descriptor_updates) fmt.sbprintf(&buf, ",\"push_constants\":%d", c.push_constants) fmt.sbprintf(&buf, ",\"vertices_submitted\":%d", c.vertices_submitted) fmt.sbprintf(&buf, ",\"indices_submitted\":%d", c.indices_submitted) strings.write_string(&buf, "}") return strings.to_string(buf) }