Search in sources :

Example 1 with ClassLoadingMXBean

use of java.lang.management.ClassLoadingMXBean in project flink by apache.

the class TaskExecutorMetricsInitializer method instantiateClassLoaderMetrics.

private static void instantiateClassLoaderMetrics(MetricGroup metrics) {
    final ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
    metrics.<Long, Gauge<Long>>gauge("ClassesLoaded", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return mxBean.getTotalLoadedClassCount();
        }
    });
    metrics.<Long, Gauge<Long>>gauge("ClassesUnloaded", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return mxBean.getUnloadedClassCount();
        }
    });
}
Also used : ClassLoadingMXBean(java.lang.management.ClassLoadingMXBean) Gauge(org.apache.flink.metrics.Gauge)

Example 2 with ClassLoadingMXBean

use of java.lang.management.ClassLoadingMXBean in project karaf by apache.

the class EnvironmentDumpProvider method dumpClassesInformation.

private void dumpClassesInformation(final PrintWriter outPW) {
    final ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
    if (null == mxBean) {
        return;
    }
    outPW.println("Classes:");
    outPW.printf(INDENT_KEY_VALUE_FORMAT, "loaded", formatLong(mxBean.getLoadedClassCount())).println();
    outPW.printf(INDENT_KEY_VALUE_FORMAT, "total", formatLong(mxBean.getTotalLoadedClassCount())).println();
    outPW.printf(INDENT_KEY_VALUE_FORMAT, "unloaded", formatLong(mxBean.getUnloadedClassCount())).println();
}
Also used : ClassLoadingMXBean(java.lang.management.ClassLoadingMXBean)

Example 3 with ClassLoadingMXBean

use of java.lang.management.ClassLoadingMXBean in project karaf by apache.

the class InfoAction method execute.

