PayloadHandle

Struct PayloadHandle 

Source
pub struct PayloadHandle { /* private fields */ }
Expand description

Handle to a background payload spawned via PayloadRun::spawn. Wraps a guest-local std::process::Child; wait / kill both consume the handle and return the collected metrics + assertion verdict.

Drop behavior: if the handle is dropped without wait/kill, the child and every process it forked are SIGKILLed via the process group headed by the child, then the child is reaped with child.wait(), and a stderr warning is emitted so the test author sees the implicit drop. The process-group kill reaches every descendant of multi-process payloads (stress-ng, schbench worker mode, fio --numjobs); without it the orphans keep stdout/stderr open, block wait_and_capture, and lose metrics.

When multiple handles are active, sidecar entries appear in finalization order (the order .wait(), .kill(), or .try_wait() returning Ok(Some(..)) are called), not spawn order. .try_wait() only records on its terminal branch; an Ok(None) return keeps the handle live and defers the sidecar write to the next terminal call.

Implementations§

Source§

impl PayloadHandle

Source

pub fn payload_name(&self) -> &'static str

Name of the Payload this handle was spawned from — i.e. the identity key used by step-level ops to address a running payload. Step-local ops (Op::WaitPayload, Op::KillPayload) match handles by this name.

Source

pub fn pid(&self) -> Option<u32>

Live child’s OS-level pid, or None once wait/kill/ try_wait has consumed the child.

Integration tests that spawn a workload and then need to target it with a second tool (for example the jemalloc-TLS probe in tests/jemalloc_probe_tests.rs, which passes the workload’s pid to ktstr-jemalloc-probe --pid) read this value between spawn and wait/kill/try_wait. The internal fork-descendant reap test also uses it to probe the process group via killpg(_, 0) after kill() without reaching into the private child field.

Source

pub fn wait(self) -> Result<(AssertResult, PayloadMetrics)>

Block until the child exits naturally, then extract metrics and evaluate checks, matching the foreground .run() return shape.

Metrics are also recorded to the per-test sidecar via the SHM ring; the returned tuple is a convenience view of the same values.

Source

pub fn kill(self) -> Result<(AssertResult, PayloadMetrics)>

SIGKILL the child and every process it forked, reap it, and return whatever stdout+stderr was captured along with the process exit code. Suitable for time-boxed background loads.

The signal is delivered via killpg(child_pid, SIGKILL) rather than child.kill() because build_command places the payload at the head of its own process group. Multi-process payloads (stress-ng, schbench worker mode, fio –numjobs) fork descendants that keep stdout/stderr open; killing only the head would orphan those writers and block wait_and_capture forever, losing every metric.

Metrics are also recorded to the per-test sidecar via the SHM ring; the returned tuple is a convenience view of the same values.

Source

pub fn try_wait(&mut self) -> Result<Option<(AssertResult, PayloadMetrics)>>

Non-blocking check for exit without consuming the handle. Returns Ok(Some((result, metrics))) once the child has exited and output is drained; Ok(None) while still running. The handle remains live on Ok(None).

On the terminal Ok(Some(..)) return, metrics are also recorded to the per-test sidecar via the SHM ring; the returned tuple is a convenience view of the same values.

Trait Implementations§

Source§

impl Debug for PayloadHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for PayloadHandle

Drop-safety net for handles that fall out of scope without going through PayloadHandle::wait, PayloadHandle::kill, or PayloadHandle::try_wait (the three paths that .take() the child normally). Drop routes the process group through kill_payload_process_group — the SAME kill path the explicit kill() method uses — so there is no redundant child.kill() call: the killpg + single-pid SIGKILL inside kill_payload_process_group is belt-and-suspenders-by-design (see its doc for the pre-exec ESRCH race rationale), not two independent kills stacked. child.wait() reaps the zombie so the pid slot is freed even on the “dropped without consume” path, and the one-shot eprintln tells the operator metrics were lost.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more