Package java.lang.management

Examples of java.lang.management.MemoryMXBean


  }

  // This shows an easy stack overflow because we're counting recursively.
  @Ignore
  public void testChainedEstimation() {
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();

    Random rnd = random();
    Entry first = new Entry();
    try {
      while (true) {
        // Check the current memory consumption and provide the estimate.
        long jvmUsed = memoryMXBean.getHeapMemoryUsage().getUsed();
        long estimated = RamUsageTester.sizeOf(first);
        System.out.println(String.format(Locale.ROOT, "%10d, %10d",
            jvmUsed, estimated));

        // Make a batch of objects.
View Full Code Here


  volatile Object guard;
 
  // This shows an easy stack overflow because we're counting recursively.
  public void testLargeSetOfByteArrays() {
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();

    causeGc();
    long before = memoryMXBean.getHeapMemoryUsage().getUsed();
    Object [] all = new Object [1000000];
    for (int i = 0; i < all.length; i++) {
      all[i] = new byte[random().nextInt(3)];
    }
    causeGc();
    long after = memoryMXBean.getHeapMemoryUsage().getUsed();
    System.out.println("mx:  " + RamUsageEstimator.humanReadableUnits(after - before));
    System.out.println("rue: " + RamUsageEstimator.humanReadableUnits(shallowSizeOf(all)));

    guard = all;
  }
View Full Code Here

    }
    return s;
  }

  public void testSimpleByteArrays() {
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();

    Object [][] all = new Object [0][];
    try {
      while (true) {
        // Check the current memory consumption and provide the estimate.
        causeGc();
        MemoryUsage mu = memoryMXBean.getHeapMemoryUsage();
        long estimated = shallowSizeOf(all);
        if (estimated > 50 * RamUsageEstimator.ONE_MB) {
          break;
        }

View Full Code Here

    long inodes = fsn.dir.totalInodes();
    long blocks = fsn.getBlocksTotal();
    long maxobjects = fsn.getMaxObjects();

    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = mem.getHeapMemoryUsage();
    long totalMemory = heap.getUsed();
    long maxMemory = heap.getMax();
    long commitedMemory = heap.getCommitted();
   
    MemoryUsage nonHeap = mem.getNonHeapMemoryUsage();
    long totalNonHeap = nonHeap.getUsed();
    long maxNonHeap = nonHeap.getMax();
    long commitedNonHeap = nonHeap.getCommitted();

    long used = (totalMemory * 100) / commitedMemory;
View Full Code Here

        doEventCountUpdates();
        metrics.update();
    }
   
    private void doMemoryUpdates() {
        MemoryMXBean memoryMXBean =
               ManagementFactory.getMemoryMXBean();
        MemoryUsage memNonHeap =
                memoryMXBean.getNonHeapMemoryUsage();
        MemoryUsage memHeap =
                memoryMXBean.getHeapMemoryUsage();
        metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed()/M);
        metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted()/M);
        metrics.setMetric("memHeapUsedM", memHeap.getUsed()/M);
        metrics.setMetric("memHeapCommittedM", memHeap.getCommitted()/M);
    }
View Full Code Here

        Map<String, String> props = new HashMap<String, String>();

        RuntimeMXBean         runtime = ManagementFactory.getRuntimeMXBean();
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
        ThreadMXBean          threads = ManagementFactory.getThreadMXBean();
        MemoryMXBean          mem = ManagementFactory.getMemoryMXBean();
        ClassLoadingMXBean    cl = ManagementFactory.getClassLoadingMXBean();

        //
        // print ServiceMix informations
        //
        maxNameLen = 25;
        io.out.println("ServiceMix");
        printValue("ServiceMix home", maxNameLen, System.getProperty("servicemix.home"));
        printValue("ServiceMix base", maxNameLen, System.getProperty("servicemix.base"));
        printValue("ServiceMix version", maxNameLen, branding.getVersion());
        io.out.println();

        io.out.println("JVM");
        printValue("Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion());
        printValue("Vendor", maxNameLen, runtime.getVmVendor());
        printValue("Uptime", maxNameLen, printDuration(runtime.getUptime()));
        try {
            com.sun.management.OperatingSystemMXBean sunOs = (com.sun.management.OperatingSystemMXBean) os;
            printValue("Process CPU time", maxNameLen, printDuration(sunOs.getProcessCpuTime() / 1000000));
            printValue("Total compile time", maxNameLen, printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime()));
        } catch (Throwable t) {}

        io.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()));

        io.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

        return kernel.getBootTime();
    }

    public Stats getStats() {
        RuntimeMXBean runmxbean = ManagementFactory.getRuntimeMXBean();
        MemoryMXBean memmxbean = ManagementFactory.getMemoryMXBean();
        MemoryUsage memUsage = memmxbean.getHeapMemoryUsage();
        CountStatisticImpl upTime;
        BoundedRangeStatisticImpl heapSize;

        if (stats == null) {
            stats = new JVMStatsImpl();
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.