@@ -243,6 +243,7 @@ fn compute_compilation_sections(profile: &ProfilingData) -> Vec<CompilationSecti
243243 let mut backend_start = None ;
244244 let mut backend_end = None ;
245245 let mut linker_duration = None ;
246+ let mut linker_start = None ;
246247
247248 for event in profile. iter_full ( ) {
248249 if first_event_start. is_none ( ) {
@@ -258,34 +259,44 @@ fn compute_compilation_sections(profile: &ProfilingData) -> Vec<CompilationSecti
258259 } else if event. label == "link_crate" {
259260 // The "link" query overlaps codegen, so we want to look at the "link_crate" query
260261 // instead.
262+ linker_start = event. payload . timestamp ( ) . map ( |t| t. start ( ) ) ;
261263 linker_duration = event. duration ( ) ;
262264 }
263265 }
264266 let mut sections = vec ! [ ] ;
265267 // We consider "frontend" to be everything from the start of the compilation (the first event)
266- // to the start of the backend part.
267- if let ( Some ( start) , Some ( end) ) = ( first_event_start, backend_start) {
268- if let Ok ( duration) = end. duration_since ( start) {
269- sections. push ( CompilationSection {
270- name : "Frontend" . to_string ( ) ,
271- value : duration. as_nanos ( ) as u64 ,
272- } ) ;
273- }
274- }
275- if let ( Some ( start) , Some ( end) ) = ( backend_start, backend_end) {
276- if let Ok ( duration) = end. duration_since ( start) {
277- sections. push ( CompilationSection {
278- name : "Backend" . to_string ( ) ,
279- value : duration. as_nanos ( ) as u64 ,
280- } ) ;
281- }
282- }
283- if let Some ( duration) = linker_duration {
284- sections. push ( CompilationSection {
285- name : "Linker" . to_string ( ) ,
286- value : duration. as_nanos ( ) as u64 ,
287- } ) ;
288- }
268+ // to the start of the backend part. If backend is missing, we use the start of the linker
269+ // section instead.
270+ let frontend_end = backend_start. or ( linker_start) ;
271+ let frontend_duration = if let ( Some ( start) , Some ( end) ) = ( first_event_start, frontend_end) {
272+ end. duration_since ( start)
273+ . map ( |duration| duration. as_nanos ( ) as u64 )
274+ . unwrap_or ( 0 )
275+ } else {
276+ 0
277+ } ;
278+ sections. push ( CompilationSection {
279+ name : "Frontend" . to_string ( ) ,
280+ value : frontend_duration,
281+ } ) ;
282+
283+ let backend_duration = if let ( Some ( start) , Some ( end) ) = ( backend_start, backend_end) {
284+ end. duration_since ( start)
285+ . map ( |duration| duration. as_nanos ( ) as u64 )
286+ . unwrap_or ( 0 )
287+ } else {
288+ 0
289+ } ;
290+ sections. push ( CompilationSection {
291+ name : "Backend" . to_string ( ) ,
292+ value : backend_duration,
293+ } ) ;
294+
295+ let linker_duration = linker_duration. unwrap_or_default ( ) ;
296+ sections. push ( CompilationSection {
297+ name : "Linker" . to_string ( ) ,
298+ value : linker_duration. as_nanos ( ) as u64 ,
299+ } ) ;
289300
290301 sections
291302}
0 commit comments