Skip to content

Commit f7b7e9c

Browse files
committed
Polish public API module boundaries
1 parent 2cc6d61 commit f7b7e9c

11 files changed

Lines changed: 241 additions & 60 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ Files are written under `target/stress/{suite}/`:
358358

359359
The JSON artifact contains tool version, run profile, environment, benchmark specs, raw samples, summaries, diagnostics, quality, and comparisons. Unknown environment fields are explicit `"unknown"` or `null`.
360360

361+
## Import Migration
362+
363+
Common benchmark files do not change: keep using root imports such as `stress`, `stress_main`, `black_box`, `StressContext`, `StressRunner`, `StressRunnerConfig`, `StressRunnerOptions`, and `RunProfile`.
364+
365+
Advanced imports moved out of the crate root. Result and schema types are under `cntryl_stress::artifact`, reporters and console formatting helpers are under `cntryl_stress::reporting`, and run gate helpers are under `cntryl_stress::runner`.
366+
361367
## Programmatic Runner
362368

363369
```rust
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ impl StressRun {
942942

943943
/// Summarize one benchmark from raw samples.
944944
#[must_use]
945-
pub fn summarize_benchmark(spec: &BenchmarkSpec, samples: &[Sample]) -> BenchmarkSummary {
945+
pub(crate) fn summarize_benchmark(spec: &BenchmarkSpec, samples: &[Sample]) -> BenchmarkSummary {
946946
let measured: Vec<&Sample> = samples
947947
.iter()
948948
.filter(|sample| sample.benchmark_id == spec.id && sample.phase == SamplePhase::Measured)
@@ -1034,7 +1034,7 @@ pub fn summarize_benchmark(spec: &BenchmarkSpec, samples: &[Sample]) -> Benchmar
10341034

10351035
/// Compare current summaries to baseline summaries.
10361036
#[must_use]
1037-
pub fn compare_summaries(
1037+
pub(crate) fn compare_summaries(
10381038
current: &[BenchmarkSummary],
10391039
baseline: &[BenchmarkSummary],
10401040
threshold: f64,
@@ -1061,7 +1061,7 @@ pub fn compare_summaries(
10611061
}
10621062

10631063
/// Add regression diagnostics to summaries after baseline comparison.
1064-
pub fn attach_regression_diagnostics(
1064+
pub(crate) fn attach_regression_diagnostics(
10651065
summaries: &mut [BenchmarkSummary],
10661066
comparisons: &[ComparisonResult],
10671067
) {

core/src/bin/cargo-stress.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
3535
use anyhow::{bail, Context, Result};
3636
use clap::{Parser, Subcommand};
37-
use cntryl_stress::{format_console_runs, StressRun};
37+
use cntryl_stress::{artifact::StressRun, reporting::format_console_runs};
3838
use std::ffi::OsStr;
3939
use std::fs;
4040
use std::path::{Path, PathBuf};
@@ -891,7 +891,7 @@ fn report_child_failures(results: &[StressRunResult]) {
891891
#[cfg(test)]
892892
mod tests {
893893
use super::*;
894-
use cntryl_stress::{
894+
use cntryl_stress::artifact::{
895895
BenchmarkBudgets, BenchmarkMode, BenchmarkSpec, BenchmarkSummary, CorrectnessCounters,
896896
CorrectnessSummary, EnvironmentInfo, MeasurementIntent, PrimaryMetric, ProfileConfig,
897897
QualityClass, RunProfile, Sample, SamplePhase, SummaryStats, SCHEMA_VERSION,

core/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Configuration and profile resolution for stress runs.
22
3-
use crate::result::{
3+
use crate::artifact::{
44
BenchmarkMode, BenchmarkModeKind, ProfileConfig, QualityClass, RunProfile, MAX_TIER,
55
};
66
use std::collections::HashMap;

core/src/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Benchmark context for named measurements, workload facts, and correctness counters.
22
33
use crate::allocation;
4-
use crate::result::{BenchmarkMode, CorrectnessCounters, MeasurementIntent};
4+
use crate::artifact::{BenchmarkMode, CorrectnessCounters, MeasurementIntent};
55
use std::collections::BTreeMap;
66
use std::future::Future;
77
use std::time::{Duration, Instant};
@@ -44,11 +44,11 @@ pub(crate) struct MeasurementOverrides {
4444
}
4545

4646
impl MeasurementOverrides {
47-
pub fn target_for_phase(self, phase: crate::result::SamplePhase, default: usize) -> usize {
47+
pub fn target_for_phase(self, phase: crate::artifact::SamplePhase, default: usize) -> usize {
4848
match phase {
49-
crate::result::SamplePhase::Warmup => self.warmup_samples.unwrap_or(default),
50-
crate::result::SamplePhase::Measured => self.samples.unwrap_or(default),
51-
crate::result::SamplePhase::Cooldown => self.cooldown_samples.unwrap_or(default),
49+
crate::artifact::SamplePhase::Warmup => self.warmup_samples.unwrap_or(default),
50+
crate::artifact::SamplePhase::Measured => self.samples.unwrap_or(default),
51+
crate::artifact::SamplePhase::Cooldown => self.cooldown_samples.unwrap_or(default),
5252
}
5353
}
5454
}

core/src/harness.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Harness for auto-discovered stress benchmarks.
22
3+
use crate::artifact::{BenchmarkBudgets, BenchmarkModeKind, BenchmarkSpec, RunProfile};
34
use crate::config::{parse_bool_env, StressRunnerConfig};
4-
use crate::result::{BenchmarkBudgets, BenchmarkModeKind, BenchmarkSpec, RunProfile};
55
use crate::runner::{evaluate_run_gate, RunGate, StressRunner};
66
use crate::StressContext;
77
use std::collections::BTreeMap;
@@ -305,11 +305,13 @@ impl StressRunnerOptions {
305305
}
306306

307307
/// Run all registered benchmarks with default options.
308+
#[allow(dead_code)]
308309
pub fn run_registered_benchmarks() {
309310
run_with_options(StressRunnerOptions::new());
310311
}
311312

312313
/// Run all registered benchmarks with programmatic options.
314+
#[allow(dead_code)]
313315
pub fn run_with_options(options: StressRunnerOptions) {
314316
let args = StressBinaryArgs {
315317
workload: options.workload,
@@ -465,7 +467,7 @@ fn run_with_resolved_config(resolved: ResolvedStressConfig) {
465467
name: display_name,
466468
tier: entry.tier,
467469
mode: config_for_specs.mode_for_kind(entry.mode),
468-
intent: crate::result::MeasurementIntent::General,
470+
intent: crate::artifact::MeasurementIntent::General,
469471
budgets: entry.budgets,
470472
parameters: BTreeMap::new(),
471473
metadata,
@@ -694,6 +696,7 @@ pub fn list_benchmarks() -> Vec<&'static str> {
694696

695697
/// Get the number of registered benchmarks.
696698
#[must_use]
699+
#[allow(dead_code)]
697700
pub fn benchmark_count() -> usize {
698701
STRESS_BENCHMARKS.len()
699702
}

core/src/lib.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
//! ```
4646
4747
mod allocation;
48+
pub mod artifact;
4849
mod config;
49-
mod context;
50+
pub mod context;
5051
mod harness;
51-
mod report;
52-
mod result;
53-
mod runner;
52+
pub mod reporting;
53+
pub mod runner;
5454

5555
#[cfg(test)]
5656
#[global_allocator]
@@ -64,37 +64,22 @@ static CNTRYL_STRESS_TEST_ALLOCATOR: allocation::StressAllocator =
6464
static CNTRYL_STRESS_TEST_ALLOCATOR_INSTALLATION: fn() =
6565
allocation::stress_allocator_installed_marker;
6666

67-
pub use allocation::StressAllocator;
67+
pub use artifact::RunProfile;
6868
pub use config::StressRunnerConfig;
69-
pub use context::{CorrectnessRecorder, StressContext};
70-
pub use report::{
71-
format_console_run, format_console_runs, ConsoleReporter, GitHubActionsReporter, JsonReporter,
72-
MultiReporter, Reporter,
73-
};
74-
pub use result::{
75-
BenchmarkBudgets, BenchmarkDiagnostic, BenchmarkMode, BenchmarkModeKind, BenchmarkSpec,
76-
BenchmarkSummary, BudgetResult, ComparisonClass, ComparisonResult, ConfidenceInterval,
77-
CorrectnessCounters, CorrectnessSummary, DiagnosticSeverity, EnvironmentInfo,
78-
MeasurementIntent, PrimaryMetric, ProfileConfig, QualityClass, RunProfile, Sample, SamplePhase,
79-
StressRun, SummaryStats, MAX_TIER, SCHEMA_VERSION,
80-
};
81-
pub use runner::{evaluate_run_gate, RunGate, StressRunner};
69+
pub use context::StressContext;
70+
pub use runner::StressRunner;
8271
pub use std::hint::black_box;
8372

8473
pub use cntryl_stress_macros::{stress, stress_main};
85-
pub use harness::stress_binary_main;
86-
pub use harness::{benchmark_count, list_benchmarks};
87-
pub use harness::{
88-
run_from_env_and_args, run_registered_benchmarks, run_with_options, StressRunnerOptions,
89-
};
74+
pub use harness::StressRunnerOptions;
9075

9176
/// Private module for macro internals.
9277
#[doc(hidden)]
9378
pub mod __private {
9479
pub use crate::allocation::{
95-
stress_allocator_installed_marker, STRESS_ALLOCATOR_INSTALLATIONS,
80+
stress_allocator_installed_marker, StressAllocator, STRESS_ALLOCATOR_INSTALLATIONS,
9681
};
97-
pub use crate::harness::{linkme, BenchmarkEntry, STRESS_BENCHMARKS};
82+
pub use crate::harness::{linkme, stress_binary_main, BenchmarkEntry, STRESS_BENCHMARKS};
9883

9984
/// Run a future to completion without requiring a runtime dependency.
10085
pub fn block_on<F: std::future::Future>(future: F) -> F::Output {
@@ -132,7 +117,8 @@ pub mod __private {
132117
macro_rules! stress_allocator {
133118
() => {
134119
#[global_allocator]
135-
static CNTRYL_STRESS_ALLOCATOR: $crate::StressAllocator = $crate::StressAllocator::new();
120+
static CNTRYL_STRESS_ALLOCATOR: $crate::__private::StressAllocator =
121+
$crate::__private::StressAllocator::new();
136122

137123
#[allow(non_upper_case_globals)]
138124
#[::cntryl_stress::__private::linkme::distributed_slice(
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Pluggable reporters for current stress artifacts.
22
3-
use crate::config::StressRunnerConfig;
4-
use crate::result::{
3+
use crate::artifact::{
54
BenchmarkDiagnostic, BenchmarkSummary, ComparisonClass, ComparisonResult, CorrectnessSummary,
65
PrimaryMetric, QualityClass, StressRun, SummaryStats,
76
};
7+
use crate::config::StressRunnerConfig;
88
use std::collections::{BTreeMap, BTreeSet};
99
use std::fmt::Write as FmtWrite;
1010
use std::io::Write;
@@ -1282,7 +1282,7 @@ fn budget_note(summary: &BenchmarkSummary) -> String {
12821282
.join(", ")
12831283
}
12841284

1285-
fn allocation_budget_unavailable(result: &crate::result::BudgetResult) -> bool {
1285+
fn allocation_budget_unavailable(result: &crate::artifact::BudgetResult) -> bool {
12861286
matches!(
12871287
result.metric.as_str(),
12881288
"max_allocs_per_op" | "max_bytes_per_op"
@@ -1759,7 +1759,7 @@ fn format_duration_ns(nanos: u128) -> String {
17591759
#[cfg(test)]
17601760
mod tests {
17611761
use super::*;
1762-
use crate::result::{
1762+
use crate::artifact::{
17631763
BenchmarkBudgets, BenchmarkMode, BenchmarkSpec, BudgetResult, ComparisonResult,
17641764
CorrectnessCounters, CorrectnessSummary, DiagnosticSeverity, EnvironmentInfo,
17651765
MeasurementIntent, Sample, SamplePhase, SummaryStats, SCHEMA_VERSION,
@@ -1804,7 +1804,7 @@ mod tests {
18041804

18051805
fn run_with_summaries(summaries: Vec<BenchmarkSummary>) -> StressRun {
18061806
let profile_config =
1807-
crate::config::StressRunnerConfig::for_profile(crate::result::RunProfile::Release)
1807+
crate::config::StressRunnerConfig::for_profile(crate::artifact::RunProfile::Release)
18081808
.profile_config();
18091809
StressRun {
18101810
schema_version: SCHEMA_VERSION.to_string(),

core/src/runner.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Stress runner that records raw samples and derives current artifacts.
22
3-
use crate::config::StressRunnerConfig;
4-
use crate::context::{MeasurementRecord, StressContext};
5-
use crate::report::{ConsoleReporter, JsonReporter, JsonStdoutReporter, Reporter};
6-
use crate::result::{
3+
use crate::artifact::{
74
attach_regression_diagnostics, compare_summaries, summarize_benchmark, BenchmarkModeKind,
85
BenchmarkSpec, ComparisonClass, EnvironmentInfo, MeasurementIntent, Sample, SamplePhase,
96
StressRun, MAX_TIER, SCHEMA_VERSION,
107
};
8+
use crate::config::StressRunnerConfig;
9+
use crate::context::{MeasurementRecord, StressContext};
10+
use crate::reporting::{ConsoleReporter, JsonReporter, JsonStdoutReporter, Reporter};
1111
use std::collections::BTreeMap;
1212
use std::path::Path;
1313
use std::process::Command;
@@ -19,7 +19,7 @@ pub struct StressRunner {
1919
config: StressRunnerConfig,
2020
benchmark_specs: Vec<BenchmarkSpec>,
2121
samples: Vec<Sample>,
22-
summaries: Vec<crate::result::BenchmarkSummary>,
22+
summaries: Vec<crate::artifact::BenchmarkSummary>,
2323
suite_start: Instant,
2424
reporters: Vec<Box<dyn Reporter>>,
2525
metadata: BTreeMap<String, String>,
@@ -129,7 +129,7 @@ impl StressRunner {
129129
.config
130130
.mode_for_kind(BenchmarkModeKind::FixedOperations),
131131
intent: MeasurementIntent::General,
132-
budgets: crate::result::BenchmarkBudgets::default(),
132+
budgets: crate::artifact::BenchmarkBudgets::default(),
133133
parameters: BTreeMap::new(),
134134
metadata: BTreeMap::new(),
135135
};
@@ -229,7 +229,7 @@ impl StressRunner {
229229
Ok(self.finish_inner(comparisons))
230230
}
231231

232-
fn finish_inner(mut self, comparisons: Vec<crate::result::ComparisonResult>) -> StressRun {
232+
fn finish_inner(mut self, comparisons: Vec<crate::artifact::ComparisonResult>) -> StressRun {
233233
attach_regression_diagnostics(&mut self.summaries, &comparisons);
234234
let run = StressRun {
235235
schema_version: SCHEMA_VERSION.to_string(),
@@ -580,7 +580,7 @@ pub fn evaluate_run_gate(run: &StressRun) -> RunGate {
580580
#[cfg(test)]
581581
mod tests {
582582
use super::*;
583-
use crate::result::{
583+
use crate::artifact::{
584584
BenchmarkBudgets, BenchmarkMode, BenchmarkModeKind, CorrectnessCounters, PrimaryMetric,
585585
RunProfile,
586586
};
@@ -644,7 +644,7 @@ mod tests {
644644
operations_per_sample: 1,
645645
},
646646
intent: MeasurementIntent::General,
647-
budgets: crate::result::BenchmarkBudgets::default(),
647+
budgets: crate::artifact::BenchmarkBudgets::default(),
648648
parameters: BTreeMap::new(),
649649
metadata: BTreeMap::new(),
650650
};
@@ -670,7 +670,7 @@ mod tests {
670670
operations_per_sample: 1,
671671
},
672672
intent: MeasurementIntent::General,
673-
budgets: crate::result::BenchmarkBudgets::default(),
673+
budgets: crate::artifact::BenchmarkBudgets::default(),
674674
parameters: BTreeMap::new(),
675675
metadata: BTreeMap::new(),
676676
};
@@ -739,7 +739,7 @@ mod tests {
739739
sample_duration: Duration::from_millis(1),
740740
},
741741
intent: MeasurementIntent::General,
742-
budgets: crate::result::BenchmarkBudgets::default(),
742+
budgets: crate::artifact::BenchmarkBudgets::default(),
743743
parameters: BTreeMap::new(),
744744
metadata: BTreeMap::new(),
745745
};

0 commit comments

Comments
 (0)