From b5370af5e902249d4022c68d50af5a97eae5cee9 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Tue, 1 Nov 2022 18:34:59 +0800 Subject: [PATCH] test: add mem-prof feature to test memory --- crates/loro-core/Cargo.toml | 1 + crates/loro-core/examples/mem.rs | 5 +++-- crates/loro-core/justfile | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/loro-core/Cargo.toml b/crates/loro-core/Cargo.toml index 77377011..e99e5d82 100644 --- a/crates/loro-core/Cargo.toml +++ b/crates/loro-core/Cargo.toml @@ -60,6 +60,7 @@ doctest = false [features] wasm = ["wasm-bindgen", "js-sys"] parallel = [] +mem-prof = [] # whether to use list slice instead of raw str in text container fuzzing = ["crdt-list/fuzzing", "rand", "arbitrary", "tabled"] proptest = ["fuzzing"] diff --git a/crates/loro-core/examples/mem.rs b/crates/loro-core/examples/mem.rs index 366b88ef..df4bf640 100644 --- a/crates/loro-core/examples/mem.rs +++ b/crates/loro-core/examples/mem.rs @@ -2,10 +2,10 @@ // #[global_allocator] // static GLOBAL: Jemalloc = Jemalloc; +#[cfg(feature = "mem-prof")] #[global_allocator] static ALLOC: dhat::Alloc = dhat::Alloc; -use tikv_jemalloc_ctl::epoch; const RAW_DATA: &[u8; 901823] = include_bytes!("../benches/automerge-paper.json.gz"); use std::{io::Read, time::Instant}; @@ -22,8 +22,8 @@ pub fn main() { let json: Value = serde_json::from_str(&s).unwrap(); drop(s); let txns = json.as_object().unwrap().get("txns"); - let e = epoch::mib().unwrap(); let start = Instant::now(); + #[cfg(feature = "mem-prof")] let profiler = dhat::Profiler::builder().trim_backtraces(None).build(); let mut loro = LoroCore::default(); let mut text = loro.get_or_create_root_text("text").unwrap(); @@ -53,6 +53,7 @@ pub fn main() { drop(d); drop(text); loro.debug_inspect(); + #[cfg(feature = "mem-prof")] drop(profiler); // e.advance().unwrap(); // let new_new_heap = alloc_stats.read().unwrap(); diff --git a/crates/loro-core/justfile b/crates/loro-core/justfile index c6062c02..0bb9d3d1 100644 --- a/crates/loro-core/justfile +++ b/crates/loro-core/justfile @@ -31,4 +31,4 @@ bench *FLAGS: cargo bench --features fuzzing {{FLAGS}} mem: - cargo run --example mem -r --features fuzzing + cargo run --example mem -r --features=fuzzing,mem-prof