diff --git a/crates/turbopack-trace-server/src/reader/heaptrack.rs b/crates/turbopack-trace-server/src/reader/heaptrack.rs index a1010340d73bd..c328230fb6534 100644 --- a/crates/turbopack-trace-server/src/reader/heaptrack.rs +++ b/crates/turbopack-trace-server/src/reader/heaptrack.rs @@ -138,10 +138,7 @@ impl HeaptrackFormat { } }, trace_instruction_pointers: vec![0], - allocations: vec![AllocationInfo { - size: 0, - trace_index: 0, - }], + allocations: vec![], spans: 0, collapse_crates: env::var("COLLAPSE_CRATES") .unwrap_or_default() diff --git a/crates/turbopack-trace-server/src/reader/mod.rs b/crates/turbopack-trace-server/src/reader/mod.rs index 233712307e2b4..ff32b47337e44 100644 --- a/crates/turbopack-trace-server/src/reader/mod.rs +++ b/crates/turbopack-trace-server/src/reader/mod.rs @@ -20,6 +20,8 @@ use crate::{ store_container::StoreContainer, }; +const MIN_INITIAL_REPORT_SIZE: u64 = 100 * 1024 * 1024; + trait TraceFormat { fn read(&mut self, buffer: &[u8]) -> Result; fn stats(&self) -> String { @@ -115,17 +117,7 @@ impl TraceReader { let mut format: Option> = None; let mut current_read = 0; - let mut initial_read = { - if let Ok(pos) = file.seek(SeekFrom::End(0)) { - if pos > 100 * 1024 * 1024 { - Some(pos) - } else { - None - } - } else { - None - } - }; + let mut initial_read = { file.seek(SeekFrom::End(0)).ok() }; if file.seek(SeekFrom::Start(0)).is_err() { return false; } @@ -145,7 +137,9 @@ impl TraceReader { match file.read(&mut chunk) { Ok(bytes_read) => { if bytes_read == 0 { - if let Some(value) = self.wait_for_more_data(&mut file, &mut initial_read) { + if let Some(value) = + self.wait_for_more_data(&mut file, &mut initial_read, format.as_deref()) + { return value; } } else { @@ -220,7 +214,9 @@ impl TraceReader { } Err(err) => { if err.kind() == io::ErrorKind::UnexpectedEof { - if let Some(value) = self.wait_for_more_data(&mut file, &mut initial_read) { + if let Some(value) = + self.wait_for_more_data(&mut file, &mut initial_read, format.as_deref()) + { return value; } } else { @@ -237,12 +233,19 @@ impl TraceReader { &mut self, file: &mut TraceFile, initial_read: &mut Option, + format: Option<&dyn TraceFormat>, ) -> Option { let Ok(pos) = file.stream_position() else { return Some(true); }; if let Some(total) = initial_read.take() { - println!("Initial read completed ({} MB)", total / (1024 * 1024),); + if let Some(format) = format { + let stats = format.stats(); + println!("{}", stats); + } + if total > MIN_INITIAL_REPORT_SIZE { + println!("Initial read completed ({} MB)", total / (1024 * 1024)); + } } thread::sleep(Duration::from_millis(100)); let Ok(end) = file.seek(SeekFrom::End(0)) else { diff --git a/crates/turbopack-trace-server/src/viewer.rs b/crates/turbopack-trace-server/src/viewer.rs index f4639ff95c8c3..de7665ae223bf 100644 --- a/crates/turbopack-trace-server/src/viewer.rs +++ b/crates/turbopack-trace-server/src/viewer.rs @@ -853,7 +853,7 @@ impl Viewer { .collect(); Update { lines, - max: current, + max: max(1, current), } } }