Skip to documentation
SLOP

tiny.profiling.capture.tracy

Reference tiny.profiling capture tracy

Defined in capture.

API (4)

Actions

Public operations.

Types and contracts

Public types and contracts.

Values and defaults

Public values and defaults.

No direct callersNo direct callscapturetracy
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallstest; no linksrc.profiling.capture.tracytest: tracy trace capture appends an ...test; no linksrc.profiling.capture.tracytest: tracy trace capture marks inval...private; no linksrc.profiling.capture.tracyappendRowprivate; no linksrc.profiling.capture.tracycaptureForIntegrityprivate; no linksrc.profiling.capture.tracyinvalidCapturecapture.tracyappendCapture
Static calls · unresolved targets: 0 · external targets: 1.

Source: src/profiling/capture/root.zig:3

zig
pub const tracy = @import("tracy.zig");

Source: src/profiling/capture/tracy.zig

zig
const std = @import("std");const capture = @import("capture");const sys = @import("sys");const host = @import("../root.zig").host;const fs_io = sys.fs.debugIo();pub const kind = "tracy_trace";pub const tool = "lib/tracy";pub const Options = struct {    enabled: bool,    exit_code: i64,    capture_path: []const u8,    summary_path: []const u8,};pub fn appendCapture(    allocator: std.mem.Allocator,    captures: []const host.Capture,    options: Options,) ![]const host.Capture {    if (!options.enabled or options.exit_code != 0) return captures;    const integrity = capture.tracy.parseSummaryFile(        allocator,        options.summary_path,    ) catch |err| switch (err) {        error.OutOfMemory => return err,        else => return try appendRow(allocator, captures, invalidCapture(options)),    };    return try appendRow(allocator, captures, captureForIntegrity(options, integrity));}fn appendRow(    allocator: std.mem.Allocator,    captures: []const host.Capture,    row: host.Capture,) ![]const host.Capture {    const result = try allocator.alloc(host.Capture, captures.len + 1);    @memcpy(result[0..captures.len], captures);    result[captures.len] = row;    return result;}fn captureForIntegrity(options: Options, integrity: capture.tracy.Integrity) host.Capture {    const complete = std.mem.eql(u8, integrity.status, "complete");    return .{        .kind = kind,        .tool = tool,        .scope = host.direct_scope,        .capture_path = options.capture_path,        .summary_path = options.summary_path,        .state = "summary_written",        .caveat_kind = if (complete) null else integrity.status,        .caveat_message = if (complete) null else integrity.message,    };}fn invalidCapture(options: Options) host.Capture {    return .{        .kind = kind,        .tool = tool,        .scope = host.direct_scope,        .capture_path = options.capture_path,        .summary_path = options.summary_path,        .state = "summary_invalid",        .caveat_kind = "invalid_trace_summary",        .caveat_message = "Tracy summary does not contain valid capture integrity evidence",    };}fn testIntegrity(status: []const u8, message: ?[]const u8) capture.tracy.Integrity {    return .{        .status = status,        .action = if (message == null) "none" else "inspect_trace_transport",        .message = message,        .event_count = 3,        .sequenced_event_count = 3,        .unsequenced_event_count = 0,        .first_sequence = 1,        .last_sequence = 3,        .sequence_gap_count = if (message == null) 0 else 1,        .missing_sequence_event_count = if (message == null) 0 else 1,        .sequence_regression_count = 0,        .start_event_count = 1,        .stop_event_count = 1,        .start_sequence = 1,        .stop_sequence = 3,        .unbalanced_event_count = 0,    };}test "tracy trace capture maps complete and partial canonical integrity" {    const options: Options = .{        .enabled = true,        .exit_code = 0,        .capture_path = "bench.tracy.jsonl",        .summary_path = "bench.tracy.summary.jsonl",    };    const complete = captureForIntegrity(options, testIntegrity("complete", null));    try std.testing.expectEqualStrings("summary_written", complete.state);    try std.testing.expect(complete.caveat_kind == null);    try std.testing.expect(complete.caveat_message == null);    try std.testing.expectEqualStrings(host.direct_scope, complete.scope);    const message = "Tracy event sequence has gaps; treat the summary as partial evidence";    const partial = captureForIntegrity(options, testIntegrity("sequence_gaps", message));    try std.testing.expectEqualStrings("sequence_gaps", partial.caveat_kind.?);    try std.testing.expectEqualStrings(message, partial.caveat_message.?);}test "tracy trace capture appends an offline integrity summary" {    var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);    defer arena_state.deinit();    const allocator = arena_state.allocator();    var tmp = std.testing.tmpDir(.{});    defer tmp.cleanup();    const text =        "{\"kind\":\"summary\",\"capture_integrity\":{" ++        "\"method\":\"tracy_event_sequence_and_lifecycle_v1\"," ++        "\"status\":\"sequence_gaps\",\"action\":\"inspect_trace_transport\"," ++        "\"message\":\"partial trace\",\"event_count\":3," ++        "\"sequenced_event_count\":3,\"unsequenced_event_count\":0," ++        "\"first_sequence\":1,\"last_sequence\":4,\"sequence_gap_count\":1," ++        "\"missing_sequence_event_count\":1,\"sequence_regression_count\":0," ++        "\"start_event_count\":1,\"stop_event_count\":1," ++        "\"start_sequence\":1,\"stop_sequence\":4," ++        "\"unbalanced_event_count\":0}}\n";    try tmp.dir.writeFile(fs_io, .{ .sub_path = "summary.jsonl", .data = text });    const root = try tmp.dir.realPathFileAlloc(fs_io, ".", allocator);    const summary_path = try std.fs.path.join(allocator, &.{ root, "summary.jsonl" });    const rows = try appendCapture(allocator, &.{}, .{        .enabled = true,        .exit_code = 0,        .capture_path = "trace.jsonl",        .summary_path = summary_path,    });    try std.testing.expectEqual(@as(usize, 1), rows.len);    try std.testing.expectEqualStrings("summary_written", rows[0].state);    try std.testing.expectEqualStrings("sequence_gaps", rows[0].caveat_kind.?);    try std.testing.expectEqualStrings("partial trace", rows[0].caveat_message.?);}test "tracy trace capture marks invalid summaries and skips unsuccessful capture" {    var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);    defer arena_state.deinit();    const allocator = arena_state.allocator();    var tmp = std.testing.tmpDir(.{});    defer tmp.cleanup();    try tmp.dir.writeFile(fs_io, .{ .sub_path = "invalid.jsonl", .data = "{}\n" });    const root = try tmp.dir.realPathFileAlloc(fs_io, ".", allocator);    const path = try std.fs.path.join(allocator, &.{ root, "invalid.jsonl" });    const options: Options = .{        .enabled = true,        .exit_code = 0,        .capture_path = "trace.jsonl",        .summary_path = path,    };    const invalid = try appendCapture(allocator, &.{}, options);    try std.testing.expectEqualStrings("summary_invalid", invalid[0].state);    try std.testing.expectEqualStrings("invalid_trace_summary", invalid[0].caveat_kind.?);    var failed = options;    failed.exit_code = 1;    try std.testing.expectEqual(@as(usize, 0), (try appendCapture(allocator, &.{}, failed)).len);    var disabled = options;    disabled.enabled = false;    try std.testing.expectEqual(@as(usize, 0), (try appendCapture(allocator, &.{}, disabled)).len);}

Audit

Definitions5
Public names5
Members4
Version26.7.0
Revisiondaab053ee433