Expand description
CLI support functions shared between ktstr and cargo-ktstr.
Validation, configuration, and kernel/KVM resolution logic used by both binaries.
Structs§
- Averaged
Group - Re-export of the comparison-policy types so downstream crates
using
ktstr::clias their public surface don’t need to reach into the internalktstr::statsmodule (which ispub(crate)— seelib.rs— and therefore not a stable public path). The policy is the only item instatsthat a CLI or external consumer constructs directly; every other item is internal plumbing reached viacli::compare_partitions. One aggregatedGauntletRowproduced bygroup_and_average_by, plus the pass-bookkeeping needed to render the per-group summary block (N/M passed+ the(S skip, I inc, F fail)breakdown). - Comparison
Policy - Re-export of the comparison-policy types so downstream crates
using
ktstr::clias their public surface don’t need to reach into the internalktstr::statsmodule (which ispub(crate)— seelib.rs— and therefore not a stable public path). The policy is the only item instatsthat a CLI or external consumer constructs directly; every other item is internal plumbing reached viacli::compare_partitions. Per-metric threshold policy drivingcompare_rows/compare_partitions. - CpuCap
- Re-export of the internal
vmm::host_topology::CpuCaptype so thektstrandcargo-ktstrCLI binaries (which import this module through thepub mod clisurface) can resolve--cpu-cap Nwithout depending on thepub(crate)vmmmodule. Keeping the canonical definition invmm::host_topology(so theacquire_llc_planinternal call site consumes its own type without needingcli) and re-exporting here — versus inverting the dependency — avoids pulling the CLI module into the VMM internals. Parsed--cpu-cap Nvalue. N is a CPU count: the planner reserves exactly N host CPUs by walking whole LLCs in contention- / NUMA-aware order (filtered to the calling process’s allowed cpuset) and partial-taking the last LLC soplan.cpus.len() == N. The flock set is still per-LLC (the last LLC is flocked whole even when only a prefix of its CPUs entersplan.cpus). Bounded to1..=usize::MAXat the constructor — a cap of 0 is nonsensical (reserving zero CPUs is just “don’t run”) and rejected upstream by the CLI layer, but we enforce the bound in the type system viaNonZeroUsizeso callers canCpuCap::new(...)?without a follow-up bounds check. - Fetch
Progress FetchProgressis the public handle thektstr/cargo-ktstrbinaries construct to render kernel-fetch progress (the parallelresolve_kernel_setand the single-shotkernel buildpaths). It must bepub(notpub(crate)) because those call sites live in the binary crates and thread&FetchProgressinto the library resolvers — the same lib/bin-boundary reasonSpinnerispub. The child-bar types (GroupBar,CloneProgress) staypub(crate): only the in-crate fetch path constructs them. Shared owner of the concurrent fetch progress bars for one resolve operation.- Gate
Options - Re-export of the comparison-policy types so downstream crates
using
ktstr::clias their public surface don’t need to reach into the internalktstr::statsmodule (which ispub(crate)— seelib.rs— and therefore not a stable public path). The policy is the only item instatsthat a CLI or external consumer constructs directly; every other item is internal plumbing reached viacli::compare_partitions. Operator-level perf-delta failure gate + render options, layered on top of the per-metric significance policy (which decides WHICH deltas are confident regressions). These decide HOW MANY / WHICH-NAMED confident regressions fail the run, and whether stable/noisy rows render. - Kernel
Build Result - Result of the post-acquisition kernel build pipeline.
- Kernel
DirCache Hit - Cache-hit signal returned from
resolve_kernel_dir_to_entrywhen a clean source tree’s cache entry was found and reused without invokingkernel_build_pipeline. - Kernel
DirOutcome - Result bundle from
resolve_kernel_dir_to_entry. - Kernel
Resolve Policy - Policy controlling
resolve_kernel_imagebehavior across binaries. - Phase
Display Options - Re-export of the comparison-policy types so downstream crates
using
ktstr::clias their public surface don’t need to reach into the internalktstr::statsmodule (which ispub(crate)— seelib.rs— and therefore not a stable public path). The policy is the only item instatsthat a CLI or external consumer constructs directly; every other item is internal plumbing reached viacli::compare_partitions. CLI-controlled rendering of the per-phase spread block incargo ktstr perf-delta --noise-adjust. Bundled as a struct so the 5-flag clap surface threads throughcompare_partitions_noiseas a single positional rather than five. Default value renders every phase / every metric / every paired row — equivalent to passing no phase flags. All 5 flags require--noise-adjust(per-phase output exists only there). - RowFilter
- Re-export of the comparison-policy types so downstream crates
using
ktstr::clias their public surface don’t need to reach into the internalktstr::statsmodule (which ispub(crate)— seelib.rs— and therefore not a stable public path). The policy is the only item instatsthat a CLI or external consumer constructs directly; every other item is internal plumbing reached viacli::compare_partitions. Typed-field filter set for narrowingGauntletRowsets in thecargo ktstr perf-deltapipeline. Every field isNone/ empty by default; populated fields are AND-combined ACROSS fields, with field-internal OR/AND semantics described per-field below. Applied viaapply_row_filtersincompare_partitionsbefore the rows reachcompare_rows_by. - Spinner
- Progress spinner for long-running CLI operations.
Enums§
- Dimension
- Re-exports of the dimensional-slicing types used by
cargo-ktstr’sBuildCompareFilters::build()plumbing. Thestatsmodule ispub(crate)(its tabular reporting types have no stable surface yet), but thecargo-ktstrbinary needsDimensionandderive_slicing_dimsto unit-test the filter-builder shape (theBuildCompareFilterstests assert which slicing dim a per-side filter pair derives). Same pattern asCpuCapabove: keep the canonical definitions instats(where the comparison plumbing consumes them internally) and re-export the slim slicing surface throughcliso the binaries reach them through the publicclimodule. One of the nine dimensions that compose aGauntletRow’s identity in the comparison pipeline:kernel,scheduler,topology,work-type,project-commit,kernel-commit,run-source,resolve-source,cpu-budget. Each maps to the correspondingRowFilterfield andGauntletRowfield; the dimension model letscompare_partitionsderive its slicing dims and dynamic pairing key without hardcoding the dimension list at every call site. Variant names match the CLI flag suffix (e.g.Dimension::ProjectCommit↔--project-commit,Dimension::RunSource↔--run-source,Dimension::CpuBudget↔--cpu-budget) so a reader can map from operator surface to internal enum without a translation table. - Kernel
Command - Shared
kernelsubcommand tree used by bothktstrandcargo ktstr. The two binaries embed this asktstr kernel <subcmd>/cargo ktstr kernel <subcmd>and dispatch identically; defining the variants once means a newkernelsubcommand (or a flag change) lands in both surfaces by construction.
Constants§
- CPU_
CAP_ HELP - Help text for the
--cpu-cap Nflag. Shared acrossktstr kernel build,cargo ktstr kernel build, andktstr shellso the operator-facing wording is identical regardless of entry point. - DIRTY_
TREE_ CACHE_ SKIP_ HINT - Emitted by
kernel buildwhen a local source tree has uncommitted index/worktree changes. Caching would key the built artifact on a git hash that does not describe the actual tree, so the build completes but the result is not archived. The hint names the two remediation paths (commit or stash) so an operator re-running the build after cleaning the tree benefits from the cache. Extracted from the call site so a wording drift between what’s printed and what’s documented elsewhere is impossible by construction; pinned bydirty_tree_cache_skip_hint_shapebelow. - DISK_
HELP - Help text for the
--disk <SIZE>shell flag, shared betweencargo ktstr shell(src/bin/cargo_ktstr/cli.rs) andktstr shell(src/bin/ktstr.rs) so a future tweak lands in one place. Mirrors thesuper::CPU_CAP_HELPpattern. - EMBEDDED_
KCONFIG - ktstr.kconfig embedded at compile time.
- EOL_
EXPLANATION - Explanation of the
(EOL)tag, shared between the text-output legend printed afterkernel listand thekernel list --helplong description (viaKERNEL_LIST_LONG_ABOUT, which embeds this exact byte sequence at its head through the sharedeol_explanation_literal!macro). One literal → one source of truth, so a wording drift cannot put the two surfaces out of sync.pubmatches the visibility of the siblingKERNEL_HELP_*constants so downstream consumers (e.g. documentation generators) can reference the exact text the CLI prints. - EXTRA_
KCONFIG_ HELP - Short clap-help for
--extra-kconfig. Mirrors theCPU_CAP_HELPpattern: terse first sentence on the clap surface, full rustdoc on theKernelCommand::Buildvariant for--helplong-about. - INCLUDE_
EOL_ HELP - Help text for the
--include-eolflag, shared by every command that expands aSTART..ENDkernel range (cargo ktstr test,coverage,llvm-cov,verifier,kernel list, andkernel buildwhen the--kernelvalue is a range). One const so the wording stays identical across every surface the flag appears on. - KERNEL_
HELP_ BUILD - Help text for
--kernelonkernel build(ktstrandcargo ktstr). UnlikeKERNEL_HELP_NO_RAW, this surface builds a kernel rather than resolving one for a test run: it is NOT repeatable (one kernel or one range per invocation), and a cache key is rejected (a cache key names an already-built entry, so there is nothing to build). A source-directory path auto-builds; a version / range auto-downloads; a git source is fetched and built. Omitting--kernelbuilds the latest stable release. - KERNEL_
HELP_ NO_ RAW - Help text for
--kernelin contexts that reject raw image files:cargo ktstr test,cargo ktstr coverage,cargo ktstr llvm-cov, andktstr shell. MatchesKernelResolvePolicy { accept_raw_image: false, .. }. - KERNEL_
HELP_ RAW_ OK - Help text for
--kernelin contexts that accept raw image files:cargo ktstr shell. MatchesKernelResolvePolicy { accept_raw_image: true, .. }. SeeKERNEL_HELP_NO_RAWfor the converse and the rationale for the asymmetry. - KERNEL_
LIST_ LONG_ ABOUT long_aboutforkernel list --help. EmbedsEOL_EXPLANATIONverbatim (viaeol_explanation_literal!) so the tag legend cannot drift between the post-table output and the help copy, then appends a plain-text rendering of the--jsonoutput schema so scripted consumers can discover the contract from the terminal without runningcargo doc. The schema wording mirrors the Rust-doc schema on super::kernel_list; keeping both surfaces terse makes a drift obvious on review. A plain-text (not JSON/markdown) rendering is used because clap applies no JSON/markdown formatting pass, so the schema reads as plain text. Clap does apply terminal-width wrapping, so the embedded EOL sentence re-flows to the width of the host terminal; the schema block’s explicit\nline breaks survive wrapping and preserve the column-aligned field table.- NON_
GIT_ TREE_ CACHE_ SKIP_ HINT - Hint shown in place of
DIRTY_TREE_CACHE_SKIP_HINTwhen the source tree is not a git repository at all.commit/stashare not actionable remediations in that case — the operator’s only path to caching is to put the source under git (or use a kernel-source fetch mode that produces a git-tracked tree). Pinned bynon_git_tree_cache_skip_hint_shapebelow so a wording drift is caught in unit tests. - STALE_
KCONFIG_ EXPLANATION - Explanation of the
(stale kconfig)tag. MirrorsUNTRACKED_KCONFIG_EXPLANATIONso the kconfig tag pair shares one shape — every kconfig-status legend in the informational trio (EOL / UNTRACKED / STALE) is now a const surfaced via a*_legend_if_anyhelper. Verbatim wording preserved from the prior inlineeprintln!inkernel_listso existing operators see no behavioural change. - UNTRACKED_
KCONFIG_ EXPLANATION - Explanation of the
(untracked kconfig)tag. Consumer-facing wording mirrorsEOL_EXPLANATION’s “one-const, one-surface” pattern so a doc-drift between the tag word and the legend cannot silently slip. MirrorsSTALE_KCONFIG_EXPLANATIONso the kconfig tag pair shares one shape.
Functions§
- append_
extra_ kconfig_ suffix - Append the
-xkc{extra_hash}segment to a cache key built around the bare baked-in suffix (...-kc{baked_hash}), bringing it to the two-segment shape produced bycrate::cache_key_suffix_with_extra. - auto_
download_ kernel - Auto-download, build, and cache the latest stable kernel.
- cache_
lookup - Look up a cache key, checking local first, then remote (if enabled).
- check_
kvm - Pre-flight check for /dev/kvm availability and permissions.
- check_
tools - Pre-flight check: verify that all required external tools are
present in
$PATHbefore starting work. Collects every missing tool into a single error so the user sees the full list at once. - compare_
partitions - Compare two filter-defined partitions of the sidecar pool and
report regressions across slicing dimensions. See
crate::stats::compare_partitionsfor the full contract. - compare_
partitions_ noise - Noise-adjusted variant of
compare_partitions: keeps every per-run row and gates a confident regression on the two sides being SEPARATED (a two-sided Welch t-test, or fully disjoint[min, max]bands) AND the mean delta being MATERIAL (the registrydefault_abs+default_reldual-gate), instead of a fixed single-run threshold. When the scenarios carry phases it also renders a per-phase spread + coverage block (render-only, honoringphase_opts; per-phase never affects the exit). Seecrate::stats::compare_partitions_noisefor the full contract. - derive_
slicing_ dims - Re-exports of the dimensional-slicing types used by
cargo-ktstr’sBuildCompareFilters::build()plumbing. Thestatsmodule ispub(crate)(its tabular reporting types have no stable surface yet), but thecargo-ktstrbinary needsDimensionandderive_slicing_dimsto unit-test the filter-builder shape (theBuildCompareFilterstests assert which slicing dim a per-side filter pair derives). Same pattern asCpuCapabove: keep the canonical definitions instats(where the comparison plumbing consumes them internally) and re-export the slim slicing surface throughcliso the binaries reach them through the publicclimodule. Derive the set of dimensions on whichfilter_aandfilter_bdiffer. These are the SLICING dimensions — dimensions on which the two sides select disjoint cohorts and therefore form the A/B contrast. The complement (every other dimension) is the PAIRING-key dimension set used bycompare_rowsto join A-side rows against B-side rows. - download_
and_ cache_ version - Download a specific kernel version, build it, and store in the cache. Returns the cache entry directory path (NOT the image path).
- embedded_
kconfig_ hash - Compute CRC32 of the embedded ktstr.kconfig fragment.
- expand_
kernel_ range - Expand a kernel-version range to the list of stable / longterm
releases that fall inside
[start, end]inclusive. - explain_
sidecar - Diagnose
Option-field absences for a run’s sidecars. Mirrorsshow_run_host’s shape (--run+ optional--dir, printable string return). See the original rustdoc on the public surface for the full JSON / text contract and exit-code policy. - format_
entry_ row - Format a human-readable table row for a cache entry.
- is_
render_ suppressed_ component - Re-export of the comparison-policy types so downstream crates
using
ktstr::clias their public surface don’t need to reach into the internalktstr::statsmodule (which ispub(crate)— seelib.rs— and therefore not a stable public path). The policy is the only item instatsthat a CLI or external consumer constructs directly; every other item is internal plumbing reached viacli::compare_partitions. True whennameis a Rate component suppressed from compare output (see the privateRENDER_SUPPRESSED_COMPONENTSlist). - kernel_
build_ pipeline - Post-acquisition kernel build pipeline.
- kernel_
clean - Remove cached kernels with optional keep-N and confirmation prompt.
- kernel_
list - List cached kernel images.
- kernel_
list_ range_ preview - Range-preview variant of
kernel_list. - list_
locks ktstr locksentry point. See module-level doc block above.- list_
metrics - Render the metric registry for
cargo ktstr stats list-metrics. - list_
runs - List test runs under
{CARGO_TARGET_DIR or "target"}/ktstr/. - list_
values - Render the distinct-value catalogue for the sidecar pool, for
cargo ktstr stats list-values. - make_
kernel_ with_ output - Build the kernel with output piped through the progress group.
- metric_
def - Re-export of the comparison-policy types so downstream crates
using
ktstr::clias their public surface don’t need to reach into the internalktstr::statsmodule (which ispub(crate)— seelib.rs— and therefore not a stable public path). The policy is the only item instatsthat a CLI or external consumer constructs directly; every other item is internal plumbing reached viacli::compare_partitions. Look up a metric definition by name. - new_
table - Build a borderless comfy-table with styling gated on
stdout_color. When stdout is not a TTY (CI, piped-to-file),force_no_ttysuppresses cell color escapes so a log or grep capture does not land raw\x1b[...sequences. The NOTHING preset skips box-drawing characters and keeps whitespace-padded columns, matching the previous hand-rolledformat!("{:<30}…")look while auto-measuring each column from actual cell contents. - new_
wrapped_ table - Variant of
new_tablethat opts into comfy-table’s terminal-width-aware [comfy_table::ContentArrangement::Dynamic] layout. Cells too wide for the available terminal width wrap inside the cell rather than pushing later columns past the edge, at the cost of taller rows. Used byctprof compare/ctprof showunder the--wrapflag; the existing fixed-columnnew_tablestays the default for every other caller (locks, verifier, stats) so their output stays byte-stable for shell-pipeline consumers. - parse_
disk_ arg - Parse the
--disk <SIZE>CLI argument into anOption<crate::vmm::disk_config::DiskConfig>.Noneinput returnsOk(None)(no disk attached); aSome(s)input runssthroughparse_disk_size_miband wraps the result in aDiskConfigwhose remaining fields fall through tocrate::vmm::disk_config::DiskConfig::default(raw filesystem, no throttle, read-write). Shared betweencargo ktstr shellandktstr shellso both bins parse identically; a malformed size surfaces here at CLI-argument time, never mid-VM-setup. - parse_
disk_ size_ mib - Parse a human-readable size string (e.g.
"256mib","10gib","1gib") into a count of mebibytes (MiB), rounded down. ReturnsErrwhen the suffix is unrecognized, the numeric portion fails to parse, the value is not a positive integer multiple of one MiB, or the result exceedsu32::MAXMiB (thecrate::vmm::disk_config::DiskConfig::capacity_mibcapacity). - parse_
topology_ string - Parse a comma-separated topology string into its four dimensions:
(numa_nodes, llcs, cores, threads). The canonical format is"numa_nodes,llcs,cores,threads"— the same shape accepted by thektstr shell --topologyandcargo ktstr shell --topologyflags. - print_
stats_ report - Read sidecar JSON files and return the gauntlet analysis report.
- read_
extra_ kconfig - Read a
--extra-kconfig PATHfile. ReturnsOk(content)on success orErr(message)with an actionable diagnostic naming--extra-kconfigand the user’s literal input path verbatim so a typo names the exact string they passed. - resolve_
cached_ kernel - Resolve a Version or CacheKey identifier to a cache entry directory.
- resolve_
git_ kernel - Resolve a
git+URL#tag=/#branch=/#sha=kernel spec to a cache-entry directory. - resolve_
include_ files - Resolve
--include-filesarguments into(archive_path, host_path)pairs. - resolve_
kernel_ dir - Resolve a kernel directory: auto-build from source tree.
- resolve_
kernel_ dir_ to_ entry - Resolve a source-tree path through the local-kernel cache,
returning a
KernelDirOutcomethat carries the boot-image directory, the cache-hit signal, and the dirty-tree flag. - resolve_
kernel_ image - Resolve a kernel identifier to a bootable image path.
- resolve_
kernel_ parallelism - Resolve the rayon pool width for
cargo ktstr’sresolve_kernel_setper-spec fan-out. - restore_
sigpipe_ default - Restore SIGPIPE to its default action (terminate the process)
so piping a ktstr binary’s output to a reader that closes
early (e.g.
... | head) does not panic insideprint!/println!. Rust’s startup code sets SIGPIPE toSIG_IGN, which turns the broken-pipe write into anio::Errorthatprint!escalates to a panic. SettingSIG_DFLrestores the POSIX “process terminates on SIGPIPE” convention that Unix CLI tools rely on. - run_
make - Run make in a kernel directory under a wall-clock timeout, with the parent’s stdout/stderr inherited.
- run_
make_ with_ output - Run make with merged stdout+stderr piped through the progress group.
- show_
host - Collect the current host context via
crate::host_context::collect_host_contextand render it as a human-readable multi-line report viacrate::host_context::HostContext::format_human. The output ends with a newline; callers print it verbatim. - show_
run_ host - Render the archived host context for the named run, resolved
against
dir(ortest_support::runs_root()whendirisNone). Loads sidecars under the run directory and returns theHostContext::format_humanof the first sidecar that has a populatedhostfield — every sidecar in a single run captures the same host, so first-wins is adequate. - show_
thresholds - Render the resolved, merged
Assertthresholds for the named test — the same merge chain evaluated at run time inrun_ktstr_test_inner:Assert::default_checks().merge(&entry.scheduler.assert).merge(&entry.assert). - stderr_
color - Whether stderr supports color (cached per process).
- stdout_
color - Whether stdout supports color (cached per process). Distinct from
stderr_colorbecausecargo ktstr perf-delta > report.txtpipes stdout to a file while leaving stderr on the TTY — gating stdout tables on the stderr TTY state would leave ANSI escapes in the file. Table-rendering code paths gate on this reading; diagnostic/status prints usestderr_color. - validate_
kernel_ config - Validate the output .config for critical options that the kconfig fragment requested but the kernel build system may have silently disabled (e.g. CONFIG_DEBUG_INFO_BTF requires pahole).