Commit 9a8880be authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

gate histogram behind debug_assertions

parent 26547c3c
......@@ -951,40 +951,43 @@ pub async fn analyse_ecmascript_module_internal(
.instrument(span)
.await?;
static HISTOGRAM: once_cell::sync::Lazy<Option<String>> =
once_cell::sync::Lazy::new(|| std::env::var("JSVALUE_HISTOGRAM").ok());
if let Some(p) = HISTOGRAM.as_ref()
&& path.path.ends_with(p)
#[cfg(debug_assertions)]
{
let mut histogram = vec![];
let mut add = |v: u32| {
let scaled = (v / 10) as usize;
if histogram.len() < scaled + 1 {
histogram.resize(scaled + 1, 0);
}
histogram[scaled] += 1usize;
};
for (name, v) in &var_graph.values {
let size = v.total_nodes();
add(size);
if size > 100 {
println!("big jsvalue {name:?} {size} {v}")
}
}
for effect in &var_graph.effects {
for v in effect.values() {
static HISTOGRAM: once_cell::sync::Lazy<Option<String>> =
once_cell::sync::Lazy::new(|| std::env::var("JSVALUE_HISTOGRAM").ok());
if let Some(p) = HISTOGRAM.as_ref()
&& path.path.ends_with(p)
{
let mut histogram = vec![];
let mut add = |v: u32| {
let scaled = (v / 10) as usize;
if histogram.len() < scaled + 1 {
histogram.resize(scaled + 1, 0);
}
histogram[scaled] += 1usize;
};
for (name, v) in &var_graph.values {
let size = v.total_nodes();
add(size);
if size > 100 {
println!("big jsvalue in effect {size} {v}")
println!("big jsvalue {name:?} {size} {v}")
}
}
}
if !histogram.is_empty() {
let scale = 150f32 / (*histogram.iter().max().unwrap() as f32);
for (i, count) in histogram.into_iter().enumerate() {
let bar = "*".repeat((count as f32 * scale) as usize);
println!("{i:3}: {bar} ({count})");
for effect in &var_graph.effects {
for v in effect.values() {
let size = v.total_nodes();
add(size);
if size > 100 {
println!("big jsvalue in effect {size} {v}")
}
}
}
if !histogram.is_empty() {
let scale = 150f32 / (*histogram.iter().max().unwrap() as f32);
for (i, count) in histogram.into_iter().enumerate() {
let bar = "*".repeat((count as f32 * scale) as usize);
println!("{i:3}: {bar} ({count})");
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment