use of com.sun.management.OperatingSystemMXBean in project gephi by gephi.
the class MemoryStarvationManager method getMaximumXmx.
private long getMaximumXmx() {
OperatingSystemMXBean mxbean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long totalMemory = mxbean.getTotalPhysicalMemorySize();
String arch = System.getProperty("sun.arch.data.model");
if (getMb(totalMemory) < 2100 || arch.equals("32")) {
return getBytes(1300);
} else {
return (long) (totalMemory * 0.7);
}
}
use of com.sun.management.OperatingSystemMXBean in project midpoint by Evolveum.
the class PerformanceStatistics method fetchCpuUsage.
//PerformanceStatistics constructor
/* BEHAVIOR */
/*
* Fetches cpuUsage during 10 ms Thread.sleep() period
* */
private double fetchCpuUsage() {
OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
int availableProcessors = operatingSystemMXBean.getAvailableProcessors();
long prevUpTime = runtimeMXBean.getUptime();
long prevProcessCpuTime = operatingSystemMXBean.getProcessCpuTime();
try {
Thread.sleep(10);
} catch (Exception ignored) {
}
operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long upTime = runtimeMXBean.getUptime();
long processCpuTime = operatingSystemMXBean.getProcessCpuTime();
long elapsedCpu = processCpuTime - prevProcessCpuTime;
long elapsedTime = upTime - prevUpTime;
double cpuUsage = Math.min(99F, elapsedCpu / (elapsedTime * 10000F * availableProcessors));
return cpuUsage;
//return operatingSystemMXBean.getSystemCpuLoad();
}
use of com.sun.management.OperatingSystemMXBean in project jdk8u_jdk by JetBrains.
the class GetProcessCpuLoad method main.
public static void main(String[] argv) throws Exception {
OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
double load;
for (int i = 0; i < 10; i++) {
load = mbean.getProcessCpuLoad();
if ((load < 0.0 || load > 1.0) && load != -1.0) {
throw new RuntimeException("getProcessCpuLoad() returns " + load + " which is not in the [0.0,1.0] interval");
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
use of com.sun.management.OperatingSystemMXBean in project jdk8u_jdk by JetBrains.
the class GetSystemCpuLoad method main.
public static void main(String[] argv) throws Exception {
OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
double load;
for (int i = 0; i < 10; i++) {
load = mbean.getSystemCpuLoad();
if ((load < 0.0 || load > 1.0) && load != -1.0) {
throw new RuntimeException("getSystemCpuLoad() returns " + load + " which is not in the [0.0,1.0] interval");
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
use of com.sun.management.OperatingSystemMXBean in project jdk8u_jdk by JetBrains.
the class MemoryStatusOverflow method main.
public static void main(String... args) throws Exception {
OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
List<String> failedGetterNames = new ArrayList<String>();
List<String> testedGetterNames = Arrays.asList("getTotalSwapSpaceSize", "getFreeSwapSpaceSize", "getTotalPhysicalMemorySize", "getFreePhysicalMemorySize");
for (String getterName : testedGetterNames) {
Method getter = OperatingSystemMXBean.class.getMethod(getterName);
long value = (Long) getter.invoke(bean);
if (value == MEMORYSTATUS_OVERFLOW) {
failedGetterNames.add(getterName);
}
}
if (!failedGetterNames.isEmpty()) {
throw new AssertionError(failedGetterNames);
}
System.out.println("Test passed.");
}
Aggregations