Skip to content

Commit

Permalink
Fix NPE in ResourceManager when collecting local resource estimation …
Browse files Browse the repository at this point in the history
…in the profiler.

Fixes #21133.

RELNOTES: None.
PiperOrigin-RevId: 603631744
Change-Id: Ied224fd14e2be1465098135e0cab87584bbedb28
  • Loading branch information
zhengwei143 authored and copybara-github committed Feb 2, 2024
1 parent f8c5b4c commit 5c4becc
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ public static ResourceManager instance() {
/** Returns prediction of RAM in Mb used by registered actions. */
@Override
public double getUsedMemoryInMb() {
return usedResources.get(ResourceSet.MEMORY);
return usedResources.getOrDefault(ResourceSet.MEMORY, 0d);
}

/** Returns prediction of CPUs used by registered actions. */
@Override
public double getUsedCPU() {
return usedResources.get(ResourceSet.CPU);
return usedResources.getOrDefault(ResourceSet.CPU, 0d);
}

// Allocated resources are allowed to go "negative", but at least
Expand Down Expand Up @@ -207,7 +207,7 @@ public double getUsedCPU() {

// Used amount of resources. Corresponds to the resource
// definition in the ResourceSet class.
private Map<String, Double> usedResources;
private Map<String, Double> usedResources = new HashMap<>();

// Used local test count. Corresponds to the local test count definition in the ResourceSet class.
private int usedLocalTestCount;
Expand Down

0 comments on commit 5c4becc

Please sign in to comment.