Skip to content

Commit

Permalink
Handle invalid NaN values that the osBean returns on Mac sometimes.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 495821759
Change-Id: I831a3386a1fdcf05266b4f6afa9e37eb9693aacf
  • Loading branch information
meisterT authored and hvadehra committed Feb 14, 2023
1 parent 1284f37 commit 7996d14
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7996d14

Please sign in to comment.