Search in sources :

Example 1 with OperatingSystemMXBean

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);
    }
}
Also used : OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Example 2 with OperatingSystemMXBean

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();
}
Also used : OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Example 3 with OperatingSystemMXBean

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();
        }
    }
}
Also used : OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Example 4 with OperatingSystemMXBean

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();
        }
    }
}
Also used : OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Example 5 with OperatingSystemMXBean

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.");
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Aggregations

OperatingSystemMXBean (com.sun.management.OperatingSystemMXBean)10 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanException (javax.management.MBeanException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ReflectionException (javax.management.ReflectionException)1 Gauge (org.apache.flink.metrics.Gauge)1