Skip to content

Commit cacdc99

Browse files
giorgidzemeta-codesync[bot]
authored andcommitted
When --no-progress is given do not initialize the memory usage monitor for the progress bar
Summary: This diff optimizes the initialization of the memory usage monitor in the `eden debug bench` command. When the `--no-progress` flag is provided, the memory usage monitor is not initialized, reducing unnecessary overhead. Reviewed By: akushner Differential Revision: D83886437 fbshipit-source-id: d29b91af65e109be31e05918ff20839a14b0d88b
1 parent d36547f commit cacdc99

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

eden/fs/cli_rs/edenfs-commands/src/debug/bench/traversal.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ struct InProgressTraversal {
4343
total_dir_entries: usize,
4444
max_files: usize,
4545
follow_symlinks: bool,
46-
system: System,
47-
pid: Pid,
46+
system: Option<System>,
47+
pid: Option<Pid>,
4848
}
4949

5050
// Define a struct for the results from the finalize step
@@ -75,9 +75,15 @@ impl InProgressTraversal {
7575
Some(pb)
7676
};
7777

78-
let mut system = System::new_all();
79-
let pid = sysinfo::get_current_pid().expect("Failed to get current process ID");
80-
system.refresh_all();
78+
// Only initialize system monitoring if progress reporting is enabled
79+
let (system, pid) = if no_progress {
80+
(None, None)
81+
} else {
82+
let mut sys = System::new_all();
83+
let process_id = sysinfo::get_current_pid().expect("Failed to get current process ID");
84+
sys.refresh_all();
85+
(Some(sys), Some(process_id))
86+
};
8187

8288
Self {
8389
file_count: 0,
@@ -131,17 +137,22 @@ impl InProgressTraversal {
131137
return;
132138
}
133139

134-
self.system
135-
.refresh_processes(sysinfo::ProcessesToUpdate::Some(&[self.pid]), false);
136-
137140
let files_per_second = self.file_count as f64 / elapsed;
138-
let (memory_usage_mb, cpu_usage) = match self.system.process(self.pid) {
139-
Some(process) => (
140-
process.memory() as f64 / 1024.0 / 1024.0,
141-
process.cpu_usage(),
142-
),
143-
None => (0.0, 0.0),
144-
};
141+
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),
152+
}
153+
} else {
154+
(0.0, 0.0)
155+
};
145156

146157
pb.set_message(format!(
147158
"{} files | {} dirs | {:.0} files/s | {:.2} MiB memory usage | {:.2}% CPU usage",

0 commit comments

Comments
 (0)