tiny.profiling.driver.control
Defined in driver.
API (1)
Actions
Public operations.
Source
Source: src/profiling/driver/control.zig
zig
const std = @import("std");const catalog = @import("../root.zig").catalog;const execute = @import("../root.zig").execute;const host = @import("../root.zig").host;const perturbation = @import("../root.zig").perturbation;const record = @import("../root.zig").record;const MeasuredCommand = @import("root.zig").model.MeasuredCommand;const MeasuredWorkload = @import("root.zig").model.MeasuredWorkload;const PreparedWorkload = @import("root.zig").model.PreparedWorkload;const WorkloadContext = @import("root.zig").model.WorkloadContext;const aggregateMeasuredCommand = @import("root.zig").acquire.aggregateMeasuredCommand;const aggregateUnmeasuredFailure = @import("root.zig").acquire.aggregateUnmeasuredFailure;const combineExecutionResults = @import("root.zig").acquire.combineExecutionResults;const runChildAcquisition = @import("root.zig").acquire.runChildAcquisition;const runMeasuredCommand = @import("root.zig").acquire.runMeasuredCommand;const writeCaptureControlProgress = @import("root.zig").progress.writeCaptureControlProgress;pub fn runCaptureControlPlan( allocator: std.mem.Allocator, context: *const WorkloadContext, workload: catalog.Workload, prepared: PreparedWorkload, capture_env: execute.ArtifactEnv, resets: *std.ArrayList(record.Reset),) !MeasuredWorkload { const options = context.request.capture_control; const seed = perturbation.workloadSeed(options.seed, workload.name); const configuration = perturbation.Configuration{ .host_kind = context.request.host_lanes.kind(), .tracy = context.request.tracy, .allocations = context.request.trace_allocations or workload.tracesAllocationsByDefault(), }; std.debug.assert(configuration.any()); const orders = try perturbation.schedule(allocator, options.repeat, seed); const pairs = try allocator.alloc(perturbation.Pair, orders.len); for (pairs, orders, 0..) |*pair, pair_order, index| { pair.* = .{ .index = @intCast(index + 1), .order = pair_order }; } const control_paths = try perturbation.makePaths(allocator, prepared.paths.root); if (!captureControlAvailable(context, prepared)) { const measurement = try runMeasuredCommand( allocator, context, workload, prepared, prepared.wrapped.argv, capture_env, .capture, .capture, 1, resets, ); const result = measurement.execution; return .{ .aggregate = aggregateMeasuredCommand(null, measurement), .executions = if (measurement.measured) try allocator.dupe(record.MeasuredExecution, &.{.{ .index = 1, .result = result, .paths = null, }}) else &.{}, .host_state_windows = if (measurement.host_state) |window| try allocator.dupe(host.state.Window, &.{window}) else &.{}, .reset_failed = !measurement.measured, .perturbation = .{ .state = captureUnavailableState(measurement.measured), .base_seed = options.seed, .workload_seed = seed, .pairs = pairs, .configuration = configuration, .control_artifacts = control_paths, }, }; } const absolute_control_paths = try perturbation.makePaths( allocator, prepared.absolute_root, ); var capture_executions: std.ArrayList(record.MeasuredExecution) = .empty; var host_state_windows: std.ArrayList(host.state.Window) = .empty; var capture_aggregate: ?execute.Result = null; var external_failure: ?execute.Result = null; var incomplete = false; var reset_failed = false; pair_loop: for (pairs) |*pair| { if (context.progress_output == .terminal) { try writeCaptureControlProgress( allocator, workload.name, pair.*, pairs.len, ); } switch (pair.order) { .control_first => { const control_measurement = try runControlCondition( allocator, context, prepared, absolute_control_paths.artifactEnv(), pair.index, resets, ); if (!retainMeasuredCondition( &pair.control, control_measurement, &reset_failed, &external_failure, )) { incomplete = true; break :pair_loop; } if (control_measurement.host_state) |window| { try host_state_windows.append(allocator, window); } if (pair.control.?.exit_code != 0) { external_failure = pair.control.?; incomplete = true; break :pair_loop; } const capture_measurement = try runCaptureCondition( allocator, context, workload, prepared, capture_env, pair.index, resets, ); if (!retainMeasuredCondition( &pair.capture, capture_measurement, &reset_failed, &external_failure, )) { incomplete = true; break :pair_loop; } if (capture_measurement.host_state) |window| { try host_state_windows.append(allocator, window); } try appendCaptureExecution( allocator, &capture_executions, &capture_aggregate, pair.capture.?, ); if (pair.capture.?.exit_code != 0) { incomplete = true; break :pair_loop; } }, .capture_first => { const capture_measurement = try runCaptureCondition( allocator, context, workload, prepared, capture_env, pair.index, resets, ); if (!retainMeasuredCondition( &pair.capture, capture_measurement, &reset_failed, &external_failure, )) { incomplete = true; break :pair_loop; } if (capture_measurement.host_state) |window| { try host_state_windows.append(allocator, window); } try appendCaptureExecution( allocator, &capture_executions, &capture_aggregate, pair.capture.?, ); if (pair.capture.?.exit_code != 0) { incomplete = true; break :pair_loop; } const control_measurement = try runControlCondition( allocator, context, prepared, absolute_control_paths.artifactEnv(), pair.index, resets, ); if (!retainMeasuredCondition( &pair.control, control_measurement, &reset_failed, &external_failure, )) { incomplete = true; break :pair_loop; } if (control_measurement.host_state) |window| { try host_state_windows.append(allocator, window); } if (pair.control.?.exit_code != 0) { external_failure = pair.control.?; incomplete = true; break :pair_loop; } }, } } const aggregate = finalizeCaptureAggregate( capture_aggregate, external_failure, ); return .{ .aggregate = aggregate, .executions = try capture_executions.toOwnedSlice(allocator), .host_state_windows = try host_state_windows.toOwnedSlice(allocator), .reset_failed = reset_failed, .perturbation = .{ .state = if (incomplete) .incomplete else .complete, .base_seed = options.seed, .workload_seed = seed, .pairs = pairs, .configuration = configuration, .control_artifacts = control_paths, }, };}fn retainMeasuredCondition( destination: *?execute.Result, measurement: MeasuredCommand, reset_failed: *bool, external_failure: *?execute.Result,) bool { if (!measurement.measured) { std.debug.assert(measurement.host_state == null); reset_failed.* = true; external_failure.* = measurement.execution; return false; } std.debug.assert(measurement.host_state != null); destination.* = measurement.execution; return true;}fn captureUnavailableState(measured: bool) perturbation.State { return if (measured) .capture_unavailable else .incomplete;}fn finalizeCaptureAggregate( capture: ?execute.Result, external_failure: ?execute.Result,) execute.Result { if (external_failure) |failure| { return aggregateUnmeasuredFailure(capture, failure); } return capture.?;}fn captureControlAvailable( context: *const WorkloadContext, prepared: PreparedWorkload,) bool { if (context.request.tracy or context.request.trace_allocations) return true; if (!context.request.host_lanes.any()) return false; return context.tool_probe.available and !prepared.execution_plan.missing_bin;}fn runControlCondition( allocator: std.mem.Allocator, context: *const WorkloadContext, prepared: PreparedWorkload, artifacts: execute.ArtifactEnv, phase_index: usize, resets: *std.ArrayList(record.Reset),) !MeasuredCommand { var control = context.request.control; control.causal = false; return try runChildAcquisition( allocator, context, prepared, prepared.execution_plan.argv, artifacts, false, false, control, .capture_control, .capture_control, phase_index, resets, );}fn runCaptureCondition( allocator: std.mem.Allocator, context: *const WorkloadContext, workload: catalog.Workload, prepared: PreparedWorkload, artifacts: execute.ArtifactEnv, phase_index: usize, resets: *std.ArrayList(record.Reset),) !MeasuredCommand { try host.resetCaptureArtifacts(prepared.wrapped); return try runMeasuredCommand( allocator, context, workload, prepared, prepared.wrapped.argv, artifacts, .capture, .capture, phase_index, resets, );}fn appendCaptureExecution( allocator: std.mem.Allocator, executions: *std.ArrayList(record.MeasuredExecution), aggregate: *?execute.Result, execution: execute.Result,) !void { try executions.append(allocator, .{ .index = executions.items.len + 1, .result = execution, .paths = null, }); aggregate.* = if (aggregate.*) |current| combineExecutionResults(current, execution) else execution;}test "profiling driver does not relabel reset failures as capture conditions" { var destination: ?execute.Result = null; var reset_failed = false; var first_failure: ?execute.Result = null; const kept = retainMeasuredCondition( &destination, .{ .execution = .{ .pid = 707, .exit_code = 9, .wall_ns = 4 }, .host_state = null, .measured = false, }, &reset_failed, &first_failure, ); try std.testing.expect(!kept); try std.testing.expect(destination == null); try std.testing.expect(reset_failed); try std.testing.expectEqual(@as(?u64, 707), first_failure.?.pid); try std.testing.expectEqual( perturbation.State.incomplete, captureUnavailableState(false), ); try std.testing.expectEqual( perturbation.State.capture_unavailable, captureUnavailableState(true), );}test "profiling driver excludes unmeasured failures from aggregate resources" { const measured = execute.Result{ .pid = 101, .exit_code = 0, .wall_ns = 12, .resource_usage_source = .wait4_rusage, .maxrss_kib = 42, .user_s = 1.5, .system_s = 0.5, .minor_page_faults = 3, .major_page_faults = 1, .voluntary_context_switches = 4, .involuntary_context_switches = 2, }; const reset = execute.Result{ .pid = 202, .exit_code = 13, .wall_ns = 99, .resource_usage_source = .wait4_rusage, .maxrss_kib = 900, }; var expected = measured; expected.pid = null; expected.exit_code = 13; try std.testing.expect(std.meta.eql( expected, finalizeCaptureAggregate(measured, reset), )); const empty = finalizeCaptureAggregate(null, reset); try std.testing.expectEqual(@as(i64, 13), empty.exit_code); try std.testing.expectEqual(@as(u64, 0), empty.wall_ns); try std.testing.expect(empty.pid == null); try std.testing.expect(empty.resource_usage_source == null); try std.testing.expect(empty.maxrss_kib == null);}test "profiling driver keeps failed measured capture process evidence" { const capture = execute.Result{ .pid = 303, .exit_code = 7, .wall_ns = 15, .resource_usage_source = .wait4_rusage, .maxrss_kib = 44, }; const aggregate = finalizeCaptureAggregate(capture, null); try std.testing.expect(std.meta.eql(capture, aggregate));}Source: src/profiling/driver/root.zig:3
zig
pub const control = @import("control.zig");Complete call list for driver.control.runCaptureControlPlan
13 direct calls.
tiny.profiling.driver.acquire.aggregateMeasuredCommand[function] atsrc/profiling/driver/acquire.zig:160tiny.profiling.driver.acquire.runMeasuredCommand[function] atsrc/profiling/driver/acquire.zig:14src.profiling.driver.control.appendCaptureExecution[function] — private; no exact target atsrc/profiling/driver/control.zig:328in nearest public ownertiny.profiling.driver.controlsrc.profiling.driver.control.captureControlAvailable[function] — private; no exact target atsrc/profiling/driver/control.zig:269in nearest public ownertiny.profiling.driver.controlsrc.profiling.driver.control.captureUnavailableState[function] — private; no exact target atsrc/profiling/driver/control.zig:255in nearest public ownertiny.profiling.driver.controlsrc.profiling.driver.control.finalizeCaptureAggregate[function] — private; no exact target atsrc/profiling/driver/control.zig:259in nearest public ownertiny.profiling.driver.controlsrc.profiling.driver.control.retainMeasuredCondition[function] — private; no exact target atsrc/profiling/driver/control.zig:238in nearest public ownertiny.profiling.driver.controlsrc.profiling.driver.control.runCaptureCondition[function] — private; no exact target atsrc/profiling/driver/control.zig:304in nearest public ownertiny.profiling.driver.controlsrc.profiling.driver.control.runControlCondition[function] — private; no exact target atsrc/profiling/driver/control.zig:278in nearest public ownertiny.profiling.driver.controltiny.profiling.driver.progress.writeCaptureControlProgress[function] atsrc/profiling/driver/progress.zig:7tiny.profiling.perturbation.makePaths[function] atsrc/profiling/perturbation.zig:101tiny.profiling.perturbation.schedule[function] atsrc/profiling/perturbation.zig:296tiny.profiling.perturbation.workloadSeed[function] atsrc/profiling/perturbation.zig:151
Audit
| Definitions | 2 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |