1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00

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>
This commit is contained in:
MrEconomical 2024-07-25 20:39:01 -07:00 committed by GitHub
parent 7907265590
commit f4952f75a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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()?;