< prev index next >
src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java
Print this page
@ rev 57734 : Review feedback
|
o rev 57733 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
| Reviewed-by: bobv, mchung
~
o rev 56862 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
| Reviewed-by: bobv
~
@@ -24,10 +24,12 @@
*/
package jdk.internal.platform;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -43,11 +45,11 @@
private static final String CPUACCT_CTRL = "cpuacct";
private static final String CPUSET_CTRL = "cpuset";
private static final String BLKIO_CTRL = "blkio";
private static final String MEMORY_CTRL = "memory";
- static CgroupSubsystem create() {
+ static CgroupMetrics create() {
Map<String, CgroupInfo> infos = new HashMap<>();
try {
List<String> lines = CgroupUtil.readAllLinesPrivileged(Paths.get("/proc/cgroups"));
for (String line : lines) {
if (line.startsWith("#")) {
@@ -84,11 +86,12 @@
}
// Warn about mixed cgroups v1 and cgroups v2 controllers. The code is
// not ready to deal with that on a per-controller basis. Return no metrics
// in that case
if (anyCgroupsV1Controller && anyCgroupsV2Controller) {
- System.err.println("Warning: Mixed cgroupv1 and cgroupv2 not supported. Metrics disabled.");
+ Logger logger = System.getLogger("jdk.internal.platform");
+ logger.log(Level.WARNING, "Mixed cgroupv1 and cgroupv2 not supported. Metrics disabled.");
return null;
}
if (isCgroupsV2) {
// read mountinfo so as to determine root mount path
@@ -109,11 +112,11 @@
for (String line: lines) {
String[] tokens = line.split(":");
if (tokens.length != 3) {
return null; // something is not right.
}
- if (!Integer.valueOf(0).toString().equals(tokens[0])) {
+ if (!"0".equals(tokens[0])) {
// hierarchy must be zero for cgroups v2
return null;
}
cgroupPath = tokens[2];
break;
@@ -122,11 +125,11 @@
return null;
}
CgroupSubsystemController unified = new CgroupV2SubsystemController(
mountPath,
cgroupPath);
- return new CgroupV2Subsystem(unified);
+ return new CgroupMetrics(new CgroupV2Subsystem(unified));
} else {
- return CgroupV1Subsystem.getInstance();
+ return new CgroupV1Metrics(CgroupV1Subsystem.getInstance());
}
}
}
< prev index next >