@@ -467,15 +467,12 @@ impl TelemetryRecorder {
467467 cpu_events = profiler. drain ( ) ;
468468 // Pull eagerly-cached thread names into our intern table
469469 for event in & cpu_events {
470- if let TelemetryEvent :: CpuSample { tid, worker_id, .. } = event {
471- if * worker_id == UNKNOWN_WORKER
470+ if let TelemetryEvent :: CpuSample { tid, worker_id, .. } = event
471+ && * worker_id == UNKNOWN_WORKER
472472 && !self . thread_name_intern . contains_key ( tid)
473- {
474- if let Some ( name) = profiler. thread_name ( * tid) {
473+ && let Some ( name) = profiler. thread_name ( * tid) {
475474 self . thread_name_intern . insert ( * tid, name. to_string ( ) ) ;
476475 }
477- }
478- }
479476 }
480477 }
481478 {
@@ -486,8 +483,8 @@ impl TelemetryRecorder {
486483 }
487484 for event in & cpu_events {
488485 // Emit ThreadNameDef for non-worker tids before their first sample in this file
489- if let TelemetryEvent :: CpuSample { worker_id, tid, .. } = event {
490- if * worker_id == UNKNOWN_WORKER
486+ if let TelemetryEvent :: CpuSample { worker_id, tid, .. } = event
487+ && * worker_id == UNKNOWN_WORKER
491488 && !self . thread_name_emitted_this_file . contains ( tid)
492489 {
493490 if self . writer . take_rotated ( ) {
@@ -504,9 +501,8 @@ impl TelemetryRecorder {
504501 }
505502 self . thread_name_emitted_this_file . insert ( * tid) ;
506503 }
507- }
508- if self . inline_callframe_symbols {
509- if let TelemetryEvent :: CpuSample { callchain, .. } = event {
504+ if self . inline_callframe_symbols
505+ && let TelemetryEvent :: CpuSample { callchain, .. } = event {
510506 // Check for rotation before writing defs
511507 if self . writer . take_rotated ( ) {
512508 self . flush_state . on_rotate ( ) ;
@@ -516,15 +512,15 @@ impl TelemetryRecorder {
516512 for & addr in callchain {
517513 if !self . callframe_emitted_this_file . contains ( & addr) {
518514 // Symbolicate if not yet interned
519- if ! self . callframe_intern . contains_key ( & addr) {
515+ self . callframe_intern . entry ( addr) . or_insert_with ( || {
520516 let sym = perf_self_profile:: resolve_symbol ( addr) ;
521517 let symbol = sym. name . unwrap_or_else ( || format ! ( "{:#x}" , addr) ) ;
522518 let location = sym. code_info . map ( |info| match info. line {
523519 Some ( line) => format ! ( "{}:{}" , info. file, line) ,
524520 None => info. file ,
525521 } ) ;
526- self . callframe_intern . insert ( addr , ( symbol, location) ) ;
527- }
522+ ( symbol, location)
523+ } ) ;
528524 let ( symbol, location) = self . callframe_intern [ & addr] . clone ( ) ;
529525 let def = TelemetryEvent :: CallframeDef {
530526 address : addr,
@@ -536,7 +532,6 @@ impl TelemetryRecorder {
536532 }
537533 }
538534 }
539- }
540535 let _ = self . writer . write_event ( event) ;
541536 }
542537 }
@@ -641,18 +636,16 @@ impl TelemetryRecorder {
641636 let s_stop = shared. clone ( ) ;
642637 builder
643638 . on_thread_start ( move || {
644- if let Ok ( mut prof) = s_start. sched_profiler . lock ( ) {
645- if let Some ( ref mut p) = * prof {
639+ if let Ok ( mut prof) = s_start. sched_profiler . lock ( )
640+ && let Some ( ref mut p) = * prof {
646641 let _ = p. track_current_thread ( ) ;
647642 }
648- }
649643 } )
650644 . on_thread_stop ( move || {
651- if let Ok ( mut prof) = s_stop. sched_profiler . lock ( ) {
652- if let Some ( ref mut p) = * prof {
645+ if let Ok ( mut prof) = s_stop. sched_profiler . lock ( )
646+ && let Some ( ref mut p) = * prof {
653647 p. stop_tracking_current_thread ( ) ;
654648 }
655- }
656649 } ) ;
657650 }
658651
@@ -862,25 +855,17 @@ impl TracedRuntimeBuilder {
862855
863856 // Start CPU profiler if configured
864857 #[ cfg( feature = "cpu-profiling" ) ]
865- let sampler = if let Some ( config) = self . cpu_profiling_config {
866- Some ( crate :: telemetry:: cpu_profile:: CpuProfiler :: start (
858+ let sampler = self . cpu_profiling_config . map ( |config| crate :: telemetry:: cpu_profile:: CpuProfiler :: start (
867859 config,
868860 start_mono_ns,
869- ) )
870- } else {
871- None
872- } ;
861+ ) ) ;
873862
874863 // Start sched event profiler if configured
875864 #[ cfg( feature = "cpu-profiling" ) ]
876- let sched = if let Some ( config) = self . sched_event_config {
877- Some ( crate :: telemetry:: cpu_profile:: SchedProfiler :: new (
865+ let sched = self . sched_event_config . map ( |config| crate :: telemetry:: cpu_profile:: SchedProfiler :: new (
878866 config,
879867 start_mono_ns,
880- ) )
881- } else {
882- None
883- } ;
868+ ) ) ;
884869
885870 let recorder = TelemetryRecorder :: install (
886871 & mut builder,
0 commit comments