Path: blob/master/src/java.base/linux/classes/jdk/internal/platform/CgroupInfo.java
40948 views
/*1* Copyright (c) 2020, Red Hat Inc.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.platform;2627/**28* Data structure to hold info from /proc/self/cgroup,29* /proc/cgroups and /proc/self/mountinfo30*31* man 7 cgroups32*33* @see CgroupSubsystemFactory34*/35public class CgroupInfo {3637private final String name;38private final int hierarchyId;39private final boolean enabled;40private String mountPoint;41private String mountRoot;42private String cgroupPath;4344private CgroupInfo(String name, int hierarchyId, boolean enabled) {45this.name = name;46this.hierarchyId = hierarchyId;47this.enabled = enabled;48}4950public String getName() {51return name;52}5354public int getHierarchyId() {55return hierarchyId;56}5758public boolean isEnabled() {59return enabled;60}6162public String getMountPoint() {63return mountPoint;64}6566public void setMountPoint(String mountPoint) {67this.mountPoint = mountPoint;68}6970public String getMountRoot() {71return mountRoot;72}7374public void setMountRoot(String mountRoot) {75this.mountRoot = mountRoot;76}7778public String getCgroupPath() {79return cgroupPath;80}8182public void setCgroupPath(String cgroupPath) {83this.cgroupPath = cgroupPath;84}8586/*87* Creates a CgroupInfo instance from a line in /proc/cgroups.88* Comment token (hash) is handled by the caller.89*90* Example (annotated):91*92* #subsys_name hierarchy num_cgroups enabled93* cpuset 10 1 1 (a)94* cpu 7 8 1 (b)95* [...]96*97* Line (a) would yield:98* info = new CgroupInfo("cpuset", 10, true);99* return info;100* Line (b) results in:101* info = new CgroupInfo("cpu", 7, true);102* return info;103*104*105* See CgroupSubsystemFactory.determineType()106*107*/108static CgroupInfo fromCgroupsLine(String line) {109String[] tokens = line.split("\\s+");110if (tokens.length != 4) {111return null;112}113// discard 3'rd field, num_cgroups114return new CgroupInfo(tokens[0] /* name */,115Integer.parseInt(tokens[1]) /* hierarchyId */,116(Integer.parseInt(tokens[3]) == 1) /* enabled */);117}118119}120121122