tiny.bench.ProfilingSession
Defined in tiny.bench.
API (18)
Actions
Public operations.
Fields and members
Public fields and members.
allocatorartifact_countartifactscapabilitiescapability_countcoz_sessionperf_artifactperf_regionperf_resulttracy_filetracy_outputtracy_startedtracy_summarytracy_summary_options
Source
Source: lib/bench/src/instrumentation.zig:129
zig
pub const ProfilingSession = struct { coz_session: CozSession = .{}, tracy_file: tracy.File = .{}, tracy_started: bool = false, tracy_output: ?[]const u8 = null, tracy_summary: ?[]const u8 = null, tracy_summary_options: tracy.summary.Options = .{}, perf_region: ?sys.perf.CounterRegion = null, perf_artifact: ?[]const u8 = null, perf_result: ?sys.perf.CountResult = null, allocator: ?Allocator = null, capabilities: [5]Capability = undefined, capability_count: usize = 0, artifacts: [8]Artifact = undefined, artifact_count: usize = 0, pub fn start(self: *ProfilingSession, allocator: Allocator, options: ProfilingSessionOptions) !void { self.deinit(); self.reset(); self.allocator = allocator; errdefer self.deinit(); if (options.coz_output) |path| { try ensureParent(path); try self.coz_session.startWithOutputPath(allocator, path); self.addCapability(.{ .name = .coz, .state = if (self.coz_session.enabled) .enabled else .unavailable, .requested = true, .artifact = path, .reason = if (self.coz_session.enabled) null else "coz runtime unavailable", }); self.addArtifact("coz_output", path); } else { self.addCapability(.{ .name = .coz, .state = .disabled, .reason = "no coz output path configured", }); } if (options.coz_summary) |path| self.addArtifact("coz_summary", path); if (options.tracy_output) |path| { self.tracy_output = path; self.tracy_summary = options.tracy_summary; self.tracy_summary_options = options.tracy_summary_options; if (!tracy.enabled) { self.addCapability(.{ .name = .tracy, .state = .unavailable, .requested = true, .artifact = path, .reason = "tracy build option disabled", }); if (options.require_tracy) return error.TracyUnavailable; } else { try ensureParent(path); try self.tracy_file.open(path); self.tracy_started = try tracy.start(self.tracy_file.interface().?, .{ .name = options.name }); self.addCapability(.{ .name = .tracy, .state = if (self.tracy_started) .enabled else .unavailable, .requested = true, .artifact = path, .reason = if (self.tracy_started) null else "tracy runtime unavailable", }); } self.addArtifact("tracy_output", path); if (options.tracy_summary) |summary_path| self.addArtifact("tracy_summary", summary_path); } else { self.addCapability(.{ .name = .tracy, .state = if (tracy.enabled) .disabled else .unavailable, .reason = if (tracy.enabled) "no tracy output path configured" else "tracy build option disabled", }); } self.addCapability(.{ .name = .stabilizer, .state = if (options.stabilizer_config != null) .enabled else .disabled, .requested = options.stabilizer_config != null, .reason = if (options.stabilizer_config != null) null else "layout randomization disabled", .stabilizer_config = options.stabilizer_config, }); if (options.memtrace_summary) |path| self.addArtifact("memtrace_summary", path); if (options.memtrace_events) |path| self.addArtifact("memtrace_events", path); self.addCapability(.{ .name = .memtrace, .state = if (options.memtrace_summary != null or options.memtrace_events != null) .enabled else .disabled, .requested = options.memtrace_summary != null or options.memtrace_events != null, .artifact = options.memtrace_summary orelse options.memtrace_events, .reason = if (options.memtrace_summary != null or options.memtrace_events != null) null else "no memtrace artifact configured", }); if (options.perf_artifact) |path| self.addArtifact("perf_counter", path); self.perf_artifact = options.perf_artifact; if (options.perf_counter) |counter| { self.perf_region = sys.perf.CounterRegion.start(counter, options.perf_counter_options) catch |err| { self.addCapability(.{ .name = .perf, .state = .unavailable, .requested = true, .artifact = options.perf_artifact, .reason = @errorName(err), }); return; }; self.addCapability(.{ .name = .perf, .state = .enabled, .requested = true, .artifact = options.perf_artifact, }); } else { self.addCapability(.{ .name = .perf, .state = .disabled, .requested = options.perf_artifact != null, .artifact = options.perf_artifact, .reason = if (options.perf_artifact != null) "no perf counter configured" else "no perf counter artifact configured", }); } } pub fn finish(self: *ProfilingSession) !void { var first_error: ?anyerror = null; self.finishPerfCounter() catch |err| rememberSessionError(&first_error, err); const write_tracy_summary = self.tracy_started; if (self.tracy_started) { tracy.stop(); self.tracy_started = false; } self.tracy_file.finish() catch |err| rememberSessionError(&first_error, err); if (write_tracy_summary) self.writeTracySummary() catch |err| rememberSessionError(&first_error, err); self.coz_session.finish() catch |err| rememberSessionError(&first_error, err); if (first_error) |err| return err; } pub fn deinit(self: *ProfilingSession) void { if (self.perf_region) |*region| { if (region.active) _ = region.stop() catch {}; region.deinit(); self.perf_region = null; } if (self.tracy_started) { tracy.stop(); self.tracy_started = false; } self.tracy_file.close(); self.coz_session.deinit(); } pub fn report(self: *const ProfilingSession) ProfilingReport { return .{ .capabilities = self.capabilities[0..self.capability_count], .artifacts = self.artifacts[0..self.artifact_count], }; } fn reset(self: *ProfilingSession) void { self.capability_count = 0; self.artifact_count = 0; self.tracy_started = false; self.tracy_output = null; self.tracy_summary = null; self.tracy_summary_options = .{}; self.perf_region = null; self.perf_artifact = null; self.perf_result = null; self.allocator = null; } fn addCapability(self: *ProfilingSession, capability: Capability) void { self.capabilities[self.capability_count] = capability; self.capability_count += 1; } fn addArtifact(self: *ProfilingSession, name: []const u8, path: []const u8) void { self.artifacts[self.artifact_count] = .{ .name = name, .path = path }; self.artifact_count += 1; } fn setCapability(self: *ProfilingSession, capability: Capability) void { for (self.capabilities[0..self.capability_count]) |*existing| { if (existing.name == capability.name) { existing.* = capability; return; } } self.addCapability(capability); } fn finishPerfCounter(self: *ProfilingSession) !void { var region = self.perf_region orelse return; self.perf_region = null; defer region.deinit(); if (!region.active) return; const result = region.stop() catch |err| { self.setCapability(.{ .name = .perf, .state = .unavailable, .requested = true, .artifact = self.perf_artifact, .reason = @errorName(err), }); return err; }; self.perf_result = result; if (self.perf_artifact) |path| try writePerfCounterResultFile(path, result); } fn writeTracySummary(self: *ProfilingSession) !void { const trace_path = self.tracy_output orelse return; const summary_path = self.tracy_summary orelse return; const allocator = self.allocator orelse return error.ProfilingSessionNotStarted; try writeTracySummaryJsonlFile(allocator, summary_path, trace_path, self.tracy_summary_options); }};Source: lib/bench/src/root.zig:48
zig
pub const ProfilingSession = instrumentation.ProfilingSession;Audit
| Definitions | 5 |
|---|---|
| Public names | 5 |
| Members | 14 |
| Version | 26.7.0 |
| Revision | daab053ee433 |