< prev index next >
src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java
Print this page
@ rev 57735 : Review feedback 2
|
o 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
~
*** 30,45 ****
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;
- import java.util.stream.Stream;
import jdk.internal.platform.cgroupv1.CgroupV1Subsystem;
import jdk.internal.platform.cgroupv2.CgroupV2Subsystem;
- import jdk.internal.platform.cgroupv2.CgroupV2SubsystemController;
class CgroupSubsystemFactory {
private static final String CPU_CTRL = "cpu";
private static final String CPUACCT_CTRL = "cpuacct";
--- 30,42 ----
*** 87,135 ****
// 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) {
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
! String mountPath = null;
! try (Stream<String> lines =
! CgroupUtil.readFilePrivileged(Paths.get("/proc/self/mountinfo"))) {
!
! String l = lines.filter(line -> line.contains(" - cgroup2 "))
! .collect(Collectors.joining());
! String[] tokens = l.split(" ");
! mountPath = tokens[4];
! } catch (IOException e) {
! return null;
! }
! String cgroupPath = null;
! try {
! List<String> lines = CgroupUtil.readAllLinesPrivileged(Paths.get("/proc/self/cgroup"));
! for (String line: lines) {
! String[] tokens = line.split(":");
! if (tokens.length != 3) {
! return null; // something is not right.
! }
! if (!"0".equals(tokens[0])) {
! // hierarchy must be zero for cgroups v2
! return null;
! }
! cgroupPath = tokens[2];
! break;
! }
! } catch (IOException e) {
! return null;
! }
! CgroupSubsystemController unified = new CgroupV2SubsystemController(
! mountPath,
! cgroupPath);
! return new CgroupMetrics(new CgroupV2Subsystem(unified));
} else {
! return new CgroupV1Metrics(CgroupV1Subsystem.getInstance());
}
}
}
--- 84,101 ----
// 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) {
Logger logger = System.getLogger("jdk.internal.platform");
! logger.log(Level.DEBUG, "Mixed cgroupv1 and cgroupv2 not supported. Metrics disabled.");
return null;
}
if (isCgroupsV2) {
! CgroupSubsystem subsystem = CgroupV2Subsystem.getInstance();
! return subsystem != null ? new CgroupMetrics(subsystem) : null;
} else {
! CgroupV1Subsystem subsystem = CgroupV1Subsystem.getInstance();
! return subsystem != null ? new CgroupV1MetricsImpl(subsystem) : null;
}
}
}
< prev index next >