< prev index next >
test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java
Print this page
@ rev 57586 : Review changes
|
o rev 57585 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
| Reviewed-by: bobv
~
o rev 56863 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
| Reviewed-by: bobv
~
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -124,10 +124,13 @@
// Initialize CPU usage metrics before we do any testing.
startSysVal = metrics.getCpuSystemUsage();
startUserVal = metrics.getCpuUserUsage();
startUsage = metrics.getCpuUsage();
startPerCpu = metrics.getPerCpuUsage();
+ if (startPerCpu == null) {
+ startPerCpu = new long[0];
+ }
try {
Stream<String> lines = Files.lines(Paths.get("/proc/self/mountinfo"));
lines.filter(line -> line.contains(" - cgroup cgroup "))
.map(line -> line.split(" "))
@@ -147,17 +150,17 @@
String fname = subSystemPaths.get(subSystem.value())[0] + File.separator + fileName;
try {
return new Scanner(new File(fname)).useDelimiter("\\Z").next();
} catch (FileNotFoundException e) {
System.err.println("Unable to open : " + fname);
- return "";
+ return null;
}
}
private static long getLongValueFromFile(Controller subSystem, String fileName) {
String data = getFileContents(subSystem, fileName);
- return data.isEmpty() ? 0L : convertStringToLong(data);
+ return (data == null || data.isEmpty()) ? 0L : convertStringToLong(data);
}
private static long convertStringToLong(String strval) {
return CgroupMetricsTester.convertStringToLong(strval, Long.MAX_VALUE);
}
@@ -330,15 +333,21 @@
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
warn(Controller.CPUACCT, "cpuacct.usage", oldVal, newVal);
}
- Long[] newVals = Stream.of(getFileContents(Controller.CPUACCT, "cpuacct.usage_percpu")
+ String newValsStr = getFileContents(Controller.CPUACCT, "cpuacct.usage_percpu");
+ Long[] newVals = new Long[0];
+ if (newValsStr != null) {
+ newVals = Stream.of(newValsStr
.split("\\s+"))
.map(Long::parseLong)
.toArray(Long[]::new);
- Long[] oldVals = LongStream.of(metrics.getPerCpuUsage()).boxed().toArray(Long[]::new);
+ }
+ long[] oldValsPrim = metrics.getPerCpuUsage();
+ Long[] oldVals = LongStream.of(oldValsPrim == null ? new long[0] : oldValsPrim)
+ .boxed().toArray(Long[]::new);
for (int i = 0; i < oldVals.length; i++) {
if (!CgroupMetricsTester.compareWithErrorMargin(oldVals[i], newVals[i])) {
warn(Controller.CPUACCT, "cpuacct.usage_percpu", oldVals[i], newVals[i]);
}
}
@@ -486,10 +495,13 @@
// make system call
long newSysVal = metrics.getCpuSystemUsage();
long newUserVal = metrics.getCpuUserUsage();
long newUsage = metrics.getCpuUsage();
long[] newPerCpu = metrics.getPerCpuUsage();
+ if (newPerCpu == null) {
+ newPerCpu = new long[0];
+ }
// system/user CPU usage counters may be slowly increasing.
// allow for equal values for a pass
if (newSysVal < startSysVal) {
fail(Controller.CPU, "getCpuSystemUsage", newSysVal, startSysVal);
< prev index next >