tiny.profiling.analyze.load
Defined in analyze.
API (8)
Actions
Public operations.
directBenchmarkReductionDomainexpectExcludedReductionTestRunfinalizeExecutionSummaryloadCounterSummaryloadRunparseCapturesparseWorkloadrelocateWorkload
Source
Source: src/profiling/analyze/load.zig
zig
const std = @import("std");const capture = @import("capture");const sys = @import("sys");const baseline = @import("../root.zig").baseline;const allocation_trace = @import("../capture/root.zig").memtrace;const catalog = @import("../root.zig").catalog;const coz = @import("../capture/root.zig").coz;const environment = @import("../root.zig").environment;const host = @import("../root.zig").host;const json = @import("../root.zig").json;const measurement = @import("../root.zig").measurement;const memory = @import("../root.zig").memory;const metric = @import("../root.zig").metric;const order = @import("../root.zig").order;const plan = @import("../root.zig").plan;const perturbation = @import("../root.zig").perturbation;const record = @import("../root.zig").record;const reducer = @import("../root.zig").reduction;const trace_capture = @import("../capture/root.zig").tracy;const ReductionDomainTestCase = @import("fixture/root.zig").ReductionDomainTestCase;const Run = @import("root.zig").model.Run;const Workload = @import("root.zig").model.Workload;const interleavedTestSamples = @import("fixture/root.zig").interleavedTestSamples;const measuredTestWorkload = @import("fixture/root.zig").measuredTestWorkload;const relocated_coz_analysis_json = @import("fixture/root.zig").relocated_coz_analysis_json;const relocated_run_start_json = @import("fixture/root.zig").relocated_run_start_json;const relocated_workload_json = @import("fixture/root.zig").relocated_workload_json;const repeated_measurement_workload_json = @import("fixture/root.zig").repeated_measurement_workload_json;const writeReductionTestRun = @import("fixture/root.zig").writeReductionTestRun;const max_results_bytes = 128 * 1024 * 1024;pub fn loadRun(allocator: std.mem.Allocator, input: []const u8) !Run { const run_ref = try baseline.resolveRun(allocator, input); const text = try sys.fs.readFileAlloc(allocator, run_ref.results_path, max_results_bytes); var workloads: std.ArrayList(Workload) = .empty; var suite: catalog.Suite = if (run_ref.suite) |suite_text| catalog.Suite.parse(suite_text) orelse .all else .all; var filters: []const []const u8 = &.{}; var selection_known = false; var selected_workload_count: usize = 0; var git = GitIdentity{ .sha = null, .dirty = null }; var optimize: ?[]const u8 = null; var run_host = environment.Host{}; var recorded_root: ?[]const u8 = null; var lines = std.mem.splitScalar(u8, text, '\n'); while (lines.next()) |line| { if (std.mem.trim(u8, line, " \t\r").len == 0) continue; const value = try std.json.parseFromSliceLeaky(std.json.Value, allocator, line, .{}); const object = try json.object(value); const event = json.string(object.get("event")) orelse continue; if (std.mem.eql(u8, event, "run_start")) { if (object.get("selection")) |selection_value| { const selection = try json.object(selection_value); if (json.string(selection.get("suite"))) |suite_text| suite = catalog.Suite.parse(suite_text) orelse suite; filters = try json.strings(allocator, selection.get("filters")); selected_workload_count = std.math.cast( usize, json.asU64(selection.get("workload_count")) orelse 0, ) orelse return error.InvalidProfilingJson; if (selected_workload_count > plan.max_workloads_per_run) { return error.InvalidProfilingJson; } selection_known = true; } if (object.get("artifacts")) |artifacts_value| { const artifacts = try json.object(artifacts_value); recorded_root = json.string(artifacts.get("root")); } git = parseGit(object); optimize = parseOptimize(object); run_host = environment.parse(object.get("environment")); } else if (std.mem.eql(u8, event, "workload")) { if (workloads.items.len >= plan.max_workloads_per_run) { return error.InvalidProfilingJson; } const workload = try loadWorkload( allocator, object, workloads.items, selected_workload_count, recorded_root, run_ref.root, ); try workloads.append(allocator, workload); } } try normalizeRunOrder(allocator, workloads.items, selected_workload_count); return .{ .ref = run_ref, .suite = suite, .filters = filters, .selection_known = selection_known, .git_sha = git.sha, .git_dirty = git.dirty, .optimize = optimize, .host = run_host, .workloads = try workloads.toOwnedSlice(allocator), };}fn loadWorkload( allocator: std.mem.Allocator, object: std.json.ObjectMap, preceding_workloads: []const Workload, selected_workload_count: usize, recorded_root: ?[]const u8, actual_root: []const u8,) !Workload { var workload = try parseWorkload( allocator, object, preceding_workloads, selected_workload_count, ); try relocateWorkload(allocator, &workload, recorded_root, actual_root); workload.perf_stat = try loadCounterSummary(allocator, workload); try finalizeExecutionSummary(&workload); try verifyBenchmarkReduction(allocator, workload); const artifacts = workload.analysisArtifacts(); const structured_path = if (artifacts) |actual| actual.structured else null; workload.metrics = switch (workload.benchmark_process_reduction) { .not_applicable => try metric.load(allocator, structured_path), .complete => |complete| try reductionMetrics( allocator, workload.name, complete, ), }; workload.memory_metrics = try memory.load(allocator, .{ .structured_path = structured_path, .allocation_repetitions_path = workload.allocation_repetitions_path, .expected_executions = workload.execution_count, .workload = workload.name, }); const coz_analysis_path = if (artifacts) |actual| actual.coz_analysis else null; workload.causal = try coz.load(allocator, workload.name, coz_analysis_path); return workload;}fn verifyBenchmarkReduction( allocator: std.mem.Allocator, workload: Workload,) !void { if (workload.executions.len > reducer.max_processes) { return error.InvalidProfilingJson; } var inputs: [reducer.max_processes]reducer.Execution = undefined; for (workload.executions, inputs[0..workload.executions.len]) |execution, *input| { const artifacts = execution.artifacts; input.* = .{ .index = execution.index, .acquisition_position = execution.acquisition_position, .exit_code = execution.exit_code, .bench_jsonl = if (artifacts) |actual| actual.bench_jsonl else "", .structured = if (artifacts) |actual| actual.structured else "", }; } try reducer.verify( allocator, workload.benchmark_process_reduction, inputs[0..workload.executions.len], directBenchmarkReductionDomain(workload), );}pub fn directBenchmarkReductionDomain(workload: Workload) bool { return reducer.directBenchmarkDomain(workload.benchmark_process_domain);}fn reductionMetrics( allocator: std.mem.Allocator, workload_name: []const u8, complete: reducer.Complete,) ![]const metric.Metric { const result = try allocator.alloc(metric.Metric, complete.benchmarks.len); for (complete.benchmarks, result) |benchmark_value, *row| { row.* = .{ .workload = workload_name, .key = benchmark_value.key, .label = try std.fmt.allocPrint( allocator, "{s} {s}", .{ benchmark_value.suite, benchmark_value.id }, ), .source_kind = "benchmark_process_reduction", .source_path = complete.sources[0].bench_jsonl.path, .source_line = 0, .sample_count = @intCast(benchmark_value.sample_ns.len), .mean_ns = benchmark_value.statistics.mean_ns, .median_ns = @floatFromInt(benchmark_value.statistics.median_ns), .p75_ns = @floatFromInt(benchmark_value.statistics.p75_ns), .p95_ns = @floatFromInt(benchmark_value.statistics.p95_ns), .p99_ns = @floatFromInt(benchmark_value.statistics.p99_ns), .min_ns = @floatFromInt(benchmark_value.statistics.min_ns), .max_ns = @floatFromInt(benchmark_value.statistics.max_ns), .mean_interval = null, .median_interval = .{ .low_ns = benchmark_value.statistics.median_interval.low_ns, .high_ns = benchmark_value.statistics.median_interval.high_ns, }, .p95_interval = null, .p99_interval = null, .samples_ns = benchmark_value.sample_ns, .sample_sequence = .{ .order = .measured_acquisition_order, .index_origin = 0, }, .distribution = .confidence_interval, }; } return result;}fn normalizeRunOrder( allocator: std.mem.Allocator, workloads: []Workload, selected_workload_count: usize,) !void { if (selected_workload_count != 0 and workloads.len > selected_workload_count) { return error.InvalidProfilingJson; } const acquired_workload_count = @max(selected_workload_count, workloads.len); for (workloads) |*workload| switch (workload.acquisition) { .blocked => |*blocked| blocked.workload_count = @max( blocked.workload_count, acquired_workload_count, ), .random_interleaved => {}, }; try validateOrderRun(allocator, workloads, selected_workload_count);}const GitIdentity = struct { sha: ?[]const u8, dirty: ?bool,};fn parseGit(object: std.json.ObjectMap) GitIdentity { const environment_object = json.object(object.get("environment") orelse return .{ .sha = null, .dirty = null, }) catch return .{ .sha = null, .dirty = null }; const git = json.object(environment_object.get("git") orelse return .{ .sha = null, .dirty = null, }) catch return .{ .sha = null, .dirty = null }; return .{ .sha = json.string(git.get("commit")), .dirty = json.asBool(git.get("dirty")), };}fn parseOptimize(object: std.json.ObjectMap) ?[]const u8 { const environment_object = json.object(object.get("environment") orelse return null) catch return null; const build = json.object(environment_object.get("build") orelse return null) catch return null; return json.string(build.get("optimize"));}pub fn parseWorkload( allocator: std.mem.Allocator, object: std.json.ObjectMap, preceding_workloads: []const Workload, selected_workload_count: usize,) !Workload { const schema_name = json.string(object.get("schema")) orelse return error.UnsupportedProfilingWorkloadSchema; if (!std.mem.eql(u8, schema_name, record.workload_schema)) { return error.UnsupportedProfilingWorkloadSchema; } const workload = try json.object(object.get("workload") orelse return error.InvalidProfilingJson); const status = try json.object(object.get("status") orelse return error.InvalidProfilingJson); const timing = try json.object(object.get("timing") orelse return error.InvalidProfilingJson); const resources = if (object.get("resources")) |value| try json.object(value) else null; const artifacts = try json.object( object.get("artifacts") orelse return error.InvalidProfilingJson, ); const artifact_root = try requiredArtifactPath(artifacts, "root"); const warmup = if (object.get("warmup")) |value| try json.object(value) else null; const warmup_artifacts = if (warmup) |actual| if (actual.get("artifacts")) |value| json.object(value) catch null else null else null; const total_wall_ns = json.asU64(timing.get("wall_ns")) orelse 0; const name = json.string(workload.get("name")) orelse return error.InvalidProfilingJson; const capture_perturbation = try perturbation.parseMeasurement(allocator, object); const executions = try measurement.parseExecutions( allocator, object, artifact_root, ); const measurement_object = try json.object(object.get("measurement").?); const output_retention = try measurement.outputRetention(measurement_object); var result = Workload{ .name = name, .package = json.string(workload.get("package")) orelse "", .step = json.string(workload.get("step")) orelse "", .surface = std.meta.stringToEnum( catalog.Surface, json.string(workload.get("surface")) orelse return error.InvalidProfilingJson, ) orelse return error.InvalidProfilingJson, .acquisition = try parseAcquisition( allocator, object, name, preceding_workloads, selected_workload_count, ), .status = json.string(status.get("state")) orelse "unknown", .exit_code = json.asI64(status.get("exit_code")) orelse -1, .wall_ns = total_wall_ns, .total_wall_ns = total_wall_ns, .executions = executions, .measurement_recorded = object.get("measurement") != null, .warmups = try measurement.parseWarmups(allocator, object), .warmup_stdout_path = if (warmup_artifacts) |actual| json.string(actual.get("stdout")) else null, .warmup_stderr_path = if (warmup_artifacts) |actual| json.string(actual.get("stderr")) else null, .resource_usage_source = try parseResourceUsageSource(resources), .max_rss_kib = if (resources) |actual| json.asI64(actual.get("max_rss_kib")) else null, .user_s = if (resources) |actual| json.asF64(actual.get("user_s")) else null, .system_s = if (resources) |actual| json.asF64(actual.get("system_s")) else null, .minor_page_faults = resourceValue(resources, "minor_page_faults"), .major_page_faults = resourceValue(resources, "major_page_faults"), .voluntary_context_switches = resourceValue(resources, "voluntary_context_switches"), .involuntary_context_switches = resourceValue(resources, "involuntary_context_switches"), .result_path = json.string(artifacts.get("result")), .allocation_repetitions_path = json.string( artifacts.get("allocation_repetitions"), ), .profiler_artifacts = try parseProfilerArtifacts( artifacts, output_retention, artifact_root, ), .benchmark_process_reduction = try reducer.parse( allocator, measurement_object.get("benchmark_process_reduction") orelse return error.InvalidProfilingJson, ), .benchmark_process_domain = try reducer.parseDomain( measurement_object.get("benchmark_process_domain") orelse return error.InvalidProfilingJson, ), .captures = try parseCaptures(allocator, object), .capture_perturbation = capture_perturbation, .capture_perturbation_summary = if (capture_perturbation) |actual| try perturbation.summarize(allocator, actual, name) else null, }; try retainWorkloadIdentity(allocator, object, &result); try validateBenchmarkReductionDomain(result); try validateMeasurementOrder(object, result.acquisition.method()); try validateWorkloadOrder(result); return result;}fn parseProfilerArtifacts( artifacts: std.json.ObjectMap, retention: measurement.OutputRetention, workload_root: []const u8,) !?measurement.ExecutionArtifacts { if (retention != .profiler_capture_contract) { if (hasProfilerArtifactFields(artifacts)) { return error.InvalidProfilingJson; } return null; } const result = measurement.ExecutionArtifacts{ .root = workload_root, .stdout = try requiredArtifactPath(artifacts, "stdout"), .stderr = try requiredArtifactPath(artifacts, "stderr"), .bench_jsonl = try requiredArtifactPath(artifacts, "bench_jsonl"), .coz_jsonl = try requiredArtifactPath(artifacts, "coz_jsonl"), .coz_analysis = try requiredArtifactPath(artifacts, "coz_analysis"), .tracy_jsonl = try requiredArtifactPath(artifacts, "tracy_jsonl"), .tracy_summary = try requiredArtifactPath(artifacts, "tracy_summary"), .allocations = try requiredArtifactPath(artifacts, "allocations"), .structured = try requiredArtifactPath(artifacts, "structured"), .structured_rows = try artifactCount(artifacts, "structured_rows"), .structured_parse_errors = try artifactCount( artifacts, "structured_parse_errors", ), }; try measurement.validateProfilerArtifacts(result, workload_root); return result;}fn hasProfilerArtifactFields(artifacts: std.json.ObjectMap) bool { inline for (.{ "stdout", "stderr", "bench_jsonl", "coz_jsonl", "coz_analysis", "tracy_jsonl", "tracy_summary", "allocations", "structured", "structured_rows", "structured_parse_errors", }) |field| { if (artifacts.get(field) != null) return true; } return false;}fn requiredArtifactPath( object: std.json.ObjectMap, field: []const u8,) ![]const u8 { const path = json.string(object.get(field)) orelse return error.InvalidProfilingJson; if (path.len == 0) return error.InvalidProfilingJson; return path;}fn artifactCount(object: std.json.ObjectMap, field: []const u8) !usize { return std.math.cast( usize, json.asU64(object.get(field)) orelse return error.InvalidProfilingJson, ) orelse error.InvalidProfilingJson;}fn parseResourceUsageSource( resources: ?std.json.ObjectMap,) !?sys.process.ResourceUsageSource { const object = resources orelse return null; const text = json.string(object.get("resource_usage_source")) orelse return null; return std.meta.stringToEnum(sys.process.ResourceUsageSource, text) orelse error.InvalidProfilingJson;}fn resourceValue(resources: ?std.json.ObjectMap, field: []const u8) ?f64 { const object = resources orelse return null; return json.asF64(object.get(field));}fn retainWorkloadIdentity( allocator: std.mem.Allocator, object: std.json.ObjectMap, result: *Workload,) !void { const command = if (object.get("command")) |value| try json.object(value) else null; result.command_argv = if (command) |actual| try json.strings(allocator, actual.get("argv")) else &.{}; result.command_cwd = if (command) |actual| json.string(actual.get("cwd")) else null; result.command_identity_recorded = if (command) |actual| actual.get("cwd") != null and actual.get("argv") != null else false; result.scope = json.string(object.get("scope")) orelse return error.InvalidProfilingJson; result.scope_recorded = true; result.causal_enabled = json.asBool(object.get("causal")) orelse return error.InvalidProfilingJson; result.tracy_enabled = json.asBool(object.get("tracy")) orelse return error.InvalidProfilingJson; result.allocations_enabled = json.asBool(object.get("trace_allocations")) orelse return error.InvalidProfilingJson; result.profiler_configuration_recorded = true; result.warmup_recorded = object.get("warmup") != null;}fn validateBenchmarkReductionDomain(workload: Workload) !void { const declaration = workload.benchmark_process_domain; if (declaration.benchmark_surface != (workload.surface == .benchmark) or declaration.direct_execution != std.mem.eql(u8, workload.scope, host.direct_scope) or declaration.tracy != workload.tracy_enabled or declaration.causal != workload.causal_enabled or declaration.allocation_trace != workload.allocations_enabled) { return error.InvalidProfilingJson; } if (workload.profiler_artifacts != null and !declaration.host_profiler) { return error.InvalidProfilingJson; } if (workload.capture_perturbation != null and !declaration.capture_control) { return error.InvalidProfilingJson; } if (reducer.directBenchmarkDomain(declaration) and workload.captures.len != 0) { return error.InvalidProfilingJson; } for (workload.captures) |capture_value| { if (!captureMatchesDomain(capture_value.kind, declaration)) { return error.InvalidProfilingJson; } }}fn captureMatchesDomain( kind: []const u8, declaration: reducer.DomainDeclaration,) bool { inline for (.{ host.counters.kind, host.sampling.kind, host.dhat.kind, host.offcpu.kind, host.coverage.kind, }) |host_kind| { if (std.mem.eql(u8, kind, host_kind)) return declaration.host_profiler; } if (std.mem.eql(u8, kind, trace_capture.kind)) return declaration.tracy; if (std.mem.eql(u8, kind, coz.capture_kind)) return declaration.causal; if (std.mem.eql(u8, kind, allocation_trace.kind)) { return declaration.allocation_trace; } return true;}fn validateMeasurementOrder( object: std.json.ObjectMap, method: order.Method,) !void { const measurement_value = object.get("measurement") orelse { if (method == .random_interleaved) return error.InvalidProfilingJson; return; }; const measurement_object = try json.object(measurement_value); const recorded = json.string(measurement_object.get("acquisition_order")) orelse { if (method == .random_interleaved) return error.InvalidProfilingJson; return; }; if (std.mem.eql(u8, recorded, method.acquisitionName())) return; return error.InvalidProfilingJson;}fn parseAcquisition( allocator: std.mem.Allocator, object: std.json.ObjectMap, workload_name: []const u8, preceding_workloads: []const Workload, selected_workload_count: usize,) !order.Context { const position = preceding_workloads.len + 1; if (object.get("index")) |index_value| { const recorded_index = json.asU64(index_value) orelse return error.InvalidProfilingJson; if (recorded_index != preceding_workloads.len) return error.InvalidProfilingJson; } const predecessors = try allocator.alloc([]const u8, preceding_workloads.len); for (preceding_workloads, 0..) |workload, index| predecessors[index] = workload.name; const acquisition_value = object.get("acquisition") orelse return .{ .blocked = .{ .position = position, .workload_count = @max(selected_workload_count, position), .predecessors = predecessors, }, }; const recorded = try order.parse(allocator, acquisition_value); switch (recorded) { .blocked => |blocked| { if (blocked.position != position or (selected_workload_count != 0 and blocked.workload_count != selected_workload_count) or blocked.predecessors.len != predecessors.len) { return error.InvalidProfilingJson; } for (blocked.predecessors, predecessors) |actual, expected| { if (!std.mem.eql(u8, actual, expected)) { return error.InvalidProfilingJson; } } }, .random_interleaved => |interleaved| { if ((selected_workload_count != 0 and interleaved.workload_count != selected_workload_count) or preceding_workloads.len >= interleaved.selected_workloads.len or !std.mem.eql( u8, interleaved.selected_workloads[preceding_workloads.len], workload_name, )) { return error.InvalidProfilingJson; } }, } return recorded;}fn validateWorkloadOrder(workload: Workload) !void { switch (workload.acquisition) { .blocked => { for (workload.executions) |execution| { if (execution.acquisition_position != null) { return error.InvalidProfilingJson; } } }, .random_interleaved => |interleaved| { if (workload.executions.len > interleaved.repeat_count or (workload.exit_code == 0 and workload.executions.len != interleaved.repeat_count)) { return error.InvalidProfilingJson; } for (workload.executions, 0..) |execution, index| { if (execution.acquisition_position != interleaved.positions[index]) { return error.InvalidProfilingJson; } } }, }}fn validateOrderRun( allocator: std.mem.Allocator, workloads: []const Workload, selected_workload_count: usize,) !void { if (workloads.len == 0) return; const first = switch (workloads[0].acquisition) { .blocked => { for (workloads[1..]) |workload| switch (workload.acquisition) { .blocked => {}, .random_interleaved => return error.InvalidProfilingJson, }; return; }, .random_interleaved => |value| value, }; if (selected_workload_count != 0 and first.workload_count != selected_workload_count) { return error.InvalidProfilingJson; } if (workloads.len > first.workload_count) return error.InvalidProfilingJson; _ = allocator; var positions_seen: [order.max_schedule_entries]bool = @splat(false); const schedule_len = first.workload_count * @as(usize, first.repeat_count); for (workloads, 0..) |workload, index| { const context = switch (workload.acquisition) { .blocked => return error.InvalidProfilingJson, .random_interleaved => |value| value, }; if (context.seed != first.seed or !order.sameDesign( .{ .random_interleaved = first }, .{ .random_interleaved = context }, )) { return error.InvalidProfilingJson; } if (!std.mem.eql(u8, workload.name, first.selected_workloads[index])) { return error.InvalidProfilingJson; } for (context.positions) |position| { if (positions_seen[position - 1]) return error.InvalidProfilingJson; positions_seen[position - 1] = true; } } if (workloads.len == first.workload_count) { for (positions_seen[0..schedule_len]) |seen| { if (!seen) return error.InvalidProfilingJson; } }}pub fn parseCaptures(allocator: std.mem.Allocator, object: std.json.ObjectMap) ![]const host.Capture { const value = object.get("captures") orelse return &.{}; const rows = json.array(value) catch return &.{}; var result: std.ArrayList(host.Capture) = .empty; for (rows.items) |item| { const row = json.object(item) catch continue; try result.append(allocator, .{ .kind = json.string(row.get("kind")) orelse continue, .tool = json.string(row.get("tool")) orelse "", .tool_version = json.string(row.get("tool_version")), .scope = json.string(row.get("scope")) orelse host.scope, .capture_path = json.string(row.get("capture")) orelse "", .summary_path = json.string(row.get("summary")) orelse "", .state = json.string(row.get("state")) orelse "unknown", .caveat_kind = json.string(row.get("caveat_kind")), .caveat_message = json.string(row.get("caveat_message")), }); } return try result.toOwnedSlice(allocator);}pub fn relocateWorkload(allocator: std.mem.Allocator, workload: *Workload, recorded_root: ?[]const u8, actual_root: []const u8) !void { workload.result_path = try relocatePath(allocator, workload.result_path, recorded_root, actual_root); workload.warmup_stdout_path = try relocatePath(allocator, workload.warmup_stdout_path, recorded_root, actual_root); workload.warmup_stderr_path = try relocatePath(allocator, workload.warmup_stderr_path, recorded_root, actual_root); workload.allocation_repetitions_path = try relocatePath( allocator, workload.allocation_repetitions_path, recorded_root, actual_root, ); const executions = try allocator.dupe(measurement.Execution, workload.executions); for (executions) |*execution| { if (execution.artifacts) |artifacts| { execution.artifacts = try relocateExecutionArtifacts( allocator, artifacts, recorded_root, actual_root, ); } } workload.executions = executions; try reducer.relocate( allocator, &workload.benchmark_process_reduction, recorded_root, actual_root, ); if (workload.profiler_artifacts) |artifacts| { workload.profiler_artifacts = try relocateExecutionArtifacts( allocator, artifacts, recorded_root, actual_root, ); } try relocateCapturePerturbation(allocator, workload, recorded_root, actual_root); const rows = try allocator.dupe(host.Capture, workload.captures); for (rows) |*row| { row.capture_path = (try relocatePath(allocator, row.capture_path, recorded_root, actual_root)) orelse row.capture_path; row.summary_path = (try relocatePath(allocator, row.summary_path, recorded_root, actual_root)) orelse row.summary_path; } workload.captures = rows;}fn relocateExecutionArtifacts( allocator: std.mem.Allocator, artifacts: measurement.ExecutionArtifacts, recorded_root: ?[]const u8, actual_root: []const u8,) !measurement.ExecutionArtifacts { var result = artifacts; inline for (.{ "root", "stdout", "stderr", "bench_jsonl", "coz_jsonl", "coz_analysis", "tracy_jsonl", "tracy_summary", "allocations", "structured", }) |field| { @field(result, field) = (try relocatePath( allocator, @field(result, field), recorded_root, actual_root, )).?; } return result;}fn relocateCapturePerturbation( allocator: std.mem.Allocator, workload: *Workload, recorded_root: ?[]const u8, actual_root: []const u8,) !void { var measurement_value = workload.capture_perturbation orelse return; var paths = measurement_value.control_artifacts; paths.stdout = (try relocatePath(allocator, paths.stdout, recorded_root, actual_root)).?; paths.stderr = (try relocatePath(allocator, paths.stderr, recorded_root, actual_root)).?; paths.bench_jsonl = (try relocatePath(allocator, paths.bench_jsonl, recorded_root, actual_root)).?; paths.coz_jsonl = (try relocatePath(allocator, paths.coz_jsonl, recorded_root, actual_root)).?; paths.coz_analysis = (try relocatePath(allocator, paths.coz_analysis, recorded_root, actual_root)).?; paths.tracy_jsonl = (try relocatePath(allocator, paths.tracy_jsonl, recorded_root, actual_root)).?; paths.tracy_summary = (try relocatePath(allocator, paths.tracy_summary, recorded_root, actual_root)).?; paths.allocations = (try relocatePath(allocator, paths.allocations, recorded_root, actual_root)).?; paths.structured = (try relocatePath(allocator, paths.structured, recorded_root, actual_root)).?; measurement_value.control_artifacts = paths; workload.capture_perturbation = measurement_value;}fn relocatePath(allocator: std.mem.Allocator, recorded: ?[]const u8, recorded_root: ?[]const u8, actual_root: []const u8) !?[]const u8 { const path = recorded orelse return null; const from = recorded_root orelse return path; if (std.mem.eql(u8, from, actual_root)) return path; if (!pathHasPrefix(path, from)) return path; return try std.fmt.allocPrint(allocator, "{s}{s}", .{ actual_root, path[from.len..] });}fn pathHasPrefix(path: []const u8, prefix: []const u8) bool { if (prefix.len == 0 or !std.mem.startsWith(u8, path, prefix)) return false; if (path.len == prefix.len) return true; return path[prefix.len] == std.fs.path.sep;}pub fn loadCounterSummary(allocator: std.mem.Allocator, workload: Workload) !?capture.perfstat.Summary { if (workload.perf_stat) |summary| return summary; return measurement.loadPerfStatSummary(allocator, workload.captures);}pub fn finalizeExecutionSummary(workload: *Workload) !void { workload.warmup_count = workload.warmups.len; workload.warmup_total_wall_ns = measurement.totalWallNs(workload.warmups); if (workload.warmups.len != 0) { const warmup_stats = try measurement.summarize( workload.warmup_total_wall_ns, .{}, workload.warmups, null, ); workload.warmup_distribution = warmup_stats.wall_distribution; } if (workload.measurement_recorded and workload.executions.len == 0) { workload.wall_ns = 0; workload.total_wall_ns = 0; workload.execution_count = 0; workload.wall_distribution = null; workload.resource_usage_source = null; workload.user_s = null; workload.system_s = null; workload.minor_page_faults = null; workload.major_page_faults = null; workload.voluntary_context_switches = null; workload.involuntary_context_switches = null; return; } const stats = try measurement.summarize( workload.total_wall_ns, .{ .source = workload.resource_usage_source, .user_s = workload.user_s, .system_s = workload.system_s, .minor_page_faults = workload.minor_page_faults, .major_page_faults = workload.major_page_faults, .voluntary_context_switches = workload.voluntary_context_switches, .involuntary_context_switches = workload.involuntary_context_switches, }, workload.executions, workload.perf_stat, ); workload.wall_ns = stats.wall_ns; workload.total_wall_ns = stats.total_wall_ns; workload.execution_count = stats.execution_count; workload.executions = stats.executions; workload.wall_distribution = stats.wall_distribution; workload.resource_usage_source = stats.resource_usage_source; workload.user_s = stats.user_s; workload.system_s = stats.system_s; workload.minor_page_faults = stats.minor_page_faults; workload.major_page_faults = stats.major_page_faults; workload.voluntary_context_switches = stats.voluntary_context_switches; workload.involuntary_context_switches = stats.involuntary_context_switches;}test "profiling analysis rebases relocated run artifacts onto the resolved root" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); const base = try std.fs.path.join(allocator, &.{ ".zig-cache", "tmp", tmp.sub_path[0..] }); const root = try std.fs.path.join(allocator, &.{ base, "run-a" }); const workload_dir = try std.fs.path.join(allocator, &.{ root, "workloads", "w" }); try sys.fs.createDirPath(workload_dir); const manifest_path = try std.fs.path.join(allocator, &.{ root, "manifest.json" }); try sys.fs.writeFile(manifest_path, \\{"schema":"tiny.profiling.run/v1","event":"manifest","run_id":"run-a","selection":{"suite":"smoke","filters":[]},"artifacts":{"root":"zig-out/profiling/run-a","results":"zig-out/profiling/run-a/results.jsonl","manifest":"zig-out/profiling/run-a/manifest.json"}} \\ ); const results_path = try std.fs.path.join(allocator, &.{ root, "results.jsonl" }); const workload_line = try std.mem.replaceOwned( u8, allocator, relocated_workload_json, "\n", "", ); try sys.fs.writeFile( results_path, try std.fmt.allocPrint( allocator, "{s}\n{s}\n", .{ relocated_run_start_json, workload_line }, ), ); const structured_path = try std.fs.path.join(allocator, &.{ workload_dir, "structured.jsonl" }); try sys.fs.writeFile(structured_path, \\{"schema":"tiny.profiling.structured/v1","workload":{"name":"w","package":"lib/w","step":"w-bench"},"source":{"kind":"bench_jsonl","path":"bench.jsonl","line":1},"row":{"schema":"tiny.profiling.metric/v1","event":"bench_end","family":"timing","metric":"duration_ns","unit":"ns","suite":"bench","name":"case","sample_ns":[10,20,30]}} \\ ); const coz_path = try std.fs.path.join(allocator, &.{ workload_dir, "bench.coz.analysis.json" }); try sys.fs.writeFile(coz_path, relocated_coz_analysis_json); const run_value = try loadRun(allocator, root); try std.testing.expectEqualStrings(root, run_value.ref.root); try std.testing.expectEqualStrings("abcdef", run_value.git_sha.?); try std.testing.expectEqual(false, run_value.git_dirty.?); try std.testing.expectEqualStrings("ReleaseFast", run_value.optimize.?); try std.testing.expectEqualStrings("bench-a", run_value.host.hostname.?); try std.testing.expectEqualStrings("policy-a", run_value.host.cpu_frequency_policy.?); try std.testing.expectEqualStrings("0-15", run_value.host.process_cpu_affinity.?); try std.testing.expectEqualStrings("0", run_value.host.process_memory_affinity.?); try std.testing.expectEqual(@as(usize, 1), run_value.workloads.len); try std.testing.expectEqualStrings("lib/w", run_value.workloads[0].command_cwd.?); try std.testing.expectEqualStrings("w-bench", run_value.workloads[0].command_argv[2]); try std.testing.expect(run_value.workloads[0].command_identity_recorded); try std.testing.expect(run_value.workloads[0].scope_recorded); try std.testing.expect(!directBenchmarkReductionDomain(run_value.workloads[0])); try std.testing.expect(run_value.workloads[0].warmup_recorded); try std.testing.expect(run_value.workloads[0].profiler_configuration_recorded); try std.testing.expect(run_value.workloads[0].allocations_enabled); const artifacts = run_value.workloads[0].analysisArtifacts().?; try std.testing.expectEqualStrings(structured_path, artifacts.structured); const expected_stdout = try std.fs.path.join(allocator, &.{ workload_dir, "stdout.txt" }); try std.testing.expectEqualStrings(expected_stdout, artifacts.stdout); try std.testing.expectEqual(@as(usize, 1), run_value.workloads[0].metrics.len); try std.testing.expectEqual(@as(f64, 20), run_value.workloads[0].metrics[0].median_ns.?); try std.testing.expectEqual(@as(usize, 1), run_value.workloads[0].causal.len); try std.testing.expectEqual(@as(f64, 0.25), run_value.workloads[0].causal[0].max_program_speedup); try std.testing.expectEqual(@as(usize, 1), run_value.causalCount());}pub fn expectExcludedReductionTestRun( allocator: std.mem.Allocator, output_root: []const u8, case: ReductionDomainTestCase,) !void { const fixture = try writeReductionTestRun( allocator, output_root, case.run_id, case.declaration, ); const run_value = try loadRun(allocator, fixture.results); const workload = run_value.workloads[0]; try std.testing.expect(!directBenchmarkReductionDomain(workload)); try std.testing.expect(std.meta.eql( case.declaration, workload.benchmark_process_domain, )); try std.testing.expectEqual(@as(usize, 2), workload.executions.len); try std.testing.expect(workload.executions[0].artifacts != null); try std.testing.expect(workload.profiler_artifacts == null); try std.testing.expect(workload.capture_perturbation == null); try std.testing.expectEqual( @as(usize, if (case.declaration.host_profiler) 1 else 0), workload.captures.len, ); try std.testing.expectEqual( reducer.NotApplicableReason.outside_direct_benchmark_domain, workload.benchmark_process_reduction.not_applicable.reason, ); if (!case.declaration.host_profiler) return; const recorded = try sys.fs.readFileAlloc( allocator, fixture.results, max_results_bytes, ); const direct = try std.mem.replaceOwned( u8, allocator, recorded, "\"host_profiler\":true", "\"host_profiler\":false", ); const unknown = try std.mem.replaceOwned( u8, allocator, direct, "\"kind\":\"dhat\"", "\"kind\":\"future_capture\"", ); try sys.fs.writeFile(fixture.results, unknown); try std.testing.expectError( error.InvalidProfilingJson, loadRun(allocator, fixture.results), );}test "profiling analysis loads verified process reduction and rejects tampering" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); const output_root = try tmp.parent_dir.realPathFileAlloc( std.testing.io, tmp.sub_path[0..], allocator, ); const declaration = reducer.DomainDeclaration{ .benchmark_surface = true, .direct_execution = true, .host_profiler = false, .tracy = false, .causal = false, .allocation_trace = false, .capture_control = false, }; const fixture = try writeReductionTestRun( allocator, output_root, "direct", declaration, ); const run_value = try loadRun(allocator, fixture.results); try std.testing.expectEqual(@as(usize, 1), run_value.workloads.len); const workload = run_value.workloads[0]; try std.testing.expect(directBenchmarkReductionDomain(workload)); try std.testing.expectEqualStrings( "multiple_execution_receipts_reduced", workload.structuredAnalysisState(), ); try std.testing.expectEqual(@as(usize, 1), workload.metrics.len); try std.testing.expectEqualSlices( u64, &.{ 10, 10 }, workload.metrics[0].samples_ns, ); try std.testing.expectEqual( metric.Distribution.confidence_interval, workload.metrics[0].distribution, ); try sys.fs.appendFile(fixture.first_bench, &.{" "}); try std.testing.expectError( error.ArtifactDigestMismatch, loadRun(allocator, fixture.results), );}test "profiling analysis accepts a partial numbered execution receipt" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); var value = try std.json.parseFromSliceLeaky( std.json.Value, allocator, repeated_measurement_workload_json, .{}, ); const status = value.object.getPtr("status").?; status.object.getPtr("state").?.* = .{ .string = "failed" }; status.object.getPtr("exit_code").?.* = .{ .integer = 23 }; const group = value.object.getPtr("measurement").?; group.object.getPtr("execution_count").?.* = .{ .integer = 1 }; const executions = group.object.getPtr("executions").?; executions.array.items.len = 1; executions.array.items[0].object.getPtr("exit_code").?.* = .{ .integer = 23 }; const workload = try parseWorkload( allocator, try json.object(value), &.{}, 1, ); try std.testing.expectEqual(@as(usize, 1), workload.executions.len); try std.testing.expectEqual(@as(i64, 23), workload.executions[0].exit_code); try std.testing.expectEqualStrings( "old/workloads/w/executions/001", workload.executions[0].artifacts.?.root, ); try std.testing.expectEqualStrings( "single_execution_receipt", workload.structuredAnalysisState(), );}test "profiling analysis rejects unsupported workload schema" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); inline for (.{ \\{"schema":"tiny.profiling.workload/v2","event":"workload"} , \\{"schema":"tiny.profiling.workload/v3","event":"workload"} , \\{"event":"workload"} , }) |text| { const value = try std.json.parseFromSliceLeaky( std.json.Value, allocator, text, .{}, ); try std.testing.expectError( error.UnsupportedProfilingWorkloadSchema, parseWorkload(allocator, try json.object(value), &.{}, 1), ); }}test "profiling analysis rejects malformed v4 measurement and artifact shapes" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); const missing_measurement = try std.json.parseFromSliceLeaky( std.json.Value, allocator, \\{"schema":"tiny.profiling.workload/v4","event":"workload", \\ "workload":{"name":"w"},"status":{},"timing":{}, \\ "artifacts":{"root":"workloads/w"}} , .{}, ); try std.testing.expectError( error.InvalidProfilingJson, parseWorkload(allocator, try json.object(missing_measurement), &.{}, 1), ); const aliased_text = try std.mem.replaceOwned( u8, allocator, repeated_measurement_workload_json, "\"artifacts\":{\"root\":\"old/workloads/w\"}", "\"artifacts\":{\"root\":\"old/workloads/w\"," ++ "\"structured\":\"old/workloads/w/structured.jsonl\"}", ); const aliased = try std.json.parseFromSliceLeaky( std.json.Value, allocator, aliased_text, .{}, ); try std.testing.expectError( error.InvalidProfilingJson, parseWorkload(allocator, try json.object(aliased), &.{}, 1), );}test "profiling analysis validates recorded acquisition context" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); const previous = Workload{ .name = "a", .package = "p", .step = "bench", .status = "passed", .exit_code = 0, .wall_ns = 1, .max_rss_kib = null, .user_s = null, .system_s = null, .result_path = null, }; const valid_value = try std.json.parseFromSliceLeaky( std.json.Value, allocator, \\{"schema":"tiny.profiling.workload/v4","event":"workload","index":1, \\ "acquisition":{"position":2,"workload_count":3,"predecessors":["a"]}, \\ "workload":{"name":"target","package":"p","step":"bench", \\ "surface":"benchmark"}, \\ "scope":"workload-binary","causal":false,"tracy":false, \\ "trace_allocations":false, \\ "status":{"state":"passed","exit_code":0},"timing":{"wall_ns":10}, \\ "measurement":{"execution_count":0,"acquisition_order":"fixed_plan_order", \\ "workload_output_retention":"no_measured_execution", \\ "measured_artifact_layout":"none", \\ "allocation_summary_retention":"disabled", \\ "benchmark_process_domain":{"benchmark_surface":true, \\ "direct_execution":true,"host_profiler":false,"tracy":false, \\ "causal":false,"allocation_trace":false,"capture_control":false}, \\ "benchmark_process_reduction":{ \\ "schema":"tiny.profiling.benchmark-process-reduction/v1", \\ "state":"not_applicable","process_count":0, \\ "reason":"fewer_than_two_executions"},"executions":[]}, \\ "artifacts":{"root":"workloads/target"}} , .{}, ); const workload = try parseWorkload( allocator, try json.object(valid_value), &.{previous}, 3, ); try std.testing.expectEqual(@as(usize, 2), workload.acquisition.blocked.position); try std.testing.expectEqual(@as(usize, 3), workload.acquisition.blocked.workload_count); try std.testing.expectEqualStrings("a", workload.acquisition.blocked.predecessors[0]); const invalid_value = try std.json.parseFromSliceLeaky( std.json.Value, allocator, \\{"schema":"tiny.profiling.workload/v4","event":"workload","index":1, \\ "acquisition":{"position":2,"workload_count":3,"predecessors":["b"]}, \\ "workload":{"name":"target","package":"p","step":"bench", \\ "surface":"benchmark"}, \\ "scope":"workload-binary","causal":false,"tracy":false, \\ "trace_allocations":false, \\ "status":{"state":"passed","exit_code":0},"timing":{"wall_ns":10}, \\ "measurement":{"execution_count":0,"acquisition_order":"fixed_plan_order", \\ "workload_output_retention":"no_measured_execution", \\ "measured_artifact_layout":"none", \\ "allocation_summary_retention":"disabled", \\ "benchmark_process_domain":{"benchmark_surface":true, \\ "direct_execution":true,"host_profiler":false,"tracy":false, \\ "causal":false,"allocation_trace":false,"capture_control":false}, \\ "benchmark_process_reduction":{ \\ "schema":"tiny.profiling.benchmark-process-reduction/v1", \\ "state":"not_applicable","process_count":0, \\ "reason":"fewer_than_two_executions"},"executions":[]}, \\ "artifacts":{"root":"workloads/target"}} , .{}, ); try std.testing.expectError( error.InvalidProfilingJson, parseWorkload(allocator, try json.object(invalid_value), &.{previous}, 3), );}test "profiling analysis validates deterministic interleaved schedules" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); const entries = try order.schedule(allocator, 2, 3, 42); const names = [_][]const u8{ "a", "b" }; const first_acquisition = try order.interleavedContext( allocator, &names, entries, 0, 3, 42, ); const second_acquisition = try order.interleavedContext( allocator, &names, entries, 1, 3, 42, ); const first_positions = first_acquisition.random_interleaved.positions; const second_positions = second_acquisition.random_interleaved.positions; const first_samples = interleavedTestSamples(first_positions); const second_samples = interleavedTestSamples(second_positions); var first = try measuredTestWorkload("a", &first_samples); first.acquisition = first_acquisition; var second = try measuredTestWorkload("b", &second_samples); second.acquisition = second_acquisition; try validateWorkloadOrder(first); try validateWorkloadOrder(second); try validateOrderRun(allocator, &.{ first, second }, 2); var tampered_samples = first_samples; tampered_samples[1].acquisition_position = first_positions[1] + 1; var tampered_receipt = try measuredTestWorkload("a", &tampered_samples); tampered_receipt.acquisition = first_acquisition; try std.testing.expectError( error.InvalidProfilingJson, validateWorkloadOrder(tampered_receipt), ); const tampered_first = first; var tampered_second = second; tampered_second.acquisition.random_interleaved.positions = tampered_first.acquisition.random_interleaved.positions; try std.testing.expectError( error.InvalidProfilingJson, validateOrderRun(allocator, &.{ tampered_first, tampered_second }, 2), );}test "profiling analysis rejects measurement order token mismatch" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); const value = try std.json.parseFromSliceLeaky( std.json.Value, allocator, \\{"measurement":{"acquisition_order":"fixed_plan_order"}} , .{}, ); const object = try json.object(value); try validateMeasurementOrder(object, .blocked); try std.testing.expectError( error.InvalidProfilingJson, validateMeasurementOrder(object, .random_interleaved), );}test "profiling analysis keeps failed warmups out of measurement timing" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); const value = try std.json.parseFromSliceLeaky( std.json.Value, allocator, \\{"schema":"tiny.profiling.workload/v4","event":"workload", \\ "workload":{"name":"w","package":"p","step":"bench", \\ "surface":"benchmark"}, \\ "scope":"workload-binary","causal":false,"tracy":false, \\ "trace_allocations":false, \\ "status":{"state":"failed","exit_code":9},"timing":{"wall_ns":7}, \\ "warmup":{"execution_count":1, \\ "executions":[{"index":1,"exit_code":9,"wall_ns":7}]}, \\ "measurement":{"execution_count":0,"acquisition_order":"fixed_plan_order", \\ "workload_output_retention":"no_measured_execution", \\ "measured_artifact_layout":"none", \\ "allocation_summary_retention":"disabled", \\ "benchmark_process_domain":{"benchmark_surface":true, \\ "direct_execution":true,"host_profiler":false,"tracy":false, \\ "causal":false,"allocation_trace":false,"capture_control":false}, \\ "benchmark_process_reduction":{ \\ "schema":"tiny.profiling.benchmark-process-reduction/v1", \\ "state":"not_applicable","process_count":0, \\ "reason":"fewer_than_two_executions"},"executions":[]}, \\ "artifacts":{"root":"workloads/w"}} , .{}, ); var workload = try parseWorkload(allocator, try json.object(value), &.{}, 1); try finalizeExecutionSummary(&workload); try std.testing.expectEqual(@as(usize, 1), workload.warmup_count); try std.testing.expectEqual(@as(u64, 7), workload.warmup_total_wall_ns); try std.testing.expectEqual(@as(usize, 0), workload.execution_count); try std.testing.expectEqual(@as(u64, 0), workload.total_wall_ns);}test "profiling analysis keeps failed setup out of measurement timing" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); const value = try std.json.parseFromSliceLeaky( std.json.Value, allocator, \\{"schema":"tiny.profiling.workload/v4","event":"workload", \\ "workload":{"name":"w","package":"p","step":"bench", \\ "surface":"benchmark"}, \\ "scope":"workload-binary","causal":false,"tracy":false, \\ "trace_allocations":false, \\ "status":{"state":"failed","exit_code":7},"timing":{"wall_ns":19}, \\ "measurement":{"execution_count":0,"acquisition_order":"fixed_plan_order", \\ "workload_output_retention":"no_measured_execution", \\ "measured_artifact_layout":"none", \\ "allocation_summary_retention":"disabled", \\ "benchmark_process_domain":{"benchmark_surface":true, \\ "direct_execution":true,"host_profiler":false,"tracy":false, \\ "causal":false,"allocation_trace":false,"capture_control":false}, \\ "benchmark_process_reduction":{ \\ "schema":"tiny.profiling.benchmark-process-reduction/v1", \\ "state":"not_applicable","process_count":0, \\ "reason":"fewer_than_two_executions"},"executions":[]}, \\ "artifacts":{"root":"workloads/w"}} , .{}, ); var workload = try parseWorkload(allocator, try json.object(value), &.{}, 1); try finalizeExecutionSummary(&workload); try std.testing.expectEqual(@as(usize, 0), workload.execution_count); try std.testing.expectEqual(@as(u64, 0), workload.wall_ns); try std.testing.expectEqual(@as(u64, 0), workload.total_wall_ns); try std.testing.expect(workload.wall_distribution == null);}test "profiling analysis keeps recorded paths when roots already agree" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); try std.testing.expectEqualStrings( "zig-out/profiling/run-a/workloads/w/structured.jsonl", (try relocatePath(allocator, "zig-out/profiling/run-a/workloads/w/structured.jsonl", "zig-out/profiling/run-a", "zig-out/profiling/run-a")).?, ); try std.testing.expectEqualStrings( "elsewhere/file.jsonl", (try relocatePath(allocator, "elsewhere/file.jsonl", "zig-out/profiling/run-a", "moved/run-a")).?, ); try std.testing.expectEqualStrings( "moved/run-a/workloads/w/structured.jsonl", (try relocatePath(allocator, "zig-out/profiling/run-a/workloads/w/structured.jsonl", "zig-out/profiling/run-a", "moved/run-a")).?, ); try std.testing.expect(!pathHasPrefix("zig-out/profiling/run-ab/x", "zig-out/profiling/run-a"));}test "profiling analysis relocates allocation repetition evidence" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); const value = try std.json.parseFromSliceLeaky( std.json.Value, allocator, \\{"schema":"tiny.profiling.workload/v4","event":"workload", \\ "workload":{"name":"w","package":"p","step":"bench", \\ "surface":"benchmark"}, \\ "scope":"workload-binary","causal":false,"tracy":false, \\ "trace_allocations":false, \\ "status":{"state":"passed","exit_code":0}, \\ "timing":{"wall_ns":10}, \\ "measurement":{"execution_count":0,"acquisition_order":"fixed_plan_order", \\ "workload_output_retention":"no_measured_execution", \\ "measured_artifact_layout":"none", \\ "allocation_summary_retention":"disabled", \\ "benchmark_process_domain":{"benchmark_surface":true, \\ "direct_execution":true,"host_profiler":false,"tracy":false, \\ "causal":false,"allocation_trace":false,"capture_control":false}, \\ "benchmark_process_reduction":{ \\ "schema":"tiny.profiling.benchmark-process-reduction/v1", \\ "state":"not_applicable","process_count":0, \\ "reason":"fewer_than_two_executions"},"executions":[]}, \\ "artifacts":{"root":"old/workloads/w","allocation_repetitions": \\ "old/workloads/w/allocations.repetitions.jsonl"}} , .{}, ); var workload = try parseWorkload(allocator, try json.object(value), &.{}, 1); try relocateWorkload(allocator, &workload, "old", "moved"); try std.testing.expectEqualStrings( "moved/workloads/w/allocations.repetitions.jsonl", workload.allocation_repetitions_path.?, );}Source: src/profiling/analyze/root.zig:4
zig
pub const load = @import("load.zig");Complete call list for analyze.load.loadRun
10 direct calls.
src.profiling.analyze.load.loadWorkload[function] — private; no exact target atsrc/profiling/analyze/load.zig:103in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.normalizeRunOrder[function] — private; no exact target atsrc/profiling/analyze/load.zig:216in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.parseGit[function] — private; no exact target atsrc/profiling/analyze/load.zig:240in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.parseOptimize[function] — private; no exact target atsrc/profiling/analyze/load.zig:255in nearest public ownertiny.profiling.analyze.loadtiny.profiling.baseline.resolveRun[function] atsrc/profiling/baseline.zig:130tiny.profiling.catalog.Suite.parse[function] atsrc/profiling/catalog.zig:11tiny.profiling.environment.parse[function] atsrc/profiling/environment.zig:86tiny.profiling.json.asU64[function] atsrc/profiling/json.zig:31tiny.profiling.json.object[function] atsrc/profiling/json.zig:3tiny.profiling.json.strings[function] atsrc/profiling/json.zig:67
Complete caller list for analyze.load.parseWorkload
8 direct callers.
src.profiling.analyze.load.loadWorkload[function] — private; no exact target atsrc/profiling/analyze/load.zig:103in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.test_profiling_analysis_accepts_a_partial_numbered_execution_receipt[function] — test; no exact target atsrc/profiling/analyze/load.zig:1040in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.test_profiling_analysis_keeps_failed_setup_out_of_measurement_timing[function] — test; no exact target atsrc/profiling/analyze/load.zig:1330in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.test_profiling_analysis_keeps_failed_warmups_out_of_measurement_timing[function] — test; no exact target atsrc/profiling/analyze/load.zig:1292in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.test_profiling_analysis_rejects_malformed_v4_measurement_and_artifact_shapes[function] — test; no exact target atsrc/profiling/analyze/load.zig:1101in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.test_profiling_analysis_rejects_unsupported_workload_schema[function] — test; no exact target atsrc/profiling/analyze/load.zig:1076in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.test_profiling_analysis_relocates_allocation_repetition_evidence[function] — test; no exact target atsrc/profiling/analyze/load.zig:1385in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.test_profiling_analysis_validates_recorded_acquisition_context[function] — test; no exact target atsrc/profiling/analyze/load.zig:1138in nearest public ownertiny.profiling.analyze.load
Complete call list for analyze.load.parseWorkload
19 direct calls.
src.profiling.analyze.load.parseAcquisition[function] — private; no exact target atsrc/profiling/analyze/load.zig:540in nearest public ownertiny.profiling.analyze.loadtiny.profiling.analyze.load.parseCaptures[function] atsrc/profiling/analyze/load.zig:673src.profiling.analyze.load.parseProfilerArtifacts[function] — private; no exact target atsrc/profiling/analyze/load.zig:362in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.parseResourceUsageSource[function] — private; no exact target atsrc/profiling/analyze/load.zig:430in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.requiredArtifactPath[function] — private; no exact target atsrc/profiling/analyze/load.zig:413in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.resourceValue[function] — private; no exact target atsrc/profiling/analyze/load.zig:439in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.retainWorkloadIdentity[function] — private; no exact target atsrc/profiling/analyze/load.zig:444in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.validateBenchmarkReductionDomain[function] — private; no exact target atsrc/profiling/analyze/load.zig:475in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.validateMeasurementOrder[function] — private; no exact target atsrc/profiling/analyze/load.zig:523in nearest public ownertiny.profiling.analyze.loadsrc.profiling.analyze.load.validateWorkloadOrder[function] — private; no exact target atsrc/profiling/analyze/load.zig:595in nearest public ownertiny.profiling.analyze.loadtiny.profiling.json.asF64[function] atsrc/profiling/json.zig:58tiny.profiling.json.asI64[function] atsrc/profiling/json.zig:40tiny.profiling.json.asU64[function] atsrc/profiling/json.zig:31tiny.profiling.json.object[function] atsrc/profiling/json.zig:3tiny.profiling.measurement.outputRetention[function] atsrc/profiling/measurement.zig:263tiny.profiling.measurement.parseExecutions[function] atsrc/profiling/measurement.zig:147tiny.profiling.measurement.parseWarmups[function] atsrc/profiling/measurement.zig:168tiny.profiling.perturbation.parseMeasurement[function] atsrc/profiling/perturbation.zig:157tiny.profiling.perturbation.summarize[function] atsrc/profiling/perturbation.zig:321
Audit
| Definitions | 9 |
|---|---|
| Public names | 10 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |