Skip to content

Commit

Permalink
Turbopack Tracing: show memory consumption (vercel/turborepo#8020)
Browse files Browse the repository at this point in the history
### Description

show allocated memory while loading to allow finding peek memory.

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->


Closes PACK-2989
  • Loading branch information
sokra authored Apr 23, 2024
1 parent 8adbcc8 commit a60d4ad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/turbopack-trace-server/src/reader/heaptrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ pub struct HeaptrackFormat {
collapse_crates: HashSet<String>,
expand_crates: HashSet<String>,
expand_recursion: bool,
allocated_memory: u64,
temp_allocated_memory: u64,
}

const RECURSION_IP: usize = 1;
Expand Down Expand Up @@ -153,19 +155,24 @@ impl HeaptrackFormat {
.map(|s| s.to_string())
.collect(),
expand_recursion: env::var("EXPAND_RECURSION").is_ok(),
allocated_memory: 0,
temp_allocated_memory: 0,
}
}
}

impl TraceFormat for HeaptrackFormat {
fn stats(&self) -> String {
format!(
"{} spans, {} strings, {} ips, {} traces, {} allocations",
"{} spans, {} strings, {} ips, {} traces, {} allocations, {:.2} GB allocated, {:.2} \
GB temporarily allocated",
self.spans,
self.strings.len() - 1,
self.trace_instruction_pointers.len() - 1,
self.traces.len() - 1,
self.allocations.len() - 1
self.allocations.len() - 1,
(self.allocated_memory / 1024 / 1024) as f32 / 1024.0,
(self.temp_allocated_memory / 1024 / 1024) as f32 / 1024.0,
)
}

Expand Down Expand Up @@ -419,6 +426,7 @@ impl TraceFormat for HeaptrackFormat {
let TraceData { span_index, .. } =
self.traces.get(*trace_index).context("trace not found")?;
store.add_allocation(*span_index, *size, 1, &mut outdated_spans);
self.allocated_memory += *size;
}
}
b'-' => {
Expand All @@ -432,6 +440,8 @@ impl TraceFormat for HeaptrackFormat {
let TraceData { span_index, .. } =
self.traces.get(*trace_index).context("trace not found")?;
store.add_deallocation(*span_index, *size, 1, &mut outdated_spans);
self.allocated_memory -= *size;
self.temp_allocated_memory += *size;
}
}
b'R' => {
Expand Down

0 comments on commit a60d4ad

Please sign in to comment.