Skip to documentation
SLOP

tiny.profiling.driver.acquire

Reference tiny.profiling driver acquire

Defined in driver.

API (7)

Actions

Public operations.

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

Source

Called byCallsdriver.controlrunCaptureControlPlandriver.measurerunMeasuredWorkloadprivate; no linksrc.profiling.driver.schedulerunInterleavedEntrydriver.acquireaggregateUnmeasuredFailuredriver.acquirecombineExecutionResultsdriver.acquireaggregateMeasuredCommand
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsdriver.acquireaggregateMeasuredCommandprivate; no linksrc.profiling.driver.controlfinalizeCaptureAggregatedriver.prepareinitializeWorkloaddriver.runrunPreparedWorkloadprivate; no linksrc.profiling.driver.scheduleinterleavedWarmupSucceededdriver.acquireaggregateUnmeasuredFailure
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsdriver.acquireaggregateMeasuredCommandtest; no linksrc.profiling.driver.acquiretest: profiling driver aggregates rep...private; no linksrc.profiling.driver.controlappendCaptureExecutionprivate; no linksrc.profiling.driver.acquireaddOptionalF64private; no linksrc.profiling.driver.acquirecombineResourceCountprivate; no linksrc.profiling.driver.acquirematchingResourceUsageSourceprivate; no linksrc.profiling.driver.acquiremaxOptionalI64driver.acquirecombineExecutionResults
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsdriver.artifactcollectMeasuredArtifactsdriver.acquirerecordAllocationRepetition
Static calls · unresolved targets: 0 · external targets: 2.
Called byCallsdriver.acquirerunMeasuredCommandprivate; no linksrc.profiling.driver.controlrunControlConditiondriver.acquirerunResetdriver.environmenteffectiveChildEnvironmentdriver.environmentworkloadBenchControlexecuterunChildhost.statecapturedriver.acquirerunChildAcquisition
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsprivate; no linksrc.profiling.driver.controlrunCaptureConditiondriver.controlrunCaptureControlPlandriver.measurerunMeasuredWorkloadprivate; no linksrc.profiling.driver.schedulerunInterleavedEntrydriver.acquirerunChildAcquisitiondriver.acquirerunMeasuredCommand
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsdriver.acquirerunChildAcquisitiondriver.preparerunWarmupsdriver.environmenteffectiveChildEnvironmentexecuterunRecordedCommandrecordresetPathsdriver.acquirerunReset
Static calls · unresolved targets: 1 · external targets: 0.

Source: src/profiling/driver/acquire.zig

zig
const std = @import("std");const sys = @import("sys");const allocation_trace = @import("../capture/root.zig").memtrace;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 MeasuredCommand = @import("root.zig").model.MeasuredCommand;const PreparedWorkload = @import("root.zig").model.PreparedWorkload;const WorkloadContext = @import("root.zig").model.WorkloadContext;const effectiveChildEnvironment = @import("root.zig").environment.effectiveChildEnvironment;const workloadBenchControl = @import("root.zig").environment.workloadBenchControl;pub fn runMeasuredCommand(    allocator: std.mem.Allocator,    context: *const WorkloadContext,    workload: catalog.Workload,    prepared: PreparedWorkload,    argv: []const []const u8,    env_paths: execute.ArtifactEnv,    condition: host.state.Condition,    reset_phase: record.ResetPhase,    phase_index: usize,    resets: *std.ArrayList(record.Reset),) !MeasuredCommand {    return try runChildAcquisition(        allocator,        context,        prepared,        argv,        env_paths,        context.request.trace_allocations or workload.tracesAllocationsByDefault(),        context.request.tracy,        context.request.control,        condition,        reset_phase,        phase_index,        resets,    );}pub fn runChildAcquisition(    allocator: std.mem.Allocator,    context: *const WorkloadContext,    prepared: PreparedWorkload,    argv: []const []const u8,    env_paths: execute.ArtifactEnv,    trace_allocations: bool,    tracy: bool,    control: execute.BenchControl,    condition: host.state.Condition,    reset_phase: record.ResetPhase,    phase_index: usize,    resets: *std.ArrayList(record.Reset),) !MeasuredCommand {    if (try runReset(        allocator,        context,        prepared,        reset_phase,        phase_index,        resets,    )) |failure| {        return .{            .execution = failure,            .host_state = null,            .measured = false,        };    }    const artifact_root = std.fs.path.dirname(env_paths.stdout) orelse        return error.InvalidExecutionArtifacts;    try sys.fs.createDirPath(artifact_root);    const before = host.state.capture();    const execution = try execute.runChild(        allocator,        context.process_io,        effectiveChildEnvironment(context, &prepared),        prepared.execution_plan.cwd,        argv,        env_paths,        trace_allocations,        tracy,        workloadBenchControl(control, prepared.runtime.environment),    );    return .{        .execution = execution,        .host_state = .{            .condition = condition,            .before = before,            .after = host.state.capture(),        },        .measured = true,    };}pub fn runReset(    allocator: std.mem.Allocator,    context: *const WorkloadContext,    prepared: PreparedWorkload,    phase: record.ResetPhase,    phase_index: usize,    resets: *std.ArrayList(record.Reset),) !?execute.Result {    const reset = prepared.runtime.reset orelse return null;    std.debug.assert(prepared.execution_plan.direct);    if (resets.items.len >= record.maximum_reset_receipts) {        return error.TooManyResetReceipts;    }    const sequence = resets.items.len + 1;    const paths = try record.resetPaths(        allocator,        prepared.paths.root,        sequence,        phase,        phase_index,    );    const command = try execute.runRecordedCommand(        allocator,        context.process_io,        effectiveChildEnvironment(context, &prepared),        reset.cwd,        reset.argv,        paths.stdout,        paths.stderr,    );    try resets.append(allocator, .{        .sequence = sequence,        .phase = phase,        .phase_index = phase_index,        .command = command,    });    return if (command.execution.exit_code == 0)        null    else        command.execution;}pub fn recordAllocationRepetition(    allocator: std.mem.Allocator,    context: *const WorkloadContext,    workload: catalog.Workload,    prepared: PreparedWorkload,    allocations_path: []const u8,    result: execute.Result,    execution_index: usize,    planned_execution_count: usize,) !void {    if (planned_execution_count <= 1) return;    std.debug.assert(execution_index <= planned_execution_count);    try allocation_trace.recordRepetition(allocator, .{        .enabled = context.request.trace_allocations or            workload.tracesAllocationsByDefault(),        .exit_code = result.exit_code,        .execution_index = execution_index,        .capture_path = allocations_path,        .repetitions_path = prepared.paths.allocation_repetitions,    });}pub fn aggregateMeasuredCommand(    aggregate: ?execute.Result,    measurement: MeasuredCommand,) execute.Result {    if (!measurement.measured) {        std.debug.assert(measurement.host_state == null);        return aggregateUnmeasuredFailure(aggregate, measurement.execution);    }    std.debug.assert(measurement.host_state != null);    return if (aggregate) |current|        combineExecutionResults(current, measurement.execution)    else        measurement.execution;}pub fn aggregateUnmeasuredFailure(    aggregate: ?execute.Result,    failure: execute.Result,) execute.Result {    std.debug.assert(failure.exit_code != 0);    var result = aggregate orelse return .{        .exit_code = failure.exit_code,        .wall_ns = 0,    };    std.debug.assert(result.exit_code == 0);    result.exit_code = failure.exit_code;    result.pid = null;    return result;}pub fn combineExecutionResults(left: execute.Result, right: execute.Result) execute.Result {    const resource_usage_source = matchingResourceUsageSource(        left.resource_usage_source,        right.resource_usage_source,    );    return .{        .pid = null,        .exit_code = if (left.exit_code != 0) left.exit_code else right.exit_code,        .wall_ns = std.math.add(u64, left.wall_ns, right.wall_ns) catch std.math.maxInt(u64),        .resource_usage_source = resource_usage_source,        .maxrss_kib = maxOptionalI64(left.maxrss_kib, right.maxrss_kib),        .user_s = addOptionalF64(left.user_s, right.user_s),        .system_s = addOptionalF64(left.system_s, right.system_s),        .minor_page_faults = combineResourceCount(            resource_usage_source,            left.minor_page_faults,            right.minor_page_faults,        ),        .major_page_faults = combineResourceCount(            resource_usage_source,            left.major_page_faults,            right.major_page_faults,        ),        .voluntary_context_switches = combineResourceCount(            resource_usage_source,            left.voluntary_context_switches,            right.voluntary_context_switches,        ),        .involuntary_context_switches = combineResourceCount(            resource_usage_source,            left.involuntary_context_switches,            right.involuntary_context_switches,        ),    };}fn matchingResourceUsageSource(    left: ?sys.process.ResourceUsageSource,    right: ?sys.process.ResourceUsageSource,) ?sys.process.ResourceUsageSource {    const left_value = left orelse return null;    const right_value = right orelse return null;    return if (left_value == right_value) left_value else null;}fn maxOptionalI64(left: ?i64, right: ?i64) ?i64 {    const left_value = left orelse return right;    const right_value = right orelse return left;    return @max(left_value, right_value);}fn addOptionalF64(left: ?f64, right: ?f64) ?f64 {    return (left orelse return null) + (right orelse return null);}fn addOptionalU64(left: ?u64, right: ?u64) ?u64 {    return (left orelse return null) +| (right orelse return null);}fn combineResourceCount(    source: ?sys.process.ResourceUsageSource,    left: ?u64,    right: ?u64,) ?u64 {    if (source == null) return null;    return addOptionalU64(left, right);}test "profiling driver aggregates repeated counter executions" {    const result = combineExecutionResults(.{        .exit_code = 0,        .wall_ns = 10,        .resource_usage_source = .wait4_rusage,        .maxrss_kib = 40,        .user_s = 1.5,        .system_s = 0.25,        .minor_page_faults = 4,        .major_page_faults = 1,        .voluntary_context_switches = 2,        .involuntary_context_switches = 3,    }, .{        .exit_code = 7,        .wall_ns = 20,        .resource_usage_source = .wait4_rusage,        .maxrss_kib = 60,        .user_s = 2.5,        .system_s = 0.5,        .minor_page_faults = 6,        .major_page_faults = 2,        .voluntary_context_switches = 5,        .involuntary_context_switches = 7,    });    try std.testing.expectEqual(@as(i64, 7), result.exit_code);    try std.testing.expectEqual(@as(u64, 30), result.wall_ns);    try std.testing.expectEqual(@as(?i64, 60), result.maxrss_kib);    try std.testing.expectEqual(@as(?f64, 4), result.user_s);    try std.testing.expectEqual(@as(?f64, 0.75), result.system_s);    try std.testing.expectEqual(        sys.process.ResourceUsageSource.wait4_rusage,        result.resource_usage_source.?,    );    try std.testing.expectEqual(@as(?u64, 10), result.minor_page_faults);    try std.testing.expectEqual(@as(?u64, 3), result.major_page_faults);    try std.testing.expectEqual(@as(?u64, 7), result.voluntary_context_switches);    try std.testing.expectEqual(@as(?u64, 10), result.involuntary_context_switches);    try std.testing.expect(addOptionalF64(null, 1) == null);    try std.testing.expect(addOptionalU64(null, 1) == null);    try std.testing.expect(matchingResourceUsageSource(.wait4_rusage, null) == null);    const mixed = combineExecutionResults(        .{ .exit_code = 0, .wall_ns = 1, .minor_page_faults = 1 },        .{            .exit_code = 0,            .wall_ns = 1,            .resource_usage_source = .wait4_rusage,            .minor_page_faults = 1,        },    );    try std.testing.expect(mixed.resource_usage_source == null);    try std.testing.expect(mixed.minor_page_faults == null);}

Source: src/profiling/driver/root.zig:1

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

Audit

Definitions8
Public names8
Members0
Version26.7.0
Revisiondaab053ee433