tiny.tldr.trace
Defined in tiny.tldr.
API (10)
Actions
Public operations.
PhaseTimers.callCountPhaseTimers.recordPhaseTimers.sumNsPhaseTimers.totalNsbeginPhaseTimingendPhaseTimingproductscope
Types and contracts
Public types and contracts.
Source
Source: lib/tldr/src/root.zig:59
zig
pub const trace = @import("trace.zig");Source: lib/tldr/src/trace.zig
zig
const std = @import("std");const coz = @import("coz");const model = @import("model.zig");const stage_count = @typeInfo(model.ProductStage).@"enum".field_names.len;pub const PhaseTimers = struct { totals_ns: [stage_count]u64 = @as([stage_count]u64, @splat(0)), calls: [stage_count]u64 = @as([stage_count]u64, @splat(0)), pub fn record(self: *PhaseTimers, stage: model.ProductStage, elapsed_ns: u64) void { const index = @backingInt(stage); _ = @atomicRmw(u64, &self.totals_ns[index], .Add, elapsed_ns, .monotonic); _ = @atomicRmw(u64, &self.calls[index], .Add, 1, .monotonic); } pub fn totalNs(self: *const PhaseTimers, stage: model.ProductStage) u64 { return self.totals_ns[@backingInt(stage)]; } pub fn callCount(self: *const PhaseTimers, stage: model.ProductStage) u64 { return self.calls[@backingInt(stage)]; } pub fn sumNs(self: *const PhaseTimers) u64 { var sum: u64 = 0; for (self.totals_ns) |value| sum += value; return sum; }};pub const Clock = *const fn () i128;var active_timers: ?*PhaseTimers = null;var active_clock: ?Clock = null;pub fn beginPhaseTiming(timers: *PhaseTimers, clock: Clock) void { active_timers = timers; active_clock = clock;}pub fn endPhaseTiming() void { active_timers = null; active_clock = null;}pub inline fn scope(comptime name: []const u8) coz.Scope("tldr." ++ name) { return coz.scope("tldr." ++ name);}pub inline fn product(comptime stage: model.ProductStage) ProductScope(stage) { return ProductScope(stage).begin();}fn ProductScope(comptime stage: model.ProductStage) type { const trace_name = "tldr." ++ stage.traceName(); const CozScope = coz.Scope(trace_name); return struct { coz_scope: CozScope, start_ns: i128, const Self = @This(); inline fn begin() Self { return .{ .coz_scope = coz.scope(trace_name), .start_ns = if (active_clock) |clock| clock() else 0, }; } pub inline fn end(self: Self) void { if (active_timers) |timers| { if (active_clock) |clock| { const elapsed = clock() - self.start_ns; timers.record(stage, if (elapsed < 0) 0 else @intCast(elapsed)); } } self.coz_scope.end(); } };}test "trace phase markers compile" { const phase = scope("test"); defer phase.end(); const product_phase = product(.manifest_recording); defer product_phase.end();}fn zeroClock() i128 { return 0;}test "phase timing accumulates while active" { var timers = PhaseTimers{}; beginPhaseTiming(&timers, zeroClock); { const phase = product(.output_writing); defer phase.end(); } endPhaseTiming(); try std.testing.expectEqual(@as(u64, 1), timers.callCount(.output_writing)); try std.testing.expectEqual(@as(u64, 0), timers.callCount(.input_discovery));}Complete caller list for trace.product
28 direct callers.
lib.tldr.src.formats.coff.applyRelocations[function] — private source atlib/tldr/src/formats/coff.zig:430in nearest public ownertiny.tldr.formats.cofftiny.tldr.formats.coff.linkExecutable[function] atlib/tldr/src/formats/coff.zig:103tiny.tldr.formats.coff.parseObject[function] atlib/tldr/src/formats/coff.zig:273lib.tldr.src.formats.elf.archive.member.addCandidates[function] — private source atlib/tldr/src/formats/elf/archive/member.zig:15in nearest public ownerlib.tldr.src.formats.elf.archive.memberlib.tldr.src.formats.elf.archive.prefetch.prepareSummaries[function] — private source atlib/tldr/src/formats/elf/archive/prefetch.zig:169in nearest public ownerlib.tldr.src.formats.elf.archive.prefetchlib.tldr.src.formats.elf.archive.select.ExtractionState.observeNewObjects[method] — private source atlib/tldr/src/formats/elf/archive/select.zig:197in nearest public ownerlib.tldr.src.formats.elf.archive.selectlib.tldr.src.formats.elf.archive.select.addCandidates[function] — private source atlib/tldr/src/formats/elf/archive/select.zig:238in nearest public ownerlib.tldr.src.formats.elf.archive.selectlib.tldr.src.formats.elf.archive.select.extractCandidatesBatched[function] — private source atlib/tldr/src/formats/elf/archive/select.zig:317in nearest public ownerlib.tldr.src.formats.elf.archive.selectlib.tldr.src.formats.elf.archive.select.extractCandidatesSerial[function] — private source atlib/tldr/src/formats/elf/archive/select.zig:275in nearest public ownerlib.tldr.src.formats.elf.archive.selecttiny.tldr.formats.elf.image.writer.write[function] atlib/tldr/src/formats/elf/image/writer.zig:30tiny.tldr.formats.elf.layout.collect.sections[function] atlib/tldr/src/formats/elf/layout/collect.zig:65tiny.tldr.formats.elf.linkExecutable[function] atlib/tldr/src/formats/elf/link.zig:59tiny.tldr.formats.elf.parser.parseObjectSelectionSummary[function] atlib/tldr/src/formats/elf/parser.zig:280tiny.tldr.formats.elf.parser.parseObjectWithOptions[function] atlib/tldr/src/formats/elf/parser.zig:397tiny.tldr.formats.elf.parser.parseObjectWithSelectionSummary[function] atlib/tldr/src/formats/elf/parser.zig:346lib.tldr.src.formats.macho.applyRelocations[function] — private source atlib/tldr/src/formats/macho.zig:459in nearest public ownertiny.tldr.formats.machotiny.tldr.formats.macho.linkExecutable[function] atlib/tldr/src/formats/macho.zig:92tiny.tldr.formats.macho.parseObject[function] atlib/tldr/src/formats/macho.zig:262tiny.tldr.link[function] atlib/tldr/src/link.zig:14lib.tldr.src.profiling.suite.planning.applyIndexed[function] — private source atlib/tldr/src/profiling/suite/planning.zig:217in nearest public ownerlib.tldr.src.profiling.suite.planninglib.tldr.src.profiling.suite.planning.applyLinear[function] — private source atlib/tldr/src/profiling/suite/planning.zig:205in nearest public ownerlib.tldr.src.profiling.suite.planninglib.tldr.src.profiling.suite.planning.decodeManifest[function] — private source atlib/tldr/src/profiling/suite/planning.zig:244in nearest public ownerlib.tldr.src.profiling.suite.planninglib.tldr.src.profiling.suite.planning.extractCandidate[function] — private source atlib/tldr/src/profiling/suite/planning.zig:229in nearest public ownerlib.tldr.src.profiling.suite.planninglib.tldr.src.profiling.suite.planning.planIndexed[function] — private source atlib/tldr/src/profiling/suite/planning.zig:195in nearest public ownerlib.tldr.src.profiling.suite.planninglib.tldr.src.profiling.suite.planning.planLinear[function] — private source atlib/tldr/src/profiling/suite/planning.zig:185in nearest public ownerlib.tldr.src.profiling.suite.planninglib.tldr.src.profiling.suite.planning.updateCandidateDiscarded256[function] — private source atlib/tldr/src/profiling/suite/planning.zig:161in nearest public ownerlib.tldr.src.profiling.suite.planninglib.tldr.src.trace.test_phase_timing_accumulates_while_active[function] — test source atlib/tldr/src/trace.zig:94in nearest public ownertiny.tldr.tracelib.tldr.src.trace.test_trace_phase_markers_compile[function] — test source atlib/tldr/src/trace.zig:83in nearest public ownertiny.tldr.trace
Audit
| Definitions | 11 |
|---|---|
| Public names | 11 |
| Members | 2 |
| Version | 26.7.0 |
| Revision | daab053ee433 |