fix(xtask): Fix dhat build
MODIFY
xtask/bench/Cargo.toml
xtask/bench/Cargo.toml
@@ -23,12 +23,12 @@ url = "2.2.2"
itertools = "0.10.3"
ansi_rgb = "0.2.0"
-[target.'cfg(target_os = "windows")'.dependencies]
-mimalloc = "0.1.29"
-
# dhat-on
dhat = { version = "0.3.0", optional = true }
humansize = {version = "1.1.1", optional = true }
+[target.'cfg(target_os = "windows")'.dependencies]
+mimalloc = "0.1.29"
+
[features]
-dhat-on = ["dhat", "humansize"]
+dhat-heap = ["dhat", "humansize"]

MODIFY
xtask/bench/README.md
xtask/bench/README.md
@@ -53,5 +53,5 @@ critcmp main pr # (cargo install critcmp)
## Heap Profiling using `dhat`
```bash
-cargo run -p xtask_bench --features dhat-on --release
+cargo run -p xtask_bench --features dhat-heap --release-with-debug
```

MODIFY
xtask/bench/src/features/formatter.rs
xtask/bench/src/features/formatter.rs
-#[cfg(feature = "dhat-on")]
+#[cfg(feature = "dhat-heap")]
use crate::features::print_diff;
use crate::BenchmarkSummary;
use rome_formatter::Printed;
@@ -29,27 +29,27 @@ pub fn benchmark_format_lib(
}
pub fn run_format(root: &JsSyntaxNode, source_type: SourceType) -> Printed {
- #[cfg(feature = "dhat-on")]
+ #[cfg(feature = "dhat-heap")]
let stats = {
println!("Start");
- dhat::get_stats().unwrap()
+ dhat::HeapStats::get()
};
let formatted = format_node(JsFormatOptions::new(source_type), root).unwrap();
- #[cfg(feature = "dhat-on")]
+ #[cfg(feature = "dhat-heap")]
let stats = {
println!("Formatted");
- print_diff(stats, dhat::get_stats().unwrap())
+ print_diff(stats, dhat::HeapStats::get())
};
let printed = formatted.print();
drop(formatted);
- #[cfg(feature = "dhat-on")]
+ #[cfg(feature = "dhat-heap")]
{
println!("Printed");
- print_diff(stats, dhat::get_stats().unwrap());
+ print_diff(stats, dhat::HeapStats::get());
}
#[allow(clippy::let_and_return)]

MODIFY
xtask/bench/src/features/mod.rs
xtask/bench/src/features/mod.rs
@@ -2,23 +2,21 @@ pub mod analyzer;
pub mod formatter;
pub mod parser;
-#[cfg(feature = "dhat-on")]
-fn print_diff(before: dhat::Stats, current: dhat::Stats) -> dhat::Stats {
+#[cfg(feature = "dhat-heap")]
+fn print_diff(before: dhat::HeapStats, current: dhat::HeapStats) -> dhat::HeapStats {
use humansize::{file_size_opts as options, FileSize};
println!("\tMemory");
- if let Some(heap) = &current.heap {
- println!("\t\tCurrent Blocks: {}", heap.curr_blocks);
+ println!("\t\tCurrent Blocks: {}", current.curr_blocks);
println!(
"\t\tCurrent Bytes: {}",
- heap.curr_bytes.file_size(options::CONVENTIONAL).unwrap()
+ current.curr_bytes.file_size(options::CONVENTIONAL).unwrap()
);
- println!("\t\tMax Blocks: {}", heap.max_blocks);
+ println!("\t\tMax Blocks: {}", current.max_blocks);
println!(
"\t\tMax Bytes: {}",
- heap.max_bytes.file_size(options::CONVENTIONAL).unwrap()
+ current.max_bytes.file_size(options::CONVENTIONAL).unwrap()
);
- }
println!(
"\t\tTotal Blocks: {}",

MODIFY
xtask/bench/src/features/parser.rs
xtask/bench/src/features/parser.rs
-#[cfg(feature = "dhat-on")]
+#[cfg(feature = "dhat-heap")]
use crate::features::print_diff;
use crate::BenchmarkSummary;
use itertools::Itertools;
@@ -20,19 +20,19 @@ pub struct ParseMeasurement {
}
pub fn benchmark_parse_lib(id: &str, code: &str, source_type: SourceType) -> BenchmarkSummary {
- #[cfg(feature = "dhat-on")]
+ #[cfg(feature = "dhat-heap")]
println!("Start");
- #[cfg(feature = "dhat-on")]
- let stats = dhat::get_stats().unwrap();
+ #[cfg(feature = "dhat-heap")]
+ let stats = dhat::HeapStats::get();
let parser_timer = timing::start();
let (events, diagnostics, trivia) = parse_common(code, 0, source_type);
let parse_duration = parser_timer.stop();
- #[cfg(feature = "dhat-on")]
+ #[cfg(feature = "dhat-heap")]
println!("Parsed");
- #[cfg(feature = "dhat-on")]
- let stats = print_diff(stats, dhat::get_stats().unwrap());
+ #[cfg(feature = "dhat-heap")]
+ let stats = print_diff(stats, dhat::HeapStats::get());
let tree_sink_timer = timing::start();
let mut tree_sink = rome_js_parser::LosslessTreeSink::new(code, &trivia);
@@ -40,10 +40,10 @@ pub fn benchmark_parse_lib(id: &str, code: &str, source_type: SourceType) -> Ben
let (_green, diagnostics) = tree_sink.finish();
let tree_sink_duration = tree_sink_timer.stop();
- #[cfg(feature = "dhat-on")]
+ #[cfg(feature = "dhat-heap")]
println!("Tree-Sink");
- #[cfg(feature = "dhat-on")]
- print_diff(stats, dhat::get_stats().unwrap());
+ #[cfg(feature = "dhat-heap")]
+ print_diff(stats, dhat::HeapStats::get());
BenchmarkSummary::Parser(ParseMeasurement {
id: id.to_string(),

MODIFY
xtask/bench/src/main.rs
xtask/bench/src/main.rs
@@ -2,20 +2,17 @@ use pico_args::Arguments;
use xtask::{project_root, pushd, Result};
use xtask_bench::{run, FeatureToBenchmark, RunArgs};
-#[cfg(feature = "dhat-on")]
-use dhat::DhatAlloc;
-
-#[cfg(feature = "dhat-on")]
+#[cfg(feature = "dhat-heap")]
#[global_allocator]
-static ALLOCATOR: DhatAlloc = DhatAlloc;
+static ALLOCATOR: dhat::Alloc = dhat::Alloc;
-#[cfg(all(target_os = "windows", not(feature = "dhat-on")))]
+#[cfg(all(target_os = "windows", not(feature = "dhat-heap")))]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
fn main() -> Result<(), pico_args::Error> {
- #[cfg(feature = "dhat-on")]
- let _dhat = dhat::Dhat::start_heap_profiling();
+ #[cfg(feature = "dhat-heap")]
+ let _profiler = dhat::Profiler::new_heap();
let _d = pushd(project_root());
let mut args = Arguments::from_env();

fix(xtask): Fix dhat build (#3161)