Skip to main content

rskit_bench/
execution.rs

1//! Benchmark execution planning with worker and observability integration.
2
3use rskit_observability::OperationContext;
4use rskit_worker::PoolConfig;
5
6/// Execution plan shared by benchmark runners and CI smoke checks.
7pub struct BenchExecutionPlan {
8    run_name: String,
9    concurrency: usize,
10    /// Observability context for benchmark-level spans and metrics.
11    pub operation: OperationContext,
12}
13
14impl BenchExecutionPlan {
15    /// Build a plan for a benchmark run.
16    #[must_use]
17    pub fn new(name: impl Into<String>, concurrency: usize) -> Self {
18        let name = name.into();
19        Self {
20            run_name: name.clone(),
21            concurrency: concurrency.max(1),
22            operation: OperationContext::new("rskit-bench", name, "benchmark", "system"),
23        }
24    }
25
26    /// Build a fresh worker pool config for one benchmark branch.
27    #[must_use]
28    pub fn pool_config_for(&self, branch: &str) -> PoolConfig {
29        PoolConfig::new(format!("bench-{}-{branch}", self.run_name)).with_size(self.concurrency)
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::BenchExecutionPlan;
36
37    #[test]
38    fn plan_uses_worker_pool_and_observability_context() {
39        let plan = BenchExecutionPlan::new("classification", 8);
40        let pool = plan.pool_config_for("baseline");
41        assert_eq!(pool.size, 8);
42        assert_eq!(pool.name, "bench-classification-baseline");
43        assert_eq!(plan.operation.service_name(), "rskit-bench");
44    }
45}