@@ -61,7 +61,12 @@ pub struct FinalizedTraversal {
6161}
6262
6363impl InProgressTraversal {
64- fn new ( no_progress : bool , max_files : usize , follow_symlinks : bool ) -> Self {
64+ fn new (
65+ no_progress : bool ,
66+ resource_usage : bool ,
67+ max_files : usize ,
68+ follow_symlinks : bool ,
69+ ) -> Self {
6570 let progress_bar = if no_progress {
6671 None
6772 } else {
@@ -75,14 +80,14 @@ impl InProgressTraversal {
7580 Some ( pb)
7681 } ;
7782
78- // Only initialize system monitoring if progress reporting is enabled
79- let ( system, pid) = if no_progress {
80- ( None , None )
81- } else {
83+ // Only initialize system monitoring if resource usage monitoring is enabled
84+ let ( system, pid) = if resource_usage {
8285 let mut sys = System :: new_all ( ) ;
8386 let process_id = sysinfo:: get_current_pid ( ) . expect ( "Failed to get current process ID" ) ;
8487 sys. refresh_all ( ) ;
8588 ( Some ( sys) , Some ( process_id) )
89+ } else {
90+ ( None , None )
8691 } ;
8792
8893 Self {
@@ -139,25 +144,32 @@ impl InProgressTraversal {
139144
140145 let files_per_second = self . file_count as f64 / elapsed;
141146
142- // Only collect system metrics if system monitoring is enabled
143- let ( memory_usage_mb , cpu_usage ) =
144- if let ( Some ( system) , Some ( pid ) ) = ( & mut self . system , & self . pid ) {
145- system . refresh_processes ( sysinfo :: ProcessesToUpdate :: Some ( & [ * pid ] ) , false ) ;
146- match system . process ( * pid ) {
147- Some ( process ) => (
148- process . memory ( ) as f64 / 1024.0 / 1024.0 ,
149- process . cpu_usage ( ) ,
150- ) ,
151- None => ( 0.0 , 0.0 ) ,
147+ let message = if let ( Some ( system) , Some ( pid ) ) = ( & mut self . system , & self . pid ) {
148+ system . refresh_processes ( sysinfo :: ProcessesToUpdate :: Some ( & [ * pid ] ) , false ) ;
149+ match system. process ( * pid) {
150+ Some ( process ) => {
151+ let memory_mb = process. memory ( ) as f64 / types :: BYTES_IN_MEGABYTE as f64 ;
152+ let cpu_usage = process . cpu_usage ( ) ;
153+ format ! (
154+ "{} files | {} dirs | {:.0} files/s | {:.2} MiB memory usage | {:.2}% CPU usage" ,
155+ self . file_count , self . dir_count , files_per_second , memory_mb , cpu_usage
156+ )
152157 }
153- } else {
154- ( 0.0 , 0.0 )
155- } ;
156-
157- pb. set_message ( format ! (
158- "{} files | {} dirs | {:.0} files/s | {:.2} MiB memory usage | {:.2}% CPU usage" ,
159- self . file_count, self . dir_count, files_per_second, memory_usage_mb, cpu_usage
160- ) ) ;
158+ None => {
159+ format ! (
160+ "{} files | {} dirs | {:.0} files/s" ,
161+ self . file_count, self . dir_count, files_per_second
162+ )
163+ }
164+ }
165+ } else {
166+ format ! (
167+ "{} files | {} dirs | {:.0} files/s" ,
168+ self . file_count, self . dir_count, files_per_second
169+ )
170+ } ;
171+
172+ pb. set_message ( message) ;
161173 }
162174 }
163175
@@ -230,6 +242,7 @@ pub async fn bench_traversal_thrift_read(
230242 max_files : usize ,
231243 follow_symlinks : bool ,
232244 no_progress : bool ,
245+ resource_usage : bool ,
233246 fbsource_path : Option < & str > ,
234247) -> Result < Benchmark > {
235248 let path = Path :: new ( dir_path) ;
@@ -238,7 +251,7 @@ pub async fn bench_traversal_thrift_read(
238251 }
239252
240253 let mut in_progress_traversal =
241- InProgressTraversal :: new ( no_progress, max_files, follow_symlinks) ;
254+ InProgressTraversal :: new ( no_progress, resource_usage , max_files, follow_symlinks) ;
242255 in_progress_traversal. traverse_path ( path) ?;
243256
244257 let ft = in_progress_traversal. finalize ( ) ;
@@ -423,14 +436,15 @@ pub fn bench_traversal_fs_read(
423436 max_files : usize ,
424437 follow_symlinks : bool ,
425438 no_progress : bool ,
439+ resource_usage : bool ,
426440) -> Result < Benchmark > {
427441 let path = Path :: new ( dir_path) ;
428442 if !path. exists ( ) || !path. is_dir ( ) {
429443 return Err ( anyhow:: anyhow!( "Invalid directory path: {}" , dir_path) ) ;
430444 }
431445
432446 let mut in_progress_traversal =
433- InProgressTraversal :: new ( no_progress, max_files, follow_symlinks) ;
447+ InProgressTraversal :: new ( no_progress, resource_usage , max_files, follow_symlinks) ;
434448
435449 in_progress_traversal. traverse_path ( path) ?;
436450
0 commit comments