Skip to content

Commit

Permalink
Fix lean
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyuzhao committed Jun 27, 2024
1 parent c1444f8 commit d989378
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ publish = false
[dependencies]
harness = "0.0.5"
num_cpus.workspace = true
once_cell = "1.19.0"

[[bench]]
name = "cfrac"
Expand Down
81 changes: 58 additions & 23 deletions bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
};

use harness::Bencher;
use once_cell::sync::Lazy;

const LD_PRELOAD: &str = if cfg!(target_os = "linux") {
"LD_PRELOAD"
Expand Down Expand Up @@ -40,22 +41,33 @@ pub struct Bench {
server: Option<Child>,
}

const LOCAL_DEV_DIR: &str = "./mimalloc-bench/extern";
static LOCAL_DEV_DIR: Lazy<String> = Lazy::new(|| {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("mimalloc-bench")
.join("extern")
.canonicalize()
.unwrap()
.to_str()
.unwrap()
.to_owned()
});

impl Bench {
pub fn new(name: &str) -> Self {
let malloc = std::env::var("MALLOC").unwrap();
let is_external = std::env::var("IS_MALLOCKIT").unwrap() == "0";
if is_external {
println!("[{name}] malloc: {malloc} (external)");
} else {
println!("[{name}] malloc: {malloc} (mallockit)");
}
let kind = match (malloc.as_str(), is_external) {
("sys", _) => "system",
(_, true) => "external",
_ => "mallockit",
};
Self::build_mallockit();
let malloc_path = Self::get_malloc_lib_path(&malloc, is_external);
if malloc != "sys" && !PathBuf::from(&malloc_path).exists() {
panic!("Malloc dylib does not exist: {malloc_path}");
}
println!("[{name}] malloc: {malloc} ({kind}) {malloc_path}");

Self {
name: name.to_string(),
alloc_name: malloc.clone(),
Expand Down Expand Up @@ -89,11 +101,12 @@ impl Bench {
}

fn get_binary_path(name: &str) -> String {
let local_dev_dir = LOCAL_DEV_DIR.as_str();
match name {
"lean" => "../bin/lean".to_owned(),
"lua" => "make".to_owned(),
"redis" => format!("{LOCAL_DEV_DIR}/redis-6.2.7/src/redis-benchmark"),
"rocksdb" => format!("{LOCAL_DEV_DIR}/rocksdb-8.1.1/db_bench"),
"redis" => format!("{local_dev_dir}/redis-6.2.7/src/redis-benchmark"),
"rocksdb" => format!("{local_dev_dir}/rocksdb-8.1.1/db_bench"),
_ => format!("./mimalloc-bench/out/bench/{name}"),
}
}
Expand All @@ -106,22 +119,26 @@ impl Bench {
.join("release");
return path
.join(format!("lib{name}.{DYLIB_EXT}"))
.canonicalize()
.unwrap()
.to_str()
.unwrap()
.to_owned();
}
let local_dev_dir = LOCAL_DEV_DIR.as_str();
match name {
"hd" => format!("{LOCAL_DEV_DIR}/hd/src/libhoard.{DYLIB_EXT}"),
"je" => format!("{LOCAL_DEV_DIR}/je/lib/libjemalloc.{DYLIB_EXT}"),
"tc" => format!("{LOCAL_DEV_DIR}/tc/.libs/libtcmalloc_minimal.{DYLIB_EXT}"),
"mi" => format!("{LOCAL_DEV_DIR}/mi/out/release/libmimalloc.{DYLIB_EXT}"),
"mi2" => format!("{LOCAL_DEV_DIR}/mi2/out/release/libmimalloc.{DYLIB_EXT}"),
"hd" => format!("{local_dev_dir}/hd/src/libhoard.{DYLIB_EXT}"),
"je" => format!("{local_dev_dir}/je/lib/libjemalloc.{DYLIB_EXT}"),
"tc" => format!("{local_dev_dir}/tc/.libs/libtcmalloc_minimal.{DYLIB_EXT}"),
"mi" => format!("{local_dev_dir}/mi/out/release/libmimalloc.{DYLIB_EXT}"),
"mi2" => format!("{local_dev_dir}/mi2/out/release/libmimalloc.{DYLIB_EXT}"),
"sys" => "1".to_owned(),
_ => panic!("Unknown malloc: {name}"),
}
}

fn init_args_and_stdin(&mut self) {
let local_dev_dir = LOCAL_DEV_DIR.as_str();
let procs = num_cpus::get().to_string();
match self.name.as_str() {
"barnes" => {
Expand Down Expand Up @@ -151,10 +168,10 @@ impl Bench {
let procs = usize::min(num_cpus::get(), 8).to_string();
self.cmd
.args(["--make", "-j", &procs])
.current_dir(format!("{LOCAL_DEV_DIR}/lean/library"));
.current_dir(format!("{local_dev_dir}/lean/library"));
}
"lua" => {
self.cmd.current_dir(format!("{LOCAL_DEV_DIR}/lua"));
self.cmd.current_dir(format!("{local_dev_dir}/lua"));
}
"redis" => {
self.cmd.args([
Expand All @@ -174,26 +191,43 @@ impl Bench {
}

fn prepare(&mut self) {
let local_dev_dir = LOCAL_DEV_DIR.as_str();
match self.name.as_str() {
"lean" => {
let status = Command::new("make")
.arg("clean-olean")
.current_dir(format!("{LOCAL_DEV_DIR}/lean/out/release"))
.status()
.unwrap();
let makefile = PathBuf::from(format!("{local_dev_dir}/lean/out/release/Makefile"));
let content = std::fs::read_to_string(makefile).unwrap();
let status = if content.contains("/root/mimalloc-bench/extern/lean/src") {
Command::new("docker")
.args([
"compose",
"run",
"mimalloc-bench",
"/bin/bash",
"-c",
"cd /root/mimalloc-bench/extern/lean/out/release && make clean-olean",
])
.status()
.unwrap()
} else {
Command::new("make")
.arg("clean-olean")
.current_dir(format!("{local_dev_dir}/lean/out/release"))
.status()
.unwrap()
};
assert!(status.success());
}
"lua" => {
let status = Command::new("make")
.arg("clean")
.current_dir(format!("{LOCAL_DEV_DIR}/lua"))
.current_dir(format!("{local_dev_dir}/lua"))
.status()
.unwrap();
assert!(status.success());
}
"redis" => {
// start the background server
let mut cmd = Command::new(format!("{LOCAL_DEV_DIR}/redis-6.2.7/src/redis-server"));
let mut cmd = Command::new(format!("{local_dev_dir}/redis-6.2.7/src/redis-server"));
Self::use_malloc(&mut cmd, &self.alloc_name, &self.alloc_path);
self.server = Some(cmd.spawn().unwrap());
}
Expand All @@ -210,8 +244,9 @@ impl Bench {
}

pub fn run(&mut self) {
let local_dev_dir = LOCAL_DEV_DIR.as_str();
if self.name == "redis" {
let redis_dir = format!("{LOCAL_DEV_DIR}/redis-6.2.7/src");
let redis_dir = format!("{local_dev_dir}/redis-6.2.7/src");
std::thread::sleep(std::time::Duration::from_secs(1));
let status = Command::new(format!("{redis_dir}/redis-cli"))
.arg("flushall")
Expand Down

0 comments on commit d989378

Please sign in to comment.