tiny.profiling.driver.prepare
Defined in driver.
API (3)
Actions
Public operations.
Source
Source: src/profiling/driver/prepare.zig
zig
const std = @import("std");const sys = @import("sys");const catalog = @import("../root.zig").catalog;const execute = @import("../root.zig").execute;const host = @import("../root.zig").host;const record = @import("../root.zig").record;const Initialization = @import("root.zig").model.Initialization;const PreparedWorkload = @import("root.zig").model.PreparedWorkload;const SetupOutcome = @import("root.zig").model.SetupOutcome;const WarmupWorkload = @import("root.zig").model.WarmupWorkload;const WorkloadContext = @import("root.zig").model.WorkloadContext;const absolutePath = @import("root.zig").paths.absolutePath;const absoluteWarmupArtifactEnv = @import("root.zig").paths.absoluteWarmupArtifactEnv;const aggregateUnmeasuredFailure = @import("root.zig").acquire.aggregateUnmeasuredFailure;const buildArgs = @import("root.zig").validation.buildArgs;const effectiveChildEnvironment = @import("root.zig").environment.effectiveChildEnvironment;const runReset = @import("root.zig").acquire.runReset;const validatePreparedChildConfiguration = @import("root.zig").validation.validatePreparedChildConfiguration;const warmupBenchControl = @import("root.zig").environment.warmupBenchControl;const workloadBenchControl = @import("root.zig").environment.workloadBenchControl;const writeWarmupProgress = @import("root.zig").progress.writeWarmupProgress;pub fn prepareWorkload( allocator: std.mem.Allocator, context: *const WorkloadContext, workload: catalog.Workload,) !PreparedWorkload { std.debug.assert(context.request.selection.selected(workload)); std.debug.assert(workload.name.len > 0); const build_args = try buildArgs( allocator, context.request.host_lanes.buildArgs(), context.request.tracy, context.metadata.optimize, ); const paths = try record.makeWorkloadPaths(allocator, context.paths, workload.name); const absolute_root = try absolutePath(allocator, paths.root); const runtime = try catalog.resolveRuntime(allocator, workload, absolute_root); var resolved_workload = workload; if (resolved_workload.bin) |*bin| bin.args = runtime.bin_args; const execution_plan = try execute.plan( allocator, context.zig_command, resolved_workload, context.request.forwarded, context.request.execution_scope.directFor(workload) or context.request.host_lanes.requiresDirect(), build_args, ); try validatePreparedChildConfiguration(workload, execution_plan); const child_environment = if (runtime.environment.len == 0) null else try execute.environmentWithOverrides( allocator, context.environ_map, runtime.environment, ); const wrapped = if (execution_plan.missing_bin) host.Wrapped{ .argv = execution_plan.argv } else try host.wrap( allocator, context.request.host_lanes, execution_plan.argv, absolute_root, context.tool_probe.available, ); return .{ .execution_plan = execution_plan, .runtime = runtime, .child_environment = child_environment, .paths = paths, .absolute_root = absolute_root, .wrapped = wrapped, .command = try execute.commandText( allocator, execution_plan.cwd, execution_plan.setup_argv, wrapped.argv, ), };}fn runSetup( allocator: std.mem.Allocator, context: *const WorkloadContext, prepared: PreparedWorkload,) !SetupOutcome { const setup_argv = prepared.execution_plan.setup_argv orelse return .{ .setup = null, .failure = null, }; const result = try execute.runCommand( context.process_io, context.environ_map, prepared.execution_plan.cwd, setup_argv, prepared.paths.setup_stdout, prepared.paths.setup_stderr, ); return .{ .setup = .{ .command = try execute.commandText( allocator, prepared.execution_plan.cwd, null, setup_argv, ), .pid = result.pid, .exit_code = result.exit_code, .wall_ns = result.wall_ns, .stdout_path = prepared.paths.setup_stdout, .stderr_path = prepared.paths.setup_stderr, }, .failure = if (result.exit_code == 0) null else result, };}pub fn initializeWorkload( allocator: std.mem.Allocator, context: *const WorkloadContext, prepared: PreparedWorkload,) !Initialization { const setup = try runSetup(allocator, context, prepared); if (setup.failure) |failure| { return .{ .setup = setup.setup, .prepare = null, .setup_failed = true, .prepare_failed = false, .failure = failure, }; } const preparation = try runPrepare(allocator, context, prepared); const prepare_failed = if (preparation) |command| command.execution.exit_code != 0 else false; return .{ .setup = setup.setup, .prepare = preparation, .setup_failed = false, .prepare_failed = prepare_failed, .failure = if (preparation) |command| if (prepare_failed) aggregateUnmeasuredFailure(null, command.execution) else null else null, };}fn runPrepare( allocator: std.mem.Allocator, context: *const WorkloadContext, prepared: PreparedWorkload,) !?execute.CommandResult { const command = prepared.runtime.prepare orelse return null; std.debug.assert(prepared.execution_plan.direct); return try execute.runRecordedCommand( allocator, context.process_io, effectiveChildEnvironment(context, &prepared), command.cwd, command.argv, prepared.paths.prepare_stdout, prepared.paths.prepare_stderr, );}pub fn runWarmups( allocator: std.mem.Allocator, context: *const WorkloadContext, workload: catalog.Workload, prepared: PreparedWorkload, resets: *std.ArrayList(record.Reset),) !WarmupWorkload { if (context.request.warmup_repeat == 0) return .{ .executions = &.{} }; try sys.fs.createDirPath(prepared.paths.warmup.root); const env_paths = try absoluteWarmupArtifactEnv(allocator, prepared.paths.warmup); var executions: std.ArrayList(execute.Result) = .empty; var failure: ?execute.Result = null; var reset_failed = false; for (0..context.request.warmup_repeat) |index| { if (context.progress_output == .terminal) { try writeWarmupProgress( allocator, workload.name, index, context.request.warmup_repeat, ); } if (try runReset( allocator, context, prepared, .warmup, index + 1, resets, )) |result| { failure = result; reset_failed = true; break; } const result = try execute.runChild( allocator, context.process_io, effectiveChildEnvironment(context, &prepared), prepared.execution_plan.cwd, prepared.execution_plan.argv, env_paths, false, false, warmupBenchControl(workloadBenchControl( context.request.control, prepared.runtime.environment, )), ); try executions.append(allocator, result); if (result.exit_code != 0) { failure = result; break; } } return .{ .executions = try executions.toOwnedSlice(allocator), .failure = failure, .reset_failed = reset_failed, };}Source: src/profiling/driver/root.zig:8
zig
pub const prepare = @import("prepare.zig");Complete call list for driver.prepare.runWarmups
7 direct calls.
tiny.profiling.driver.acquire.runReset[function] atsrc/profiling/driver/acquire.zig:96tiny.profiling.driver.environment.effectiveChildEnvironment[function] atsrc/profiling/driver/environment.zig:12tiny.profiling.driver.environment.warmupBenchControl[function] atsrc/profiling/driver/environment.zig:23tiny.profiling.driver.environment.workloadBenchControl[function] atsrc/profiling/driver/environment.zig:30tiny.profiling.driver.paths.absoluteWarmupArtifactEnv[function] atsrc/profiling/driver/paths.zig:45tiny.profiling.driver.progress.writeWarmupProgress[function] atsrc/profiling/driver/progress.zig:57tiny.profiling.execute.runChild[function] atsrc/profiling/execute.zig:454
Audit
| Definitions | 4 |
|---|---|
| Public names | 4 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |