Path: blob/master/src/java.base/linux/classes/jdk/internal/platform/CgroupMetrics.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;2627import java.util.Objects;2829public class CgroupMetrics implements Metrics {3031private final CgroupSubsystem subsystem;3233CgroupMetrics(CgroupSubsystem subsystem) {34this.subsystem = Objects.requireNonNull(subsystem);35}3637@Override38public String getProvider() {39return subsystem.getProvider();40}4142@Override43public long getCpuUsage() {44return subsystem.getCpuUsage();45}4647@Override48public long[] getPerCpuUsage() {49return subsystem.getPerCpuUsage();50}5152@Override53public long getCpuUserUsage() {54return subsystem.getCpuUserUsage();55}5657@Override58public long getCpuSystemUsage() {59return subsystem.getCpuSystemUsage();60}6162@Override63public long getCpuPeriod() {64return subsystem.getCpuPeriod();65}6667@Override68public long getCpuQuota() {69return subsystem.getCpuQuota();70}7172@Override73public long getCpuShares() {74return subsystem.getCpuShares();75}7677@Override78public long getCpuNumPeriods() {79return subsystem.getCpuNumPeriods();80}8182@Override83public long getCpuNumThrottled() {84return subsystem.getCpuNumThrottled();85}8687@Override88public long getCpuThrottledTime() {89return subsystem.getCpuThrottledTime();90}9192@Override93public long getEffectiveCpuCount() {94return subsystem.getEffectiveCpuCount();95}9697@Override98public int[] getCpuSetCpus() {99return subsystem.getCpuSetCpus();100}101102@Override103public int[] getEffectiveCpuSetCpus() {104return subsystem.getEffectiveCpuSetCpus();105}106107@Override108public int[] getCpuSetMems() {109return subsystem.getCpuSetMems();110}111112@Override113public int[] getEffectiveCpuSetMems() {114return subsystem.getEffectiveCpuSetMems();115}116117public long getMemoryFailCount() {118return subsystem.getMemoryFailCount();119}120121@Override122public long getMemoryLimit() {123return subsystem.getMemoryLimit();124}125126@Override127public long getMemoryUsage() {128return subsystem.getMemoryUsage();129}130131@Override132public long getTcpMemoryUsage() {133return subsystem.getTcpMemoryUsage();134}135136@Override137public long getMemoryAndSwapLimit() {138return subsystem.getMemoryAndSwapLimit();139}140141@Override142public long getMemoryAndSwapUsage() {143return subsystem.getMemoryAndSwapUsage();144}145146@Override147public long getMemorySoftLimit() {148return subsystem.getMemorySoftLimit();149}150151@Override152public long getBlkIOServiceCount() {153return subsystem.getBlkIOServiceCount();154}155156@Override157public long getBlkIOServiced() {158return subsystem.getBlkIOServiced();159}160161public static Metrics getInstance() {162if (!isUseContainerSupport()) {163// Return null on -XX:-UseContainerSupport164return null;165}166return CgroupSubsystemFactory.create();167}168169private static native boolean isUseContainerSupport();170171}172173174