Skip to documentation
SLOP

tiny.profiling.ingest.collection

Reference tiny.profiling ingest collection

Defined in ingest.

API (1)

Actions

Public operations.

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

Source

Called byCallsNo direct callstest; no linksrc.profiling.ingest.collectiontest: artifact ingestion reports cold...test; no linksrc.profiling.ingest.collectiontest: profiling ingestion preserves s...test; no linksrc.profiling.ingest.collectiontest: profiling ingestion retains a p...ingest.collectioncollect
Static calls · unresolved targets: 1 · external targets: 4.

Source: src/profiling/ingest/collection.zig

zig
const std = @import("std");const alloc_phase = @import("alloc_phase");const sys = @import("sys");const profiling = @import("../root.zig");const ingest = @import("root.zig");pub fn collect(    allocator: std.mem.Allocator,    workload: profiling.catalog.Workload,    paths: ingest.Paths,) !ingest.Summary {    std.debug.assert(workload.name.len > 0);    std.debug.assert(paths.structured.len > 0);    const limits = try ingest.Limits.inspect(paths);    var ingestion = try ingest.ArtifactIngestion.init(allocator, limits);    defer ingestion.deinit(allocator);    try ingestion.activate();    return ingestion.write(workload);}const OwnedPaths = struct {    paths: ingest.Paths,    fn init(allocator: std.mem.Allocator, root: []const u8) !OwnedPaths {        std.debug.assert(root.len > 0);        const result = OwnedPaths{ .paths = .{            .stdout = try std.fs.path.join(allocator, &.{ root, "stdout.txt" }),            .stderr = try std.fs.path.join(allocator, &.{ root, "stderr.txt" }),            .bench_jsonl = try std.fs.path.join(allocator, &.{ root, "bench.jsonl" }),            .coz_jsonl = try std.fs.path.join(allocator, &.{ root, "coz.jsonl" }),            .coz_analysis = try std.fs.path.join(allocator, &.{ root, "coz.analysis.json" }),            .tracy_summary = try std.fs.path.join(allocator, &.{ root, "tracy.summary.jsonl" }),            .allocations = try std.fs.path.join(allocator, &.{ root, "allocations.jsonl" }),            .structured = try std.fs.path.join(allocator, &.{ root, "structured.jsonl" }),        } };        assertOwnedPaths(result.paths, root.len);        return result;    }    fn deinit(self: OwnedPaths, allocator: std.mem.Allocator) void {        assertOwnedPaths(self.paths, 0);        allocator.free(self.paths.stdout);        allocator.free(self.paths.stderr);        allocator.free(self.paths.bench_jsonl);        allocator.free(self.paths.coz_jsonl);        allocator.free(self.paths.coz_analysis);        allocator.free(self.paths.tracy_summary);        allocator.free(self.paths.allocations);        allocator.free(self.paths.structured);    }};fn assertOwnedPaths(paths: ingest.Paths, minimum: usize) void {    std.debug.assert(paths.stdout.len > minimum);    std.debug.assert(paths.stderr.len > minimum);    std.debug.assert(paths.bench_jsonl.len > minimum);    std.debug.assert(paths.coz_jsonl.len > minimum);    std.debug.assert(paths.coz_analysis.len > minimum);    std.debug.assert(paths.tracy_summary.len > minimum);    std.debug.assert(paths.allocations.len > minimum);    std.debug.assert(paths.structured.len > minimum);}const Fixture = struct {    temporary: std.testing.TmpDir,    root: [:0]u8,    paths: OwnedPaths,};fn testFixture(allocator: std.mem.Allocator) !Fixture {    var temporary = std.testing.tmpDir(.{});    errdefer temporary.cleanup();    const root = try temporary.dir.realPathFileAlloc(sys.fs.debugIo(), ".", allocator);    std.debug.assert(root.len > 0);    errdefer allocator.free(root);    const paths = try OwnedPaths.init(allocator, root);    std.debug.assert(paths.paths.structured.len > root.len);    return .{ .temporary = temporary, .root = root, .paths = paths };}fn cleanupFixture(fixture: anytype, allocator: std.mem.Allocator) void {    std.debug.assert(fixture.root.len > 0);    fixture.paths.deinit(allocator);    allocator.free(fixture.root);    fixture.temporary.cleanup();}fn initializeOwner(allocator: std.mem.Allocator, limits: ingest.Limits) !void {    var ingestion = try ingest.ArtifactIngestion.init(allocator, limits);    std.debug.assert(ingestion.phase == .initialization);    defer ingestion.deinit(allocator);    try ingestion.activate();    std.debug.assert(ingestion.phase == .steady);}test "profiling ingestion preserves structured rows and allocation counters" {    const allocator = std.testing.allocator;    var fixture = try testFixture(allocator);    defer cleanupFixture(&fixture, allocator);    const paths = fixture.paths.paths;    try sys.fs.writeFile(        paths.stdout,        "human\n{\"event\":\"bench_end\",\"name\":\"a\",\"median_ns\":10}\n",    );    try sys.fs.writeFile(paths.stderr, "{\"broken\":}\n");    try sys.fs.writeFile(paths.tracy_summary,        \\{"kind":"zone","name":"bench.sample","count":1,"mean_ns":10}        \\    );    try sys.fs.writeFile(paths.allocations,        \\{"kind":"alloc","len":64}        \\{"kind":"resize","old_len":64,"new_len":96}        \\{"kind":"free","len":96}        \\    );    const result = try collect(        allocator,        profiling.catalog.find("gpalloc.allocator").?,        paths,    );    try std.testing.expectEqual(@as(usize, 7), result.rows);    try std.testing.expectEqual(@as(usize, 1), result.parse_errors);    try std.testing.expectEqual(@as(usize, 4), result.sources);    const structured = try sys.fs.readFileAlloc(allocator, paths.structured, 4096);    defer allocator.free(structured);    try std.testing.expect(std.mem.indexOf(        u8,        structured,        "\"schema\":\"tiny.profiling.structured/v1\"",    ) != null);    try std.testing.expect(std.mem.indexOf(        u8,        structured,        "\"row\":{\"event\":\"bench_end\"",    ) != null);    try std.testing.expect(std.mem.indexOf(        u8,        structured,        "\"metric\":\"allocated_bytes\"",    ) != null);    try std.testing.expect(std.mem.indexOf(        u8,        structured,        "\"kind\":\"tracy_summary\"",    ) != null);    try std.testing.expect(std.mem.indexOf(        u8,        structured,        "\"kind\":\"alloc\",\"len\"",    ) == null);}test "profiling ingestion retains a positive benchmark allocation witness" {    const allocator = std.testing.allocator;    var fixture = try testFixture(allocator);    defer cleanupFixture(&fixture, allocator);    const paths = fixture.paths.paths;    try sys.fs.writeFile(        paths.bench_jsonl,        "{\"event\":\"bench_end\",\"sample_ns\":[1],\"alloc_bytes\":4096}\n" ++            "{\"schema\":\"tiny.profiling.metric/v1\"," ++            "\"allocated_bytes\":8192}\n",    );    try sys.fs.writeFile(        paths.stdout,        "{\"event\":\"bench_end\",\"sample_ns\":[1],\"alloc_bytes\":16384}\n",    );    const result = try collect(        allocator,        profiling.catalog.find("gpalloc.allocator").?,        paths,    );    try std.testing.expectEqual(        @as(?u64, 8_192),        result.max_benchmark_allocated_bytes,    );}test "artifact ingestion rejects mutation before activation without touching output" {    comptime {        @stardustClaim(            @import("alloc_phase").capacity.witness(@import("./root.zig").ArtifactIngestion, "profiling_ingestion_mutation"),            null,            null,            null,            null,            null,            null,        );    }    const allocator = std.testing.allocator;    var fixture = try testFixture(allocator);    defer cleanupFixture(&fixture, allocator);    const paths = fixture.paths.paths;    try sys.fs.writeFile(paths.stdout, "{}\n");    try sys.fs.writeFile(paths.structured, "preserve");    const limits = try ingest.Limits.inspect(paths);    var ingestion = try ingest.ArtifactIngestion.init(allocator, limits);    defer ingestion.deinit(allocator);    try sys.fs.writeFile(paths.stdout, "{\"changed\":true}\n");    try std.testing.expectError(error.InputChanged, ingestion.activate());    const structured = try sys.fs.readFileAlloc(allocator, paths.structured, 64);    defer allocator.free(structured);    try std.testing.expectEqualStrings("preserve", structured);}test "artifact ingestion rejects max plus one during steady rescan without replacing output" {    comptime {        @stardustClaim(            @import("alloc_phase").capacity.witness(@import("./root.zig").ArtifactIngestion, "profiling_ingestion_max_plus_one"),            null,            null,            null,            null,            null,            null,        );    }    const allocator = std.testing.allocator;    var fixture = try testFixture(allocator);    defer cleanupFixture(&fixture, allocator);    const paths = fixture.paths.paths;    try sys.fs.writeFile(paths.stdout, "{}\n");    try sys.fs.writeFile(paths.structured, "preserve");    const limits = try ingest.Limits.inspect(paths);    var ingestion = try ingest.ArtifactIngestion.init(allocator, limits);    defer ingestion.deinit(allocator);    try ingestion.activate();    try sys.fs.writeFile(paths.stdout, "{}\r\n");    try std.testing.expectError(        error.InputChanged,        ingestion.write(profiling.catalog.find("gpalloc.allocator").?),    );    const structured = try sys.fs.readFileAlloc(allocator, paths.structured, 64);    defer allocator.free(structured);    try std.testing.expectEqualStrings("preserve", structured);}test "artifact ingestion acquires exact storage before a sealed steady write" {    comptime {        @stardustClaim(            @import("alloc_phase").capacity.witness(@import("./root.zig").ArtifactIngestion, "profiling_ingestion_sealed_transitive_risk"),            null,            null,            null,            null,            null,            null,        );    }    comptime {        @stardustClaim(            @import("alloc_phase").capacity.witness(@import("./root.zig").ArtifactIngestion, "profiling_ingestion_sealed_foreign_risk"),            null,            null,            null,            null,            null,            null,        );    }    const allocator = std.testing.allocator;    var fixture = try testFixture(allocator);    defer cleanupFixture(&fixture, allocator);    const paths = fixture.paths.paths;    try sys.fs.writeFile(paths.stdout, "{}\n");    const limits = try ingest.Limits.inspect(paths);    const capacity = try ingest.Capacity.derive(limits);    var phase_allocator = try alloc_phase.SealedPhaseAllocator.init(allocator);    var ingestion = try ingest.ArtifactIngestion.init(        phase_allocator.initializationAllocator(),        limits,    );    try std.testing.expectEqual(capacity.working_bytes, ingestion.capacity.working_bytes);    const line_pointer = ingestion.line_storage.ptr;    const row_pointer = ingestion.row_bits.ptr;    const scratch_pointer = ingestion.scratch_storage.ptr;    phase_allocator.seal();    try ingestion.activate();    const result = try ingestion.write(profiling.catalog.find("gpalloc.allocator").?);    try std.testing.expectEqual(@as(usize, 1), result.rows);    try std.testing.expectEqual(line_pointer, ingestion.line_storage.ptr);    try std.testing.expectEqual(row_pointer, ingestion.row_bits.ptr);    try std.testing.expectEqual(scratch_pointer, ingestion.scratch_storage.ptr);    try std.testing.expectEqual(capacity.line_bytes, ingestion.line_storage.len);    try std.testing.expectEqual(capacity.row_bit_bytes, ingestion.row_bits.len);    try std.testing.expectEqual(capacity.scratch_bytes, ingestion.scratch_storage.len);    try std.testing.expectEqual(        alloc_phase.PhaseViolations{},        phase_allocator.violations(),    );    phase_allocator.beginTeardown();    ingestion.deinit(phase_allocator.teardownAllocator());    try std.testing.expectEqual(alloc_phase.capacity.Phase.teardown, ingestion.phase);    try std.testing.expectEqual(        alloc_phase.PhaseViolations{},        phase_allocator.violations(),    );    phase_allocator.deinit();}test "artifact ingestion reports cold zero capacity and survives every initialization OOM" {    comptime {        @stardustClaim(            @import("alloc_phase").capacity.witness(@import("./root.zig").ArtifactIngestion, "profiling_ingestion_oom_retry"),            null,            null,            null,            null,            null,            null,        );    }    const allocator = std.testing.allocator;    var fixture = try testFixture(allocator);    defer cleanupFixture(&fixture, allocator);    const paths = fixture.paths.paths;    const cold_limits = try ingest.Limits.inspect(paths);    const cold_capacity = try ingest.Capacity.derive(cold_limits);    try std.testing.expectEqual(@as(usize, 0), cold_capacity.working_bytes);    const cold = try collect(        allocator,        profiling.catalog.find("gpalloc.allocator").?,        paths,    );    try std.testing.expectEqual(ingest.Summary{ .rows = 0, .parse_errors = 0, .sources = 0 }, cold);    try sys.fs.writeFile(paths.stdout, "{\"payload\":\"0123456789abcdef\"}\n");    try sys.fs.writeFile(paths.structured, "preserve");    const limits = try ingest.Limits.inspect(paths);    try std.testing.checkAllAllocationFailures(        allocator,        initializeOwner,        .{limits},    );    var retry = try ingest.ArtifactIngestion.init(allocator, limits);    defer retry.deinit(allocator);    try retry.activate();    try std.testing.expectEqual(        (try ingest.Capacity.derive(limits)).working_bytes,        retry.capacity.working_bytes,    );    const structured = try sys.fs.readFileAlloc(allocator, paths.structured, 64);    defer allocator.free(structured);    try std.testing.expectEqualStrings("preserve", structured);}

Source: src/profiling/ingest/root.zig:13

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

Audit

Definitions2
Public names3
Members0
Version26.7.0
Revisiondaab053ee433