8284977: MetricsTesterCgroupV2.getLongValueEntryFromFile fails when named value doesn't exist

Reviewed-by: sgehwolf, mdoerr
This commit is contained in:
Matthias Baesken 2022-06-15 06:39:23 +00:00
parent 08400f18ba
commit 444a0d98ac

@ -121,6 +121,11 @@ public class MetricsTesterCgroupV2 implements CgroupMetricsTester {
Path filePath = Paths.get(UNIFIED.getPath(), file);
try {
String strVal = Files.lines(filePath).filter(l -> l.startsWith(metric)).collect(Collectors.joining());
if (strVal.isEmpty()) {
// sometimes the match for the metric does not exist, e.g. cpu.stat's nr_periods iff the controller
// is not enabled
return UNLIMITED;
}
String[] keyValues = strVal.split("\\s+");
String value = keyValues[1];
return convertStringToLong(value);