@@ -5,11 +5,11 @@ use crate::zinit::errors::ZInitError;
55use crate :: zinit:: ord:: { service_dependency_order, ProcessDAG , DUMMY_ROOT } ;
66use crate :: zinit:: service:: ZInitService ;
77use crate :: zinit:: state:: { State , Target } ;
8- use crate :: zinit:: types:: { ProcessStats , ServiceStats , ServiceTable } ;
98#[ cfg( target_os = "linux" ) ]
109use crate :: zinit:: types:: Watcher ;
11- use sysinfo :: { self , PidExt , ProcessExt , System , SystemExt } ;
10+ use crate :: zinit :: types :: { ProcessStats , ServiceStats , ServiceTable } ;
1211use std:: collections:: HashMap ;
12+ use sysinfo:: { self , PidExt , ProcessExt , System , SystemExt } ;
1313
1414// Define a local extension trait for WaitStatus
1515trait WaitStatusExt {
@@ -32,9 +32,9 @@ use std::sync::Arc;
3232#[ cfg( target_os = "linux" ) ]
3333use tokio:: sync:: mpsc;
3434use tokio:: sync:: { Notify , RwLock } ;
35+ use tokio:: time:: sleep;
3536#[ cfg( target_os = "linux" ) ]
3637use tokio:: time:: timeout;
37- use tokio:: time:: sleep;
3838#[ cfg( target_os = "linux" ) ]
3939use tokio_stream:: StreamExt ;
4040
@@ -245,27 +245,27 @@ impl LifecycleManager {
245245 async fn get_process_stats ( & self , pid : i32 ) -> Result < ( u64 , f32 ) > {
246246 // Create a new System instance
247247 let mut system = System :: new ( ) ;
248-
248+
249249 // Convert i32 pid to sysinfo::Pid
250250 let sys_pid = sysinfo:: Pid :: from ( pid as usize ) ;
251-
251+
252252 // First refresh to get initial CPU values
253253 system. refresh_process ( sys_pid) ;
254-
254+
255255 // Wait a short time for CPU measurement
256256 sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
257-
257+
258258 // Refresh again to get updated CPU values
259259 system. refresh_process ( sys_pid) ;
260-
260+
261261 // Get the process
262262 if let Some ( process) = system. process ( sys_pid) {
263263 // Get memory in bytes
264264 let memory_usage = process. memory ( ) ;
265-
265+
266266 // Get CPU usage as percentage
267267 let cpu_usage = process. cpu_usage ( ) ;
268-
268+
269269 Ok ( ( memory_usage, cpu_usage) )
270270 } else {
271271 // Process not found
@@ -278,22 +278,22 @@ impl LifecycleManager {
278278 // Create a new System instance with all processes information
279279 let mut system = System :: new_all ( ) ;
280280 system. refresh_all ( ) ;
281-
281+
282282 // Convert i32 pid to sysinfo::Pid
283283 let sys_pid = sysinfo:: Pid :: from ( parent_pid as usize ) ;
284-
284+
285285 // Wait a short time for CPU measurement
286286 sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
287-
287+
288288 // Refresh processes to get updated CPU values
289289 system. refresh_processes ( ) ;
290-
290+
291291 let mut children = Vec :: new ( ) ;
292-
292+
293293 // Recursively collect all descendant PIDs
294294 let mut descendant_pids = Vec :: new ( ) ;
295295 self . collect_descendants ( sys_pid, & system. processes ( ) , & mut descendant_pids) ;
296-
296+
297297 // Get stats for each child process
298298 for & child_pid in & descendant_pids {
299299 if let Some ( process) = system. process ( child_pid) {
@@ -304,10 +304,10 @@ impl LifecycleManager {
304304 } ) ;
305305 }
306306 }
307-
307+
308308 Ok ( children)
309309 }
310-
310+
311311 /// Recursively collect all descendant PIDs of a process
312312 fn collect_descendants (
313313 & self ,
@@ -328,7 +328,7 @@ impl LifecycleManager {
328328 info ! ( "shutting down" ) ;
329329 #[ cfg( target_os = "linux" ) ]
330330 return self . power ( RebootMode :: RB_POWER_OFF ) . await ;
331-
331+
332332 #[ cfg( not( target_os = "linux" ) ) ]
333333 {
334334 * self . shutdown . write ( ) . await = true ;
@@ -346,7 +346,7 @@ impl LifecycleManager {
346346 info ! ( "rebooting" ) ;
347347 #[ cfg( target_os = "linux" ) ]
348348 return self . power ( RebootMode :: RB_AUTOBOOT ) . await ;
349-
349+
350350 #[ cfg( not( target_os = "linux" ) ) ]
351351 {
352352 * self . shutdown . write ( ) . await = true ;
0 commit comments