Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/jdk/internal/platform/Metrics.java
41159 views
1
/*
2
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
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
package jdk.internal.platform;
26
27
import java.lang.reflect.Method;
28
29
/**
30
* Operating System Metrics class
31
*
32
* @implNote Some of the APIs within this class return metrics for an
33
* "Isolation Group" or "Container". When the term "Isolation Group"
34
* is used in the API description, this refers to either:
35
*
36
*<ol>
37
*<li> All processes, including the current process within a container.
38
*
39
*<li> All processes, including the current process running together
40
* isolated from other non-isolated processes.
41
*
42
*<li> All processes running on a host when that there is no isolation
43
* in effect.
44
*</ol>
45
*
46
* @author bobv
47
* @since 11
48
*/
49
50
public interface Metrics {
51
52
/**
53
* Returns an instance of the Metrics class.
54
*
55
* @return Metrics object or null if not supported on this platform.
56
*/
57
public static Metrics systemMetrics() {
58
return SystemMetrics.instance();
59
}
60
61
/**
62
* Returns the interface responsible for providing the
63
* platform metrics.
64
*
65
* @implNote
66
* Metrics are currently only supported Linux.
67
* The provider for Linux is cgroups (version 1 or 2).
68
*
69
* @return The name of the provider.
70
*
71
*/
72
public String getProvider();
73
74
75
/*****************************************************************
76
* CPU Accounting Subsystem
77
****************************************************************/
78
79
/**
80
* Returns the aggregate time, in nanoseconds, consumed by all
81
* tasks in the Isolation Group.
82
*
83
* @return Time in nanoseconds, -1 if unknown or
84
* -2 if the metric is not supported.
85
*
86
*/
87
public long getCpuUsage();
88
89
/**
90
* Returns the aggregate time, in nanoseconds, consumed by all tasks in
91
* the Isolation Group, separated by CPU. If the current process
92
* is running within a container, the reported time will only be
93
* valid for processes running within the same container. The values
94
* are returned in an array, one entry for each physical processor
95
* on the system. Time values for processors unavailable to this
96
* Group are undefined.
97
*
98
* @return long array of time values. The size of the array is equal
99
* to the total number of physical processors in the system. If
100
* this metric is not supported or not available, null will be
101
* returned.
102
*
103
*/
104
public long[] getPerCpuUsage();
105
106
/**
107
* Returns the aggregate user time, in nanoseconds, consumed by all
108
* tasks in the Isolation Group.
109
*
110
* @return User time in nanoseconds, -1 if the metric is not available or
111
* -2 if the metric is not supported.
112
*
113
*/
114
public long getCpuUserUsage();
115
116
/**
117
* Returns the aggregate system time, in nanoseconds, consumed by
118
* all tasks in the Isolation Group.
119
*
120
* @return System time in nanoseconds, -1 if the metric is not available or
121
* -2 if the metric is not supported.
122
*
123
*/
124
public long getCpuSystemUsage();
125
126
/*****************************************************************
127
* CPU Scheduling Metrics
128
****************************************************************/
129
130
/**
131
* Returns the length of the scheduling period, in
132
* microseconds, for processes within the Isolation Group.
133
*
134
* @return time in microseconds, -1 if the metric is not available or
135
* -2 if the metric is not supported.
136
*
137
*/
138
public long getCpuPeriod();
139
140
/**
141
* Returns the total available run-time allowed, in microseconds,
142
* during each scheduling period for all tasks in the Isolation
143
* Group.
144
*
145
* @return time in microseconds, -1 if the quota is unlimited or
146
* -2 if not supported.
147
*
148
*/
149
public long getCpuQuota();
150
151
152
/**
153
* Returns the relative weighting of processes with the Isolation
154
* Group used for prioritizing the scheduling of processes across
155
* all Isolation Groups running on a host.
156
*
157
* @implNote
158
* Popular container orchestration systems have standardized shares
159
* to be multiples of 1024, where 1024 is interpreted as 1 CPU share
160
* of execution. Users can distribute CPU resources to multiple
161
* Isolation Groups by specifying the CPU share weighting needed by
162
* each process. To request 2 CPUS worth of execution time, CPU shares
163
* would be set to 2048.
164
*
165
* @return shares value, -1 if the metric is not available or
166
* -2 if cpu shares are not supported.
167
*
168
*/
169
public long getCpuShares();
170
171
/**
172
* Returns the number of time-slice periods that have elapsed if
173
* a CPU quota has been setup for the Isolation Group
174
*
175
* @return count of elapsed periods, -1 if the metric is not available
176
* or -2 if the metric is not supported.
177
*
178
*/
179
public long getCpuNumPeriods();
180
181
/**
182
* Returns the number of time-slice periods that the group has
183
* been throttled or limited due to the group exceeding its quota
184
* if a CPU quota has been setup for the Isolation Group.
185
*
186
* @return count of throttled periods, -1 if the metric is not available or
187
* -2 if it is not supported.
188
*
189
*/
190
public long getCpuNumThrottled();
191
192
/**
193
* Returns the total time duration, in nanoseconds, that the
194
* group has been throttled or limited due to the group exceeding
195
* its quota if a CPU quota has been setup for the Isolation Group.
196
*
197
* @return Throttled time in nanoseconds, -1 if the metric is not available
198
* or -2 if it is not supported.
199
*
200
*/
201
public long getCpuThrottledTime();
202
203
204
/**
205
* Returns the number of effective processors that this Isolation
206
* group has available to it. This effective processor count is
207
* computed based on the number of dedicated CPUs, CPU shares and
208
* CPU quotas in effect for this isolation group.
209
*
210
* This method returns the same value as
211
* {@link java.lang.Runtime#availableProcessors()}.
212
*
213
* @return The number of effective CPUs.
214
*
215
*/
216
public long getEffectiveCpuCount();
217
218
/*****************************************************************
219
* CPU Sets
220
****************************************************************/
221
222
/**
223
* Returns the CPUS that are available for execution of processes
224
* in the current Isolation Group. The size of the array is equal
225
* to the total number of CPUs and the elements in the array are the
226
* physical CPU numbers that are available. Some of the CPUs returned
227
* may be offline. To get the current online CPUs, use
228
* {@link getEffectiveCpuSetCpus()}.
229
*
230
* @return An array of available CPUs. Returns null if the metric is not
231
* available or the metric is not supported.
232
*
233
*/
234
public int[] getCpuSetCpus();
235
236
/**
237
* Returns the CPUS that are available and online for execution of
238
* processes within the current Isolation Group. The size of the
239
* array is equal to the total number of CPUs and the elements in
240
* the array are the physical CPU numbers.
241
*
242
* @return An array of available and online CPUs. Returns null
243
* if the metric is not available or the metric is not supported.
244
*
245
*/
246
public int[] getEffectiveCpuSetCpus();
247
248
/**
249
* Returns the memory nodes that are available for use by processes
250
* in the current Isolation Group. The size of the array is equal
251
* to the total number of nodes and the elements in the array are the
252
* physical node numbers that are available. Some of the nodes returned
253
* may be offline. To get the current online memory nodes, use
254
* {@link getEffectiveCpuSetMems()}.
255
*
256
* @return An array of available memory nodes or null
257
* if the metric is not available or is not supported.
258
*
259
*/
260
public int[] getCpuSetMems();
261
262
/**
263
* Returns the memory nodes that are available and online for use by
264
* processes within the current Isolation Group. The size of the
265
* array is equal to the total number of nodes and the elements in
266
* the array are the physical node numbers.
267
*
268
* @return An array of available and online nodes or null
269
* if the metric is not available or is not supported.
270
*
271
*/
272
public int[] getEffectiveCpuSetMems();
273
274
/*****************************************************************
275
* Memory Subsystem
276
****************************************************************/
277
278
/**
279
* Returns the number of times that user memory requests in the
280
* Isolation Group have exceeded the memory limit.
281
*
282
* @return The number of exceeded requests or -1 if the metric
283
* is not available. Returns -2 if the metric is not
284
* supported.
285
*
286
*/
287
public long getMemoryFailCount();
288
289
/**
290
* Returns the maximum amount of physical memory, in bytes, that
291
* can be allocated in the Isolation Group.
292
*
293
* @return The maximum amount of memory in bytes or -1 if
294
* there is no limit or -2 if this metric is not supported.
295
*
296
*/
297
public long getMemoryLimit();
298
299
/**
300
* Returns the amount of physical memory, in bytes, that is currently
301
* allocated in the current Isolation Group.
302
*
303
* @return The amount of memory in bytes allocated or -1 if
304
* the metric is not available or -2 if the metric is not
305
* supported.
306
*
307
*/
308
public long getMemoryUsage();
309
310
/**
311
* Returns the amount of networking physical memory, in bytes, that
312
* is currently allocated in the current Isolation Group.
313
*
314
* @return The amount of memory in bytes allocated or -1 if the metric
315
* is not available. Returns -2 if this metric is not supported.
316
*
317
*/
318
public long getTcpMemoryUsage();
319
320
/**
321
* Returns the maximum amount of physical memory and swap space,
322
* in bytes, that can be allocated in the Isolation Group.
323
*
324
* @return The maximum amount of memory in bytes or -1 if
325
* there is no limit set or -2 if this metric is not supported.
326
*
327
*/
328
public long getMemoryAndSwapLimit();
329
330
/**
331
* Returns the amount of physical memory and swap space, in bytes,
332
* that is currently allocated in the current Isolation Group.
333
*
334
* @return The amount of memory in bytes allocated or -1 if
335
* the metric is not available. Returns -2 if this metric is not
336
* supported.
337
*
338
*/
339
public long getMemoryAndSwapUsage();
340
341
/**
342
* Returns the hint to the operating system that allows groups
343
* to specify the minimum amount of physical memory that they need to
344
* achieve reasonable performance in low memory systems. This allows
345
* host systems to provide greater sharing of memory.
346
*
347
* @return The minimum amount of physical memory, in bytes, that the
348
* operating system will try to maintain under low memory
349
* conditions. If this metric is not available, -1 will be
350
* returned. Returns -2 if the metric is not supported.
351
*
352
*/
353
public long getMemorySoftLimit();
354
355
/*****************************************************************
356
* BlKIO Subsystem
357
****************************************************************/
358
359
/**
360
* Returns the number of block I/O requests to the disk that have been
361
* issued by the Isolation Group.
362
*
363
* @return The count of requests or -1 if the metric is not available.
364
* Returns -2 if this metric is not supported.
365
*
366
*/
367
public long getBlkIOServiceCount();
368
369
/**
370
* Returns the number of block I/O bytes that have been transferred
371
* to/from the disk by the Isolation Group.
372
*
373
* @return The number of bytes transferred or -1 if the metric is not
374
* available. Returns -2 if this metric is not supported.
375
*
376
*/
377
public long getBlkIOServiced();
378
}
379
380