Open simonpcouch opened 1 week ago
Max was able to replicate behavior of pct_cpu
maxing out around 2.4% on a 12-core machine while the "% CPU" in Activity Monitor was hitting 100%.
cc @gaborcsardi and r-lib/ps#73. syrup does a relatively straightforward transformation on the user
and system
CPU values outputted from ps::ps()
:
https://github.com/simonpcouch/syrup/blob/fe57dd21ccca34966276586863835068ce99705f/R/utils.R#L24-L42
...so the operation, per value, is something like:
interval <- .5
times_t <- ps::ps_cpu_times()
Sys.sleep(interval)
times_t_plus_1 <- ps::ps_cpu_times()
user <- times_t_plus_1[["user"]] - times_t[["user"]]
system <- times_t_plus_1[["system"]] - times_t[["system"]]
(user + system) / interval
#> [1] 0.001063258
This gives reasonable values on Linux, but not on macOS. If you have any intuition on why this might be, Gábor, it'd definitely be appreciated.
Seems like this is broken on new macs, Apple has changed the scale of the values they report and we need to adjust. Fixed in https://github.com/r-lib/ps/commit/b6e0b6235f03edfd87029106bffc2ab6bd1e1ca8
{
times_t <- ps::ps_cpu_times()
tic <- Sys.time()
for (i in 1:10000) runif(100000)
toc <- Sys.time()
times_t_plus_1 <- ps::ps_cpu_times()
interval <- as.double(toc - tic, units = "secs")
user <- times_t_plus_1[["user"]] - times_t[["user"]]
system <- times_t_plus_1[["system"]] - times_t[["system"]]
(user + system) / interval
}
#> [1] 0.9935361
I can do a ps release this week.
Awesome, thanks for looking into this!
@simonpcouch New ps is on CRAN, FYI.
Related to #1. The distributions of
pct_cpu
values, intended to measure CPU usage, are weird on MacOS. Here's an example that distributes a set of linear regression fits across 5 cores using forking:The distribution of
pct_cpu
values seems spot on (except they need to be multiplied by 100, woops) when I run it on Linux. Most of the time, most R sessions are using very little CPU, though each child of the parent process briefly hits 100% while training models:Created on 2024-06-24 with reprex v2.1.0
Here's what the distribution looks like when I run it on macOS, though:
Trying to figure out if that 2.4% approximates something that's useful for debugging... this Macbook has 10 cores.