FEATURE: Track resource usage in Landlock.capture - #5
Closed
tgxworld wants to merge 3 commits into
Closed
Conversation
Capture results previously exposed output and status without reporting how long the child ran or which CPU and memory resources it consumed. Callers could not measure sandboxed command cost, and process-wide accounting could not safely distinguish concurrent children. This commit reaps capture children with native `wait4`, collecting the matching status and `rusage` atomically. Native waits release the GVL and remain interruptible, while capture cleanup uses nonblocking polling so other Ruby threads can continue running. `CaptureResult` now exposes monotonic elapsed time and an immutable `ResourceUsage` value for successful and failed commands, with Linux peak RSS normalized to bytes. Once a child is reaped, retained descendant pipes cannot replace its status, usage, or completion time during timeout cleanup. The existing three-value destructuring contract remains unchanged, and `capture!` errors continue to carry the complete result.
tgxworld
marked this pull request as ready for review
August 20, 2026 04:00
The changelog named the new measurements but did not show callers how to access them or clarify which process they describe. This commit adds successful and failed capture examples and describes the accounting as belonging to the direct process launched by each capture.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Capture results previously exposed output and status without reporting how long the command ran or which CPU and memory resources it consumed. Callers could not measure sandboxed command cost, and process-wide accounting could not safely distinguish concurrent captures.
This commit reaps each capture's direct process with native
wait4, collecting its matching status andrusageatomically. The native helper is replaced by the target command withexec, so the helper and target keep the same PID and are measured as one process. This accounting is isolated from unrelated children running concurrently; it is not a general process-tree profiler, and descendant accounting follows the operating system'swait4semantics.Native waits release the GVL and remain interruptible, while capture cleanup uses nonblocking polling so other Ruby threads can continue running.
CaptureResultnow exposes monotonic elapsed time and an immutableResourceUsagevalue for successful and failed commands, with Linux peak RSS normalized to bytes:For
Landlock.capture!failures, the same measurements are available througherror.result:Once a process is reaped, retained descendant pipes cannot replace its status, usage, or completion time during timeout cleanup.
The existing three-value destructuring contract remains unchanged, and
capture!errors continue to carry the complete result.