diff --git a/src/main/java/com/google/devtools/build/lib/profiler/CollectLocalResourceUsage.java b/src/main/java/com/google/devtools/build/lib/profiler/CollectLocalResourceUsage.java index 76c9d478d95aa1..761d7be7e4bd2a 100644 --- a/src/main/java/com/google/devtools/build/lib/profiler/CollectLocalResourceUsage.java +++ b/src/main/java/com/google/devtools/build/lib/profiler/CollectLocalResourceUsage.java @@ -132,6 +132,12 @@ public void run() { long nextCpuTimeNanos = osBean.getProcessCpuTime(); double systemCpuLoad = osBean.getSystemCpuLoad(); + if (Double.isNaN(systemCpuLoad)) { + // Unlike advertised, on Mac the system CPU load is NaN sometimes. + // There is no good way to handle this, so to avoid any downstream method crashing on this, + // we reset the CPU value here. + systemCpuLoad = 0; + } double systemUsage = systemCpuLoad * numProcessors; long systemMemoryUsageMb = -1;