@Override
public Object execute() throws Exception {
    int maxNameLen;
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    ThreadMXBean threads = ManagementFactory.getThreadMXBean();
    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
    // 
    // print Karaf informations
    // 
    maxNameLen = 25;
    System.out.println("Karaf");
    printValue("Karaf version", maxNameLen, System.getProperty("karaf.version"));
    printValue("Karaf home", maxNameLen, System.getProperty("karaf.home"));
    printValue("Karaf base", maxNameLen, System.getProperty("karaf.base"));
    String osgi = getOsgiFramework();
    if (osgi != null) {
        printValue("OSGi Framework", maxNameLen, osgi);
    }
    System.out.println();
    System.out.println("JVM");
    printValue("Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion());
    printValue("Version", maxNameLen, System.getProperty("java.version"));
    printValue("Vendor", maxNameLen, runtime.getVmVendor());
    printValue("Pid", maxNameLen, getPid());
    printValue("Uptime", maxNameLen, printDuration(runtime.getUptime()));
    try {
        Class<?> sunOS = Class.forName("com.sun.management.OperatingSystemMXBean");
        printValue("Process CPU time", maxNameLen, printDuration(getValueAsLong(sunOS, "getProcessCpuTime") / 1000000));
        printValue("Process CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS, "getProcessCpuLoad")));
        printValue("System CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS, "getSystemCpuLoad")));
    } catch (Throwable t) {
    }
    try {
        Class<?> unixOS = Class.forName("com.sun.management.UnixOperatingSystemMXBean");
        printValue("Open file descriptors", maxNameLen, printLong(getValueAsLong(unixOS, "getOpenFileDescriptorCount")));
        printValue("Max file descriptors", maxNameLen, printLong(getValueAsLong(unixOS, "getMaxFileDescriptorCount")));
    } catch (Throwable t) {
    }
    printValue("Total compile time", maxNameLen, printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime()));
    System.out.println("Threads");
    printValue("Live threads", maxNameLen, Integer.toString(threads.getThreadCount()));
    printValue("Daemon threads", maxNameLen, Integer.toString(threads.getDaemonThreadCount()));
    printValue("Peak", maxNameLen, Integer.toString(threads.getPeakThreadCount()));
    printValue("Total started", maxNameLen, Long.toString(threads.getTotalStartedThreadCount()));
    System.out.println("Memory");
    printValue("Current heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getUsed()));
    printValue("Maximum heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getMax()));
    printValue("Committed heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getCommitted()));
    printValue("Pending objects", maxNameLen, Integer.toString(mem.getObjectPendingFinalizationCount()));
    for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
        String val = "Name = '" + gc.getName() + "', Collections = " + gc.getCollectionCount() + ", Time = " + printDuration(gc.getCollectionTime());
        printValue("Garbage collector", maxNameLen, val);
    }
    if (showMemoryPools) {
        List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
        System.out.println("Memory Pools");
        printValue("Total Memory Pools", maxNameLen, printLong(memoryPools.size()));
        String spaces4 = "   ";
        for (MemoryPoolMXBean pool : memoryPools) {
            String name = pool.getName();
            MemoryType type = pool.getType();
            printValue(spaces4 + "Pool (" + type + ")", maxNameLen, name);
            // PeakUsage/CurrentUsage
            MemoryUsage peakUsage = pool.getPeakUsage();
            MemoryUsage usage = pool.getUsage();
            if (usage != null && peakUsage != null) {
                long init = peakUsage.getInit();
                long used = peakUsage.getUsed();
                long committed = peakUsage.getCommitted();
                long max = peakUsage.getMax();
                System.out.println(spaces4 + spaces4 + "Peak Usage");
                printValue(spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
                printValue(spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
                printValue(spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
                printValue(spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
                init = usage.getInit();
                used = usage.getUsed();
                committed = usage.getCommitted();
                max = usage.getMax();
                System.out.println(spaces4 + spaces4 + "Current Usage");
                printValue(spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
                printValue(spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
                printValue(spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
                printValue(spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
            }
        }
    }
    System.out.println("Classes");
    printValue("Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount()));
    printValue("Total classes loaded", maxNameLen, printLong(cl.getTotalLoadedClassCount()));
    printValue("Total classes unloaded", maxNameLen, printLong(cl.getUnloadedClassCount()));
    System.out.println("Operating system");
    printValue("Name", maxNameLen, os.getName() + " version " + os.getVersion());
    printValue("Architecture", maxNameLen, os.getArch());
    printValue("Processors", maxNameLen, Integer.toString(os.getAvailableProcessors()));
    try {
        printValue("Total physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalPhysicalMemorySize")));
        printValue("Free physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getFreePhysicalMemorySize")));
        printValue("Committed virtual memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getCommittedVirtualMemorySize")));
        printValue("Total swap space", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalSwapSpaceSize")));
        printValue("Free swap space", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getFreeSwapSpaceSize")));
    } catch (Throwable t) {
    }
    // Display Information from external information providers.
    Map<String, Map<Object, Object>> properties = new HashMap<>();
    if (infoProviders != null) {
        // dump all properties to Map, KARAF-425
        for (InfoProvider provider : infoProviders) {
            if (!properties.containsKey(provider.getName())) {
                properties.put(provider.getName(), new Properties());
            }
            properties.get(provider.getName()).putAll(provider.getProperties());
        }
        List<String> sections = new ArrayList<>(properties.keySet());
        Collections.sort(sections);
        for (String section : sections) {
            List<Object> keys = new ArrayList<>(properties.get(section).keySet());
            if (keys.size() > 0) {
                System.out.println(section);
                keys.sort(Comparator.comparing(String::valueOf));
                for (Object key : keys) {
                    printValue(String.valueOf(key), maxNameLen, String.valueOf(properties.get(section).get(key)));
                }
            }
        }
    }
    return null;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) HashMap(java.util.HashMap) InfoProvider(org.apache.karaf.shell.commands.info.InfoProvider) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) ArrayList(java.util.ArrayList) RuntimeMXBean(java.lang.management.RuntimeMXBean) Properties(java.util.Properties) MemoryUsage(java.lang.management.MemoryUsage) MemoryMXBean(java.lang.management.MemoryMXBean) ClassLoadingMXBean(java.lang.management.ClassLoadingMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) HashMap(java.util.HashMap) Map(java.util.Map) MemoryType(java.lang.management.MemoryType)

Example 4 with ClassLoadingMXBean

use of java.lang.management.ClassLoadingMXBean in project openj9 by eclipse.

the class TestManagementFactory method testClassLoadingMXBeanProxy.

@Test
public void testClassLoadingMXBeanProxy() {
    try {
        ClassLoadingMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "java.lang:type=ClassLoading", ClassLoadingMXBean.class);
        AssertJUnit.assertNotNull(proxy);
        AssertJUnit.assertNotNull(proxy.toString());
        AssertJUnit.assertEquals("java.lang:type=ClassLoading", proxy.getObjectName().toString());
        // It isn't reasonable to assert that the same values are returned via different paths.
        // It might be reasonable to assert that each of those metrics are non-decreasing over time.
        // It needs to check proxy <= direct <= proxy (with a call at each stage).
        long totalLoadedClassCount = ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount();
        AssertJUnit.assertTrue(totalLoadedClassCount <= proxy.getTotalLoadedClassCount());
        totalLoadedClassCount = proxy.getTotalLoadedClassCount();
        AssertJUnit.assertTrue(totalLoadedClassCount <= ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount());
        totalLoadedClassCount = ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount();
        AssertJUnit.assertTrue(totalLoadedClassCount <= proxy.getTotalLoadedClassCount());
        long unloadedClassCount = ManagementFactory.getClassLoadingMXBean().getUnloadedClassCount();
        AssertJUnit.assertTrue(unloadedClassCount <= proxy.getUnloadedClassCount());
        unloadedClassCount = proxy.getUnloadedClassCount();
        AssertJUnit.assertTrue(unloadedClassCount <= ManagementFactory.getClassLoadingMXBean().getUnloadedClassCount());
        unloadedClassCount = ManagementFactory.getClassLoadingMXBean().getUnloadedClassCount();
        AssertJUnit.assertTrue(unloadedClassCount <= proxy.getUnloadedClassCount());
        AssertJUnit.assertEquals(proxy.isVerbose(), ManagementFactory.getClassLoadingMXBean().isVerbose());
        boolean initialVal = proxy.isVerbose();
        proxy.setVerbose(!initialVal);
        AssertJUnit.assertTrue(proxy.isVerbose() != initialVal);
        proxy.setVerbose(initialVal);
    } catch (IOException e) {
        Assert.fail("Unexpected IOException : " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : ClassLoadingMXBean(java.lang.management.ClassLoadingMXBean) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 5 with ClassLoadingMXBean

use of java.lang.management.ClassLoadingMXBean in project openj9 by eclipse.

the class TestManagementFactory method testGetClassLoadingMXBean.

@Test
public final void testGetClassLoadingMXBean() {
    ClassLoadingMXBean clb = ManagementFactory.getClassLoadingMXBean();
    AssertJUnit.assertNotNull(clb);
    // Verify that there is only instance of the class loading bean
    ClassLoadingMXBean clb2 = ManagementFactory.getClassLoadingMXBean();
    AssertJUnit.assertNotNull(clb2);
    AssertJUnit.assertSame(clb, clb2);
}
Also used : ClassLoadingMXBean(java.lang.management.ClassLoadingMXBean) Test(org.testng.annotations.Test)

Aggregations

ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)19 MemoryMXBean (java.lang.management.MemoryMXBean)5 RuntimeMXBean (java.lang.management.RuntimeMXBean)5 ThreadMXBean (java.lang.management.ThreadMXBean)4 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)3 MemoryUsage (java.lang.management.MemoryUsage)3 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)3 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Gauge (org.apache.flink.metrics.Gauge)2 ClasseStatisticsVO (org.olat.restapi.system.vo.ClasseStatisticsVO)2 Test (org.testng.annotations.Test)2 Function (com.google.common.base.Function)1 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)1 IOException (java.io.IOException)1 CompilationMXBean (java.lang.management.CompilationMXBean)1 MemoryType (java.lang.management.MemoryType)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1