sk.baka.webvm.misc
Class MgmtUtils

java.lang.Object
  extended by sk.baka.webvm.misc.MgmtUtils

public final class MgmtUtils
extends Object

Provides utilities for the java.util.management package.

Author:
Martin Vysny

Method Summary
static MemoryUsage add(MemoryUsage u1, MemoryUsage u2)
          Sums two memory usages together.
static String getFreePerc(MemoryUsage mu)
          Returns amount of free memory in the following format: xx%
static MemoryUsage getHeapFromRuntime()
          Computes and returns the memory usage object, using information only from Runtime.
static MemoryUsage getInMB(MemoryUsage mu)
          Returns a new object with all values divided by 1024*1024 (converted from bytes to mebibytes).
static SortedMap<String,MemoryPoolMXBean> getMemoryPools()
          Returns all known memory pools which are garbage-collectable and provide meaningful usage information.
static MemoryUsage getNonHeapSummary()
          Sums up all non-heap pools and return their memory usage.
static String getUsagePerc(MemoryUsage mu)
          Returns memory usage in the following format: xx%
static boolean isNonHeapPool()
          Checks if there is a non-heap pool in the memory pool list.
static String toString(MemoryUsage mu, boolean inMegs)
          Formats a memory usage instance to a compact string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNonHeapSummary

public static MemoryUsage getNonHeapSummary()
Sums up all non-heap pools and return their memory usage.

Returns:
memory usage, null if no pool collects non-heap space.

isNonHeapPool

public static boolean isNonHeapPool()
Checks if there is a non-heap pool in the memory pool list.

Returns:
true if there is pool managing non-heap memory, false otherwise.

getHeapFromRuntime

public static MemoryUsage getHeapFromRuntime()
Computes and returns the memory usage object, using information only from Runtime.

Returns:
non-null usage object.

add

public static MemoryUsage add(MemoryUsage u1,
                              MemoryUsage u2)
Sums two memory usages together. Does not allow null values.

Parameters:
u1 - first usage, must not be null
u2 - second usage, must not be null
Returns:
a summed usage, never null

getInMB

public static MemoryUsage getInMB(MemoryUsage mu)
Returns a new object with all values divided by 1024*1024 (converted from bytes to mebibytes).

Parameters:
mu - the memory usage to convert
Returns:
new memory object with values in mebibytes. Returns null if null was supplied.

toString

public static String toString(MemoryUsage mu,
                              boolean inMegs)
Formats a memory usage instance to a compact string. Uses the following format: [used (committed) / max].

Parameters:
mu - the memory usage object.
inMegs - if true then given memory usage values are already megabytes. If false then the values are in bytes.
Returns:
[used (committed) / max], or [not available] if null was given

getUsagePerc

public static String getUsagePerc(MemoryUsage mu)
Returns memory usage in the following format: xx%

Parameters:
mu - the memory usage object, may be null
Returns:
formatted percent value; "not available" if the object is null or max is -1; "none" if max is zero

getFreePerc

public static String getFreePerc(MemoryUsage mu)
Returns amount of free memory in the following format: xx%

Parameters:
mu - the memory usage object, may be null
Returns:
formatted percent value; "?" if the object is null or max is -1; "none" if max is zero

getMemoryPools

public static SortedMap<String,MemoryPoolMXBean> getMemoryPools()
Returns all known memory pools which are garbage-collectable and provide meaningful usage information.

Returns:
map of memory pools, never null, may be empty.


Copyright © 2010 Baka. All Rights Reserved.