Search in sources :

Example 36 with GarbageCollectorMXBean

use of java.lang.management.GarbageCollectorMXBean in project YCSB by brianfrankcooper.

the class Utils method getGCTotalCollectionCount.

/** @return The total number of garbage collections executed for all
   * memory pools. */
public static long getGCTotalCollectionCount() {
    final List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
    long count = 0;
    for (final GarbageCollectorMXBean bean : gcBeans) {
        if (bean.getCollectionCount() < 0) {
            continue;
        }
        count += bean.getCollectionCount();
    }
    return count;
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean)

Example 37 with GarbageCollectorMXBean

use of java.lang.management.GarbageCollectorMXBean in project storm by apache.

the class SystemBolt method prepare.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void prepare(final Map topoConf, TopologyContext context, OutputCollector collector) {
    if (_prepareWasCalled && !"local".equals(topoConf.get(Config.STORM_CLUSTER_MODE))) {
        throw new RuntimeException("A single worker should have 1 SystemBolt instance.");
    }
    _prepareWasCalled = true;
    int bucketSize = Utils.getInt(topoConf.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
    final RuntimeMXBean jvmRT = ManagementFactory.getRuntimeMXBean();
    context.registerMetric("uptimeSecs", new IMetric() {

        @Override
        public Object getValueAndReset() {
            return jvmRT.getUptime() / 1000.0;
        }
    }, bucketSize);
    context.registerMetric("startTimeSecs", new IMetric() {

        @Override
        public Object getValueAndReset() {
            return jvmRT.getStartTime() / 1000.0;
        }
    }, bucketSize);
    context.registerMetric("newWorkerEvent", new IMetric() {

        boolean doEvent = true;

        @Override
        public Object getValueAndReset() {
            if (doEvent) {
                doEvent = false;
                return 1;
            } else
                return 0;
        }
    }, bucketSize);
    final MemoryMXBean jvmMemRT = ManagementFactory.getMemoryMXBean();
    context.registerMetric("memory/heap", new MemoryUsageMetric(jvmMemRT::getHeapMemoryUsage), bucketSize);
    context.registerMetric("memory/nonHeap", new MemoryUsageMetric(jvmMemRT::getNonHeapMemoryUsage), bucketSize);
    for (GarbageCollectorMXBean b : ManagementFactory.getGarbageCollectorMXBeans()) {
        context.registerMetric("GC/" + b.getName().replaceAll("\\W", ""), new GarbageCollectorMetric(b), bucketSize);
    }
    registerMetrics(context, (Map<String, String>) topoConf.get(Config.WORKER_METRICS), bucketSize, topoConf);
    registerMetrics(context, (Map<String, String>) topoConf.get(Config.TOPOLOGY_WORKER_METRICS), bucketSize, topoConf);
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) IMetric(org.apache.storm.metric.api.IMetric) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 38 with GarbageCollectorMXBean

use of java.lang.management.GarbageCollectorMXBean in project bazel by bazelbuild.

the class RetainedHeapLimiter method install.

void install() {
    Preconditions.checkState(!installed, "RetainedHeapLimiter installed twice");
    installed = true;
    List<GarbageCollectorMXBean> gcbeans = ManagementFactory.getGarbageCollectorMXBeans();
    boolean foundTenured = false;
    // space. Normally there is one such collector.
    for (GarbageCollectorMXBean gcbean : gcbeans) {
        boolean collectsTenured = false;
        for (String name : gcbean.getMemoryPoolNames()) {
            collectsTenured |= isTenuredSpace(name);
        }
        if (collectsTenured) {
            foundTenured = true;
            NotificationEmitter emitter = (NotificationEmitter) gcbean;
            emitter.addNotificationListener(this, null, null);
        }
    }
    if (!foundTenured) {
        throw new IllegalStateException("Can't find tenured space; update this class for a new collector");
    }
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean)

Example 39 with GarbageCollectorMXBean

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();
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) ArrayList(java.util.ArrayList) MemoryManagerMXBean(java.lang.management.MemoryManagerMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) Date(java.util.Date)

Example 40 with GarbageCollectorMXBean

use of java.lang.management.GarbageCollectorMXBean in project hazelcast by hazelcast.

the class GCStatsSupport method fill.

static void fill(DefaultGarbageCollectorStats stats) {
    long minorCount = 0;
    long minorTime = 0;
    long majorCount = 0;
    long majorTime = 0;
    long unknownCount = 0;
    long unknownTime = 0;
    for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
        long count = gc.getCollectionCount();
        if (count >= 0) {
            if (YOUNG_GC.contains(gc.getName())) {
                minorCount += count;
                minorTime += gc.getCollectionTime();
            } else if (OLD_GC.contains(gc.getName())) {
                majorCount += count;
                majorTime += gc.getCollectionTime();
            } else {
                unknownCount += count;
                unknownTime += gc.getCollectionTime();
            }
        }
    }
    stats.setMajorCount(majorCount);
    stats.setMajorTime(majorTime);
    stats.setMinorCount(minorCount);
    stats.setMinorTime(minorTime);
    stats.setUnknownCount(unknownCount);
    stats.setUnknownTime(unknownTime);
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean)

Aggregations

GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)62 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)10 RuntimeMXBean (java.lang.management.RuntimeMXBean)10 MemoryMXBean (java.lang.management.MemoryMXBean)8 HashMap (java.util.HashMap)8 MemoryUsage (java.lang.management.MemoryUsage)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 ThreadMXBean (java.lang.management.ThreadMXBean)4 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)3 ObjectName (javax.management.ObjectName)3 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 NotificationEmitter (javax.management.NotificationEmitter)2 MetricGroup (org.apache.flink.metrics.MetricGroup)2 MetricsInfo (org.apache.hadoop.metrics2.MetricsInfo)2 Metric (com.codahale.metrics.Metric)1 Checkpoint (com.datatorrent.stram.api.Checkpoint)1 ContainerStatsEvent (com.datatorrent.stram.api.ContainerEvent.ContainerStatsEvent)1