Package java.lang.management

Examples of java.lang.management.MemoryMXBean


        int maxNameLen;

        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
        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"));
        printValue("OSGi Framework", maxNameLen, bundleContext.getBundle(0).getSymbolicName() + " - " +
                bundleContext.getBundle(0).getVersion());
        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("Uptime", maxNameLen, printDuration(runtime.getUptime()));
        try {
            printValue("Process CPU time", maxNameLen, printDuration(getSunOsValueAsLong(os, "getProcessCpuTime") / 1000000));
        } 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);
        }
View Full Code Here


            }

            name_value_pairs.put(name, value);
        }

        MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
        name_value_pairs.put("Memory - Heap",
                "Used: " + formatBytes(memoryBean.getHeapMemoryUsage().getUsed())
                + ", Committed: " + formatBytes(memoryBean.getHeapMemoryUsage().getCommitted())
                + ", Max: " + formatBytes(memoryBean.getHeapMemoryUsage().getMax()));
        name_value_pairs.put("Memory - Non Heap",
                "Used: " + formatBytes(memoryBean.getNonHeapMemoryUsage().getUsed())
                + ", Committed: " + formatBytes(memoryBean.getNonHeapMemoryUsage().getCommitted())
                + ", Max: " + formatBytes(memoryBean.getNonHeapMemoryUsage().getMax()));


        out.println(MSG.getMsg(AgentI18NResourceKeys.METRICS_HEADER));
        out.println(StringUtil.justifyKeyValueStrings(name_value_pairs));
View Full Code Here

        return;
    }

    private void setVerbosity(boolean verbose) {
        final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
        memoryMxBean.setVerbose(verbose);
    }
View Full Code Here

        final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
        memoryMxBean.setVerbose(verbose);
    }

    private void freeMemory(PrintWriter out) {
        final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();

        printGlobalMemoryUsage(out, memoryMxBean);

        // free up some global static caches
        Introspector.flushCaches();
        LogFactory.releaseAll();

        // invoke the garbage collector
        out.println(MSG.getMsg(AgentI18NResourceKeys.GC_INVOKE));
        memoryMxBean.gc();

        printGlobalMemoryUsage(out, memoryMxBean);
        return;
    }
View Full Code Here

        printGlobalMemoryUsage(out, memoryMxBean);
        return;
    }

    private void printCurrentMemoryUsage(PrintWriter out) {
        final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
        printGlobalMemoryUsage(out, memoryMxBean);

        List<MemoryPoolMXBean> poolMxBeans = ManagementFactory.getMemoryPoolMXBeans();
        if (poolMxBeans != null) {
            for (MemoryPoolMXBean bean : poolMxBeans) {
View Full Code Here

    /**
     * Returns true if we are out of memory.
     */
    boolean isOutOfMemory() {
        MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
        List<MemoryPoolMXBean> memoryPoolMxBeans = getMemoryPoolMXBeansToMonitor();
        return checkMemory(memoryMxBean) || checkPoolMemories(memoryPoolMxBeans, memoryMxBean);
    }
View Full Code Here

        int maxNameLen;

        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
        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"));
        printValue("Karaf etc", maxNameLen, System.getProperty("karaf.etc"));
        printValue("OSGi Framework", maxNameLen, bundleContext.getBundle(0).getSymbolicName() + " - " +
                bundleContext.getBundle(0).getVersion());
        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 {
            printValue("Process CPU time", maxNameLen, printDuration(getSunOsValueAsLong(os, "getProcessCpuTime") / 1000000));
        } 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);
        }
View Full Code Here

        outPW.printf(INDENT_KEY_VALUE_FORMAT, "total", formatLong(mxBean.getTotalLoadedClassCount())).println();
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "unloaded", formatLong(mxBean.getUnloadedClassCount())).println();
    }

    private void dumpMemoryInformation(final PrintWriter outPW) {
        final MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean();
        if( null == mxBean) {
            return;
        }
        final MemoryUsage heapMemoryUsage = mxBean.getHeapMemoryUsage();
        final MemoryUsage nonHeapMemoryUsage = mxBean.getNonHeapMemoryUsage();
        if( heapMemoryUsage != null ) {
            outPW.println("HEAP Memory:");
            outPW.printf(INDENT_KEY_VALUE_FORMAT, "commited", printMemory(heapMemoryUsage.getCommitted())).println();
            outPW.printf(INDENT_KEY_VALUE_FORMAT, "init", printMemory(heapMemoryUsage.getInit())).println();
            outPW.printf(INDENT_KEY_VALUE_FORMAT, "used", printMemory(heapMemoryUsage.getUsed())).println();
View Full Code Here

    private void dumpGCInformation(final PrintWriter outPW) {
        final List<GarbageCollectorMXBean> mxBeans = ManagementFactory.getGarbageCollectorMXBeans();
        if( null == mxBeans || mxBeans.isEmpty()) {
            return;
        }
        final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
        if( memoryMxBean != null ) {
            outPW.printf(INDENT_KEY_VALUE_FORMAT, "pending objects", formatLong(memoryMxBean.getObjectPendingFinalizationCount())).println();
        }
        final String gcFormat ="'%1$s' collections: %2$s\ttime: %3$s";
        outPW.println();
        for (final GarbageCollectorMXBean mxBean : mxBeans) {
            if( null == mxBean) {
View Full Code Here

        super("memory.txt");
    }

    @Override
    protected void writeDump(OutputStreamWriter outputStream) throws Exception {
        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();

        outputStream.write("Number of objects waiting finalization: " + memoryMXBean.getObjectPendingFinalizationCount() + "\n\n");

        outputStream.write("Heap:\n");
        outputStream.write("\tInit:      " + memoryMXBean.getHeapMemoryUsage().getInit() + "\n");
        outputStream.write("\tUser:      " + memoryMXBean.getHeapMemoryUsage().getUsed() + "\n");
        outputStream.write("\tCommitted: " + memoryMXBean.getHeapMemoryUsage().getCommitted() + "\n");
        outputStream.write("\tMax:       " + memoryMXBean.getHeapMemoryUsage().getMax() + "\n");

        outputStream.write("Non-Heap: \n");
        outputStream.write("\tInit:      " + memoryMXBean.getNonHeapMemoryUsage().getInit() + "\n");
        outputStream.write("\tUser:      " + memoryMXBean.getNonHeapMemoryUsage().getUsed() + "\n");
        outputStream.write("\tCommitted: " + memoryMXBean.getNonHeapMemoryUsage().getCommitted() + "\n");
        outputStream.write("\tMax:       " + memoryMXBean.getNonHeapMemoryUsage().getMax() + "\n");

    }
View Full Code Here

TOP

Related Classes of java.lang.management.MemoryMXBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.