@@ -21,6 +21,7 @@ const MAX_PROCESS_NAME_BYTES: usize = 1_024;
2121const MAX_PROCESS_COMMAND_BYTES : usize = 16 * 1_024 ;
2222const MAX_PROCESS_STATUS_BYTES : usize = 256 ;
2323const HISTORY_CHUNK_SNAPSHOTS : usize = 32 ;
24+ const TWO_STAGE_PROCESS_REFRESH : bool = cfg ! ( any( target_os = "linux" , target_os = "macos" ) ) ;
2425
2526#[ derive( Debug , Clone , Deserialize , Serialize ) ]
2627#[ serde( rename_all = "camelCase" ) ]
@@ -455,7 +456,7 @@ impl Collector {
455456 roots. insert ( config. root_pid ) ;
456457 let tracked = select_tracked_pids ( & rows, & roots) ;
457458 let tracked_process_count = tracked. len ( ) ;
458- let process_details = if cfg ! ( target_os = "linux" ) && !tracked. is_empty ( ) {
459+ let process_details = if TWO_STAGE_PROCESS_REFRESH && !tracked. is_empty ( ) {
459460 let monitor_pid = Pid :: from_u32 ( std:: process:: id ( ) ) ;
460461 let mut detail_pids = tracked
461462 . iter ( )
@@ -562,7 +563,7 @@ impl Collector {
562563
563564// Keep CPU baselines separate. Even a metadata refresh resets Linux process times.
564565fn process_discovery_refresh_kind ( ) -> ProcessRefreshKind {
565- if cfg ! ( target_os = "linux" ) {
566+ if TWO_STAGE_PROCESS_REFRESH {
566567 ProcessRefreshKind :: nothing ( ) . with_cpu ( ) . without_tasks ( )
567568 } else {
568569 process_refresh_kind ( )
@@ -1035,6 +1036,43 @@ mod tests {
10351036 assert ! ( process. cpu_percent. is_finite( ) ) ;
10361037 }
10371038
1039+ #[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
1040+ #[ test]
1041+ fn keeps_command_lines_and_memory_out_of_the_discovery_table ( ) {
1042+ let mut collector = Collector :: new ( ) ;
1043+ let mut config = CollectorConfig {
1044+ root_pid : u32:: MAX ,
1045+ sample_interval : None ,
1046+ external_processes : HashMap :: new ( ) ,
1047+ } ;
1048+ assert ! ( collector. sample( & config, None ) . processes. is_empty( ) ) ;
1049+
1050+ let pid = Pid :: from_u32 ( std:: process:: id ( ) ) ;
1051+ let unselected = collector. system . process ( pid) . expect ( "discovered process" ) ;
1052+ assert ! ( unselected. cmd( ) . is_empty( ) ) ;
1053+ assert_eq ! ( unselected. memory( ) , 0 ) ;
1054+ assert_eq ! ( unselected. virtual_memory( ) , 0 ) ;
1055+
1056+ config. external_processes . insert ( pid. as_u32 ( ) , None ) ;
1057+ let snapshot = collector. sample ( & config, None ) ;
1058+ let selected = snapshot
1059+ . processes
1060+ . iter ( )
1061+ . find ( |process| process. pid == pid. as_u32 ( ) )
1062+ . expect ( "external process details" ) ;
1063+ assert ! ( !selected. command. is_empty( ) ) ;
1064+ assert ! ( selected. resident_bytes > 0 ) ;
1065+ assert ! ( selected. start_time_ms > 0 ) ;
1066+
1067+ let retained = collector
1068+ . system
1069+ . process ( pid)
1070+ . expect ( "retained CPU baseline" ) ;
1071+ assert ! ( retained. cmd( ) . is_empty( ) ) ;
1072+ assert_eq ! ( retained. memory( ) , 0 ) ;
1073+ assert_eq ! ( retained. virtual_memory( ) , 0 ) ;
1074+ }
1075+
10381076 #[ test]
10391077 fn accepts_clock_shifts_without_accepting_reused_process_starts ( ) {
10401078 assert ! ( matches_process_start_time( 10_000 , 13_600 , 3_600 ) ) ;
0 commit comments