diff options
author | MrEconomical <47700125+MrEconomical@users.noreply.github.com> | 2024-07-25 20:39:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-26 09:09:01 +0530 |
commit | f4952f75a82fa3e3dbba9e5d63ede6565f9c37ce (patch) | |
tree | 9475d870d5b58da562ab084c6a30ec145b347ba7 | |
parent | 790726559016c98655bd93c3f223f8ad5e480d41 (diff) |
fix(ext/node): read correct CPU usage stats on Linux (#24732)
Fixes #24731
<img width="554" alt="deno_fixed"
src="https://github.com/user-attachments/assets/691f2f89-d979-4ca5-be9a-cf51446cd9b2">
The total CPU usage row is ignored and info from `cpu0` and `cpu1` is
correctly read.
---------
Signed-off-by: MrEconomical <47700125+MrEconomical@users.noreply.github.com>
-rw-r--r-- | ext/node/ops/os/cpus.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/ext/node/ops/os/cpus.rs b/ext/node/ops/os/cpus.rs index 7515bae8b..f57e84a1c 100644 --- a/ext/node/ops/os/cpus.rs +++ b/ext/node/ops/os/cpus.rs @@ -246,12 +246,13 @@ pub fn cpu_info() -> Option<Vec<CpuInfo>> { let reader = std::io::BufReader::new(fp); let mut count = 0; - for (i, line) in reader.lines().enumerate() { + // Skip the first line which tracks total CPU time across all cores + for (i, line) in reader.lines().skip(1).enumerate() { let line = line.ok()?; if !line.starts_with("cpu") { break; } - count = i; + count = i + 1; let mut fields = line.split_whitespace(); fields.next()?; let user = fields.next()?.parse::<u64>().ok()?; |