Skip to content

Commit

Permalink
fix(ext/node): read correct CPU usage stats on Linux (#24732)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
MrEconomical authored Jul 26, 2024
1 parent 7907265 commit f4952f7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ext/node/ops/os/cpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down

0 comments on commit f4952f7

Please # to comment.