Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/linux/classes/jdk/internal/platform/CgroupInfo.java
40948 views
1
/*
2
* Copyright (c) 2020, Red Hat Inc.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package jdk.internal.platform;
27
28
/**
29
* Data structure to hold info from /proc/self/cgroup,
30
* /proc/cgroups and /proc/self/mountinfo
31
*
32
* man 7 cgroups
33
*
34
* @see CgroupSubsystemFactory
35
*/
36
public class CgroupInfo {
37
38
private final String name;
39
private final int hierarchyId;
40
private final boolean enabled;
41
private String mountPoint;
42
private String mountRoot;
43
private String cgroupPath;
44
45
private CgroupInfo(String name, int hierarchyId, boolean enabled) {
46
this.name = name;
47
this.hierarchyId = hierarchyId;
48
this.enabled = enabled;
49
}
50
51
public String getName() {
52
return name;
53
}
54
55
public int getHierarchyId() {
56
return hierarchyId;
57
}
58
59
public boolean isEnabled() {
60
return enabled;
61
}
62
63
public String getMountPoint() {
64
return mountPoint;
65
}
66
67
public void setMountPoint(String mountPoint) {
68
this.mountPoint = mountPoint;
69
}
70
71
public String getMountRoot() {
72
return mountRoot;
73
}
74
75
public void setMountRoot(String mountRoot) {
76
this.mountRoot = mountRoot;
77
}
78
79
public String getCgroupPath() {
80
return cgroupPath;
81
}
82
83
public void setCgroupPath(String cgroupPath) {
84
this.cgroupPath = cgroupPath;
85
}
86
87
/*
88
* Creates a CgroupInfo instance from a line in /proc/cgroups.
89
* Comment token (hash) is handled by the caller.
90
*
91
* Example (annotated):
92
*
93
* #subsys_name hierarchy num_cgroups enabled
94
* cpuset 10 1 1 (a)
95
* cpu 7 8 1 (b)
96
* [...]
97
*
98
* Line (a) would yield:
99
* info = new CgroupInfo("cpuset", 10, true);
100
* return info;
101
* Line (b) results in:
102
* info = new CgroupInfo("cpu", 7, true);
103
* return info;
104
*
105
*
106
* See CgroupSubsystemFactory.determineType()
107
*
108
*/
109
static CgroupInfo fromCgroupsLine(String line) {
110
String[] tokens = line.split("\\s+");
111
if (tokens.length != 4) {
112
return null;
113
}
114
// discard 3'rd field, num_cgroups
115
return new CgroupInfo(tokens[0] /* name */,
116
Integer.parseInt(tokens[1]) /* hierarchyId */,
117
(Integer.parseInt(tokens[3]) == 1) /* enabled */);
118
}
119
120
}
121
122