Skip to content

Commit

Permalink
first cut at benchmarking with Criterion. Will expand the set of benc…
Browse files Browse the repository at this point in the history
…hmarks after this is merged
  • Loading branch information
JustinCappos committed May 5, 2024
1 parent a938eea commit f4bf0d6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ edition = "2018"

[lib]
path = "src/lib.rs"
crate-type = ["cdylib"]
# cdylib is a dynamically linkable library, which is great for linking into
# C programs and similar. rlib is needed for the criterion benchmarking libary
# and creates one of Rust's static libraries. We are currently not generating
# dylib files which are Rust's internal (non-stable) ABI.
# Source: https://users.rust-lang.org/t/what-is-the-difference-between-dylib-and-cdylib/28847/3
crate-type = ["cdylib","rlib"]
test = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -19,6 +24,14 @@ ringbuf = "0.2.6"
dashmap = { version = "5.1", features=["serde"] }
parking_lot = "0.12"

[dev-dependencies]
criterion = { version = "0.3", features = ["html_reports"]}

[[bench]]
name = "basic_rustposix_benchmark"
path = "benches/rustposix-criterion.rs"
harness= false

[[bin]]
name = "lind_fs_utils"
path = "src/tools/fs_utils.rs"
70 changes: 70 additions & 0 deletions benches/rustposix-criterion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};

use rustposix::safeposix::cage::*;
use rustposix::interface;

// This is just a dummy benchmark to see if there is a problem with the
// benchmarker. We can remove this once things are well setup and tested.
fn fibonacci(n: u64) -> u64 {
match n {
0 => 1,
1 => 1,
n => fibonacci(n-1) + fibonacci(n-2),
}
}


fn get_dummy_cage() -> Cage {

// I chose random numbers for values here, so if a value is returned, you
// know which call was made by the result.
let cageobj = Cage {
cageid: 17,
cwd: interface::RustLock::new(interface::RustRfc::new(interface::RustPathBuf::from("/"))),
parent: 15,
filedescriptortable: Vec::new(),
cancelstatus: interface::RustAtomicBool::new(false),
getgid: interface::RustAtomicI32::new(7),
getuid: interface::RustAtomicI32::new(8),
getegid: interface::RustAtomicI32::new(9),
geteuid: interface::RustAtomicI32::new(10),
rev_shm: interface::Mutex::new(vec!()),
mutex_table: interface::RustLock::new(vec!()),
cv_table: interface::RustLock::new(vec!()),
sem_table: interface::RustHashMap::new(),
thread_table: interface::RustHashMap::new(),
signalhandler: interface::RustHashMap::new(),
sigset: interface::RustHashMap::new(),
pendingsigset: interface::RustHashMap::new(),
main_threadid: interface::RustAtomicU64::new(0),
interval_timer: interface::IntervalTimer::new(20)

};
return cageobj;
}


pub fn basic_rustposix_benchmark(c: &mut Criterion) {

// First, just do a basic benchmark to show the runner works...
c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20))));
let a = get_dummy_cage();

// Now, let's have a combined benchmark of all of the get*id* system calls
// in RustPOSIX... I'm not running these separately, because they should
// not vary too much.
c.bench_function("get*ids", |b| b.iter(||
{
a.getpid_syscall();
a.getppid_syscall();
a.getgid_syscall();
a.getegid_syscall();
a.getuid_syscall();
a.geteuid_syscall();
}
));
}

criterion_group!(benches, basic_rustposix_benchmark);
criterion_main!(benches);

6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#![feature(thread_local)]
#![allow(unused_imports)]

mod interface;
mod safeposix;
// interface and safeposix are public because otherwise there isn't a great
// way to 'use' them for benchmarking.
pub mod interface;
pub mod safeposix;
mod tests;
mod lib_fs_utils;

0 comments on commit f4bf0d6

Please sign in to comment.