Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/openshell-sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ repository.workspace = true
name = "openshell-sandbox"
path = "src/main.rs"

[[bin]]
name = "openshell-seccomp-perf"
path = "src/bin/seccomp-perf.rs"
required-features = ["perf-harness"]

[features]
perf-harness = []

Expand Down
113 changes: 113 additions & 0 deletions crates/openshell-sandbox/src/bin/seccomp-perf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//! Microbenchmark entry point for the production seccomp network broker.

#[cfg(target_os = "linux")]
use std::net::SocketAddr;

#[cfg(target_os = "linux")]
use clap::builder::{PossibleValue, PossibleValuesParser};
#[cfg(target_os = "linux")]
use clap::{Parser, Subcommand, ValueEnum as _};
#[cfg(target_os = "linux")]
use openshell_sandbox::perf::{BenchmarkOptions, Layer, Protocol};

#[cfg(target_os = "linux")]
#[derive(Debug, Parser)]
#[command(
about = "Measure native and seccomp-filtered socket performance",
long_about = "Measure native and seccomp-filtered TCP socket performance."
)]
struct Cli {
/// Benchmark layer: native, filtered, or all.
#[arg(long, default_value = "all", value_parser = ["native", "filtered", "all"])]
layer: String,
/// Implemented protocol to benchmark, or all.
#[arg(long, default_value = "all", value_parser = protocol_value_parser())]
protocol: String,
#[arg(long, default_value_t = 10_000)]
iterations: u64,
#[arg(long, default_value_t = 1_000)]
warmup: u64,
#[arg(long, default_value_t = 1)]
concurrency: usize,
#[arg(long, default_value_t = 64)]
payload_bytes: usize,
#[command(subcommand)]
command: Option<Command>,
}

#[cfg(target_os = "linux")]
fn protocol_value_parser() -> PossibleValuesParser {
let mut values = vec![PossibleValue::new("all")];
values.extend(
Protocol::value_variants()
.iter()
.filter_map(clap::ValueEnum::to_possible_value),
);
PossibleValuesParser::new(values)
}

#[cfg(target_os = "linux")]
#[derive(Debug, Subcommand)]
enum Command {
#[command(hide = true)]
Worker {
#[arg(long)]
protocol: Protocol,
#[arg(long)]
target: SocketAddr,
#[arg(long)]
iterations: u64,
#[arg(long)]
warmup: u64,
#[arg(long)]
concurrency: usize,
#[arg(long)]
payload_bytes: usize,
},
}

#[cfg(target_os = "linux")]
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
if let Some(Command::Worker {
protocol,
target,
iterations,
warmup,
concurrency,
payload_bytes,
}) = cli.command
{
let report = openshell_sandbox::perf::run_worker(
protocol,
target,
iterations,
warmup,
concurrency,
payload_bytes,
)?;
println!("{}", serde_json::to_string(&report)?);
return Ok(());
}

let options = BenchmarkOptions {
layers: Layer::selection(&cli.layer)?,
protocols: Protocol::selection(&cli.protocol)?,
iterations: cli.iterations,
warmup: cli.warmup,
concurrency: cli.concurrency,
payload_bytes: cli.payload_bytes,
};
for report in openshell_sandbox::perf::run(options)? {
println!("{}", serde_json::to_string(&report)?);
}
Ok(())
}

#[cfg(not(target_os = "linux"))]
fn main() -> anyhow::Result<()> {
anyhow::bail!("the seccomp performance harness requires Linux")
}
2 changes: 2 additions & 0 deletions crates/openshell-sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub mod main_session;
pub mod managed_children;
#[cfg(target_os = "linux")]
mod network_broker;
#[cfg(all(target_os = "linux", feature = "perf-harness"))]
pub mod perf;
#[cfg(unix)]
pub mod process;
mod pty;
Expand Down
Loading
Loading