Skip to content

Commit 9aeca9d

Browse files
giorgidzemeta-codesync[bot]
authored andcommitted
Only display cpu and memory usage if --resource-usage is passed
Summary: This diff modifies the Eden debug bench to only display CPU and memory usage if the `--resource-usage` flag is passed. Reviewed By: akushner Differential Revision: D83893620 fbshipit-source-id: bbe5605a918a378e3fe7754dc5213304700170cf
1 parent cacdc99 commit 9aeca9d

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ pub enum BenchCmd {
7979
#[clap(long)]
8080
no_progress: bool,
8181

82+
/// Enable CPU and memory usage monitoring during traversal
83+
#[clap(long)]
84+
resource_usage: bool,
85+
8286
/// Output results in JSON format
8387
#[clap(long)]
8488
json: bool,
@@ -158,6 +162,7 @@ impl crate::Subcommand for BenchCmd {
158162
max_files,
159163
follow_symlinks,
160164
no_progress,
165+
resource_usage,
161166
json,
162167
} => {
163168
if !*json {
@@ -173,6 +178,7 @@ impl crate::Subcommand for BenchCmd {
173178
*max_files,
174179
*follow_symlinks,
175180
*no_progress,
181+
*resource_usage,
176182
thrift_io.as_deref(),
177183
)
178184
.await?
@@ -182,6 +188,7 @@ impl crate::Subcommand for BenchCmd {
182188
*max_files,
183189
*follow_symlinks,
184190
*no_progress,
191+
*resource_usage,
185192
)?
186193
};
187194

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

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ pub struct FinalizedTraversal {
6161
}
6262

6363
impl 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

Comments
 (0)