use of java.lang.management.GarbageCollectorMXBean in project karaf by apache.
the class InfoAction method execute.
@Override
public Object execute() throws Exception {
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"));
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 {
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);
}
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;
}
use of java.lang.management.GarbageCollectorMXBean in project heron by twitter.
the class JVMMetrics method updateGcCounts.
private void updateGcCounts() {
long totalCount = 0;
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
long collectionCount = bean.getCollectionCount();
totalCount += collectionCount;
// Replace all non alpha-numeric characters to '-'
String normalizedKeyName = bean.getName().replaceAll("[^\\w]", "-");
jvmGCCountPerGCType.safeScope(normalizedKeyName).setValue(collectionCount);
}
jvmGCCount.setValue(totalCount);
}
use of java.lang.management.GarbageCollectorMXBean in project intellij-community by JetBrains.
the class GuiTestRunner method printPerfStats.
private void printPerfStats() {
long gcCount = 0, gcTime = 0;
for (GarbageCollectorMXBean garbageCollectorMXBean : myGarbageCollectorMXBeans) {
gcCount += garbageCollectorMXBean.getCollectionCount();
gcTime += garbageCollectorMXBean.getCollectionTime();
}
System.out.printf("%d garbage collections; cumulative %d ms%n", gcCount, gcTime);
myMemoryMXBean.gc();
System.out.printf("heap: %s%n", myMemoryMXBean.getHeapMemoryUsage());
System.out.printf("non-heap: %s%n", myMemoryMXBean.getNonHeapMemoryUsage());
}
use of java.lang.management.GarbageCollectorMXBean in project android by JetBrains.
the class TestPerformance method printPerfStats.
private void printPerfStats() {
long gcCount = 0, gcTime = 0;
for (GarbageCollectorMXBean garbageCollectorMXBean : myGarbageCollectorMXBeans) {
gcCount += garbageCollectorMXBean.getCollectionCount();
gcTime += garbageCollectorMXBean.getCollectionTime();
}
System.out.printf("cumulative garbage collections: %d, %d ms", gcCount, gcTime);
if (myGcTime > 0L) {
System.out.printf(" (this test %d, %dms)", gcCount - myGcCount, gcTime - myGcTime);
}
System.out.println();
myGcCount = gcCount;
myGcTime = gcTime;
myMemoryMXBean.gc();
System.out.printf("heap: %s%n", myMemoryMXBean.getHeapMemoryUsage());
System.out.printf("non-heap: %s%n", myMemoryMXBean.getNonHeapMemoryUsage());
}
use of java.lang.management.GarbageCollectorMXBean in project tomcat by apache.
the class Diagnostics method getVMInfo.
/**
* Retrieve a JVM information text formatted
* using the given StringManager.
*
* @param requestedSm the StringManager to use
* @return the formatted JVM information text
*/
public static String getVMInfo(StringManager requestedSm) {
StringBuilder sb = new StringBuilder();
synchronized (timeformat) {
sb.append(timeformat.format(new Date()));
}
sb.append(CRLF);
sb.append(requestedSm.getString("diagnostics.vmInfoRuntime"));
sb.append(":" + CRLF);
sb.append(INDENT1 + "vmName: " + runtimeMXBean.getVmName() + CRLF);
sb.append(INDENT1 + "vmVersion: " + runtimeMXBean.getVmVersion() + CRLF);
sb.append(INDENT1 + "vmVendor: " + runtimeMXBean.getVmVendor() + CRLF);
sb.append(INDENT1 + "specName: " + runtimeMXBean.getSpecName() + CRLF);
sb.append(INDENT1 + "specVersion: " + runtimeMXBean.getSpecVersion() + CRLF);
sb.append(INDENT1 + "specVendor: " + runtimeMXBean.getSpecVendor() + CRLF);
sb.append(INDENT1 + "managementSpecVersion: " + runtimeMXBean.getManagementSpecVersion() + CRLF);
sb.append(INDENT1 + "name: " + runtimeMXBean.getName() + CRLF);
sb.append(INDENT1 + "startTime: " + runtimeMXBean.getStartTime() + CRLF);
sb.append(INDENT1 + "uptime: " + runtimeMXBean.getUptime() + CRLF);
sb.append(INDENT1 + "isBootClassPathSupported: " + runtimeMXBean.isBootClassPathSupported() + CRLF);
sb.append(CRLF);
sb.append(requestedSm.getString("diagnostics.vmInfoOs"));
sb.append(":" + CRLF);
sb.append(INDENT1 + "name: " + operatingSystemMXBean.getName() + CRLF);
sb.append(INDENT1 + "version: " + operatingSystemMXBean.getVersion() + CRLF);
sb.append(INDENT1 + "architecture: " + operatingSystemMXBean.getArch() + CRLF);
sb.append(INDENT1 + "availableProcessors: " + operatingSystemMXBean.getAvailableProcessors() + CRLF);
sb.append(INDENT1 + "systemLoadAverage: " + operatingSystemMXBean.getSystemLoadAverage() + CRLF);
sb.append(CRLF);
sb.append(requestedSm.getString("diagnostics.vmInfoThreadMxBean"));
sb.append(":" + CRLF);
sb.append(INDENT1 + "isCurrentThreadCpuTimeSupported: " + threadMXBean.isCurrentThreadCpuTimeSupported() + CRLF);
sb.append(INDENT1 + "isThreadCpuTimeSupported: " + threadMXBean.isThreadCpuTimeSupported() + CRLF);
sb.append(INDENT1 + "isThreadCpuTimeEnabled: " + threadMXBean.isThreadCpuTimeEnabled() + CRLF);
sb.append(INDENT1 + "isObjectMonitorUsageSupported: " + threadMXBean.isObjectMonitorUsageSupported() + CRLF);
sb.append(INDENT1 + "isSynchronizerUsageSupported: " + threadMXBean.isSynchronizerUsageSupported() + CRLF);
sb.append(INDENT1 + "isThreadContentionMonitoringSupported: " + threadMXBean.isThreadContentionMonitoringSupported() + CRLF);
sb.append(INDENT1 + "isThreadContentionMonitoringEnabled: " + threadMXBean.isThreadContentionMonitoringEnabled() + CRLF);
sb.append(CRLF);
sb.append(requestedSm.getString("diagnostics.vmInfoThreadCounts"));
sb.append(":" + CRLF);
sb.append(INDENT1 + "daemon: " + threadMXBean.getDaemonThreadCount() + CRLF);
sb.append(INDENT1 + "total: " + threadMXBean.getThreadCount() + CRLF);
sb.append(INDENT1 + "peak: " + threadMXBean.getPeakThreadCount() + CRLF);
sb.append(INDENT1 + "totalStarted: " + threadMXBean.getTotalStartedThreadCount() + CRLF);
sb.append(CRLF);
sb.append(requestedSm.getString("diagnostics.vmInfoStartup"));
sb.append(":" + CRLF);
for (String arg : runtimeMXBean.getInputArguments()) {
sb.append(INDENT1 + arg + CRLF);
}
sb.append(CRLF);
sb.append(requestedSm.getString("diagnostics.vmInfoPath"));
sb.append(":" + CRLF);
sb.append(INDENT1 + "bootClassPath: " + runtimeMXBean.getBootClassPath() + CRLF);
sb.append(INDENT1 + "classPath: " + runtimeMXBean.getClassPath() + CRLF);
sb.append(INDENT1 + "libraryPath: " + runtimeMXBean.getLibraryPath() + CRLF);
sb.append(CRLF);
sb.append(requestedSm.getString("diagnostics.vmInfoClassLoading"));
sb.append(":" + CRLF);
sb.append(INDENT1 + "loaded: " + classLoadingMXBean.getLoadedClassCount() + CRLF);
sb.append(INDENT1 + "unloaded: " + classLoadingMXBean.getUnloadedClassCount() + CRLF);
sb.append(INDENT1 + "totalLoaded: " + classLoadingMXBean.getTotalLoadedClassCount() + CRLF);
sb.append(INDENT1 + "isVerbose: " + classLoadingMXBean.isVerbose() + CRLF);
sb.append(CRLF);
sb.append(requestedSm.getString("diagnostics.vmInfoClassCompilation"));
sb.append(":" + CRLF);
sb.append(INDENT1 + "name: " + compilationMXBean.getName() + CRLF);
sb.append(INDENT1 + "totalCompilationTime: " + compilationMXBean.getTotalCompilationTime() + CRLF);
sb.append(INDENT1 + "isCompilationTimeMonitoringSupported: " + compilationMXBean.isCompilationTimeMonitoringSupported() + CRLF);
sb.append(CRLF);
for (MemoryManagerMXBean mbean : memoryManagerMXBeans) {
sb.append(requestedSm.getString("diagnostics.vmInfoMemoryManagers", mbean.getName()));
sb.append(":" + CRLF);
sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF);
sb.append(INDENT1 + "mbean.getMemoryPoolNames: " + CRLF);
String[] names = mbean.getMemoryPoolNames();
Arrays.sort(names);
for (String name : names) {
sb.append(INDENT2 + name + CRLF);
}
sb.append(CRLF);
}
for (GarbageCollectorMXBean mbean : garbageCollectorMXBeans) {
sb.append(requestedSm.getString("diagnostics.vmInfoGarbageCollectors", mbean.getName()));
sb.append(":" + CRLF);
sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF);
sb.append(INDENT1 + "mbean.getMemoryPoolNames: " + CRLF);
String[] names = mbean.getMemoryPoolNames();
Arrays.sort(names);
for (String name : names) {
sb.append(INDENT2 + name + CRLF);
}
sb.append(INDENT1 + "getCollectionCount: " + mbean.getCollectionCount() + CRLF);
sb.append(INDENT1 + "getCollectionTime: " + mbean.getCollectionTime() + CRLF);
sb.append(CRLF);
}
sb.append(requestedSm.getString("diagnostics.vmInfoMemory"));
sb.append(":" + CRLF);
sb.append(INDENT1 + "isVerbose: " + memoryMXBean.isVerbose() + CRLF);
sb.append(INDENT1 + "getObjectPendingFinalizationCount: " + memoryMXBean.getObjectPendingFinalizationCount() + CRLF);
sb.append(formatMemoryUsage("heap", memoryMXBean.getHeapMemoryUsage()));
sb.append(formatMemoryUsage("non-heap", memoryMXBean.getNonHeapMemoryUsage()));
sb.append(CRLF);
for (MemoryPoolMXBean mbean : memoryPoolMXBeans) {
sb.append(requestedSm.getString("diagnostics.vmInfoMemoryPools", mbean.getName()));
sb.append(":" + CRLF);
sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF);
sb.append(INDENT1 + "getType: " + mbean.getType() + CRLF);
sb.append(INDENT1 + "mbean.getMemoryManagerNames: " + CRLF);
String[] names = mbean.getMemoryManagerNames();
Arrays.sort(names);
for (String name : names) {
sb.append(INDENT2 + name + CRLF);
}
sb.append(INDENT1 + "isUsageThresholdSupported: " + mbean.isUsageThresholdSupported() + CRLF);
try {
sb.append(INDENT1 + "isUsageThresholdExceeded: " + mbean.isUsageThresholdExceeded() + CRLF);
} catch (UnsupportedOperationException ex) {
// IGNORE
}
sb.append(INDENT1 + "isCollectionUsageThresholdSupported: " + mbean.isCollectionUsageThresholdSupported() + CRLF);
try {
sb.append(INDENT1 + "isCollectionUsageThresholdExceeded: " + mbean.isCollectionUsageThresholdExceeded() + CRLF);
} catch (UnsupportedOperationException ex) {
// IGNORE
}
try {
sb.append(INDENT1 + "getUsageThreshold: " + mbean.getUsageThreshold() + CRLF);
} catch (UnsupportedOperationException ex) {
// IGNORE
}
try {
sb.append(INDENT1 + "getUsageThresholdCount: " + mbean.getUsageThresholdCount() + CRLF);
} catch (UnsupportedOperationException ex) {
// IGNORE
}
try {
sb.append(INDENT1 + "getCollectionUsageThreshold: " + mbean.getCollectionUsageThreshold() + CRLF);
} catch (UnsupportedOperationException ex) {
// IGNORE
}
try {
sb.append(INDENT1 + "getCollectionUsageThresholdCount: " + mbean.getCollectionUsageThresholdCount() + CRLF);
} catch (UnsupportedOperationException ex) {
// IGNORE
}
sb.append(formatMemoryUsage("current", mbean.getUsage()));
sb.append(formatMemoryUsage("collection", mbean.getCollectionUsage()));
sb.append(formatMemoryUsage("peak", mbean.getPeakUsage()));
sb.append(CRLF);
}
sb.append(requestedSm.getString("diagnostics.vmInfoSystem"));
sb.append(":" + CRLF);
Map<String, String> props = runtimeMXBean.getSystemProperties();
ArrayList<String> keys = new ArrayList<>(props.keySet());
Collections.sort(keys);
for (String prop : keys) {
sb.append(INDENT1 + prop + ": " + props.get(prop) + CRLF);
}
sb.append(CRLF);
sb.append(requestedSm.getString("diagnostics.vmInfoLogger"));
sb.append(":" + CRLF);
List<String> loggers = loggingMXBean.getLoggerNames();
Collections.sort(loggers);
for (String logger : loggers) {
sb.append(INDENT1 + logger + ": level=" + loggingMXBean.getLoggerLevel(logger) + ", parent=" + loggingMXBean.getParentLoggerName(logger) + CRLF);
}
sb.append(CRLF);
return sb.toString();
}
Aggregations