@@ -326,29 +326,35 @@ impl LifecycleManager {
326326
327327 /// Get memory and CPU usage for a process
328328 async fn get_process_stats ( & self , pid : i32 ) -> Result < ( u64 , f32 ) > {
329- // Create a new System instance
330- let mut system = System :: new ( ) ;
331-
329+ // Create a new System instance with all information
330+ let mut system = System :: new_all ( ) ;
331+
332332 // Convert i32 pid to sysinfo::Pid
333333 let sys_pid = sysinfo:: Pid :: from ( pid as usize ) ;
334-
334+
335+ // Make sure we're refreshing CPU information
336+ system. refresh_cpu ( ) ;
337+ system. refresh_processes ( ) ;
338+
335339 // First refresh to get initial CPU values
336- system. refresh_process ( sys_pid ) ;
337-
338- // Wait a short time for CPU measurement
339- sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
340-
340+ system. refresh_all ( ) ;
341+
342+ // Wait longer for CPU measurement (500ms instead of 100ms)
343+ sleep ( std:: time:: Duration :: from_millis ( 500 ) ) . await ;
344+
341345 // Refresh again to get updated CPU values
342- system. refresh_process ( sys_pid) ;
343-
346+ system. refresh_cpu ( ) ;
347+ system. refresh_processes ( ) ;
348+ system. refresh_all ( ) ;
349+
344350 // Get the process
345351 if let Some ( process) = system. process ( sys_pid) {
346352 // Get memory in bytes
347353 let memory_usage = process. memory ( ) ;
348-
354+
349355 // Get CPU usage as percentage
350356 let cpu_usage = process. cpu_usage ( ) ;
351-
357+
352358 Ok ( ( memory_usage, cpu_usage) )
353359 } else {
354360 // Process not found
@@ -360,16 +366,22 @@ impl LifecycleManager {
360366 async fn get_child_process_stats ( & self , parent_pid : i32 ) -> Result < Vec < ProcessStats > > {
361367 // Create a new System instance with all processes information
362368 let mut system = System :: new_all ( ) ;
369+
370+ // Make sure we're refreshing CPU information
371+ system. refresh_cpu ( ) ;
372+ system. refresh_processes ( ) ;
363373 system. refresh_all ( ) ;
364-
374+
365375 // Convert i32 pid to sysinfo::Pid
366376 let sys_pid = sysinfo:: Pid :: from ( parent_pid as usize ) ;
367-
368- // Wait a short time for CPU measurement
369- sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
370-
371- // Refresh processes to get updated CPU values
377+
378+ // Wait longer for CPU measurement (500ms instead of 100ms)
379+ sleep ( std:: time:: Duration :: from_millis ( 500 ) ) . await ;
380+
381+ // Refresh all system information to get updated CPU values
382+ system. refresh_cpu ( ) ;
372383 system. refresh_processes ( ) ;
384+ system. refresh_all ( ) ;
373385
374386 let mut children = Vec :: new ( ) ;
375387
0 commit comments