当前位置: 首页>>代码示例>>Java>>正文


Java ManagementFactory.getGarbageCollectorMXBeans方法代码示例

本文整理汇总了Java中java.lang.management.ManagementFactory.getGarbageCollectorMXBeans方法的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactory.getGarbageCollectorMXBeans方法的具体用法?Java ManagementFactory.getGarbageCollectorMXBeans怎么用?Java ManagementFactory.getGarbageCollectorMXBeans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ManagementFactory的用法示例。


在下文中一共展示了ManagementFactory.getGarbageCollectorMXBeans方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sense

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public void sense(final MetricRecorder.Context metricContext)
{
    List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();

    // sum up metrics for all the garbage collectors
    //TODO: individual metrics per gc?
    long totalCollections = 0L;
    long totalTime = 0L;
    for (GarbageCollectorMXBean mxBean : gcBeans) {
        totalCollections += mxBean.getCollectionCount();
        totalTime += mxBean.getCollectionTime();
    }

    metricContext.record(COLLECTION_COUNT_TOTAL, totalCollections, Unit.NONE);
    metricContext.record(COLLECTION_TIME_TOTAL, totalTime, Unit.MILLISECOND);

    metricContext.record(COLLECTION_COUNT, (totalCollections - prevTotalCollections), Unit.NONE);
    metricContext.record(COLLECTION_TIME, (totalTime - prevTotalTime), Unit.MILLISECOND);

    prevTotalCollections = totalCollections;
    prevTotalTime = totalTime;
}
 
开发者ID:awslabs,项目名称:swage,代码行数:24,代码来源:GarbageCollectorSensor.java

示例2: printGCStats

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void printGCStats(Tracer logger) {
    long totalGarbageCollections = 0;
    long garbageCollectionTime = 0;

    for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {

        long count = gc.getCollectionCount();

        if (count >= 0) {
            totalGarbageCollections += count;
        }

        long time = gc.getCollectionTime();

        if (time >= 0) {
            garbageCollectionTime += time;
        }
    }

    logger.info("Total Garbage Collections: " + totalGarbageCollections);
    logger.info("Total Garbage Collection Time (ms): " + garbageCollectionTime);
}
 
开发者ID:nfisher,项目名称:cljbuck,代码行数:23,代码来源:Main.java

示例3: isTenuredParallelGC

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * Check if the tenured generation are currently using a parallel GC.
 */
protected static boolean isTenuredParallelGC() {
    // Currently the only parallel GC for the tenured generation is PS MarkSweep.
    List<String> parallelGCs = Arrays.asList(new String[] { "PS MarkSweep"});
    try {
        List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean bean : beans) {
            if (parallelGCs.contains(bean.getName())) {
                return true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:JstatGcCapacityResults.java

示例4: getCollectionTime

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * Approx. time spent in gc. See {@link GarbageCollectorMXBean}
 */
public long getCollectionTime() {
    long garbageCollectionTime = 0;
    for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
        long time = gc.getCollectionTime();
        if (time >= 0) {
            garbageCollectionTime += time;
        }
    }
    return garbageCollectionTime;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:GarbageCollectionInfo.java

示例5: doGarbageCollectionUpdates

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private void doGarbageCollectionUpdates() {
    List<GarbageCollectorMXBean> gcBeans =
            ManagementFactory.getGarbageCollectorMXBeans();
    long count = 0;
    long timeMillis = 0;
    for (GarbageCollectorMXBean gcBean : gcBeans) {
        count += gcBean.getCollectionCount();
        timeMillis += gcBean.getCollectionTime();
    }
    metrics.incrMetric("gcCount", (int)(count - gcCount));
    metrics.incrMetric("gcTimeMillis", (int)(timeMillis - gcTimeMillis));
    
    gcCount = count;
    gcTimeMillis = timeMillis;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:JvmMetrics.java

示例6: getGCTotalTime

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/** @return The total time, in milliseconds, spent in GC. */
public static long getGCTotalTime() {
  final List<GarbageCollectorMXBean> gcBeans =
      ManagementFactory.getGarbageCollectorMXBeans();
  long time = 0;
  for (final GarbageCollectorMXBean bean : gcBeans) {
    if (bean.getCollectionTime() < 0) {
      continue;
    }
    time += bean.getCollectionTime();
  }
  return time;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:14,代码来源:Utils.java

示例7: getCMSGCBean

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static GarbageCollectorMXBean getCMSGCBean() {
  for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
    if (gcBean.getObjectName().toString().equals("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep")) {
      return gcBean;
    }
  }
  return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TestCMSClassUnloadingEnabledHWM.java

示例8: getGcTimes

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private Map<String, GcTimes> getGcTimes() {
  Map<String, GcTimes> map = Maps.newHashMap();
  List<GarbageCollectorMXBean> gcBeans =
      ManagementFactory.getGarbageCollectorMXBeans();
  for (GarbageCollectorMXBean gcBean : gcBeans) {
    map.put(gcBean.getName(), new GcTimes(gcBean));
  }
  return map;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:10,代码来源:JvmPauseMonitor.java

示例9: JvmGcMetrics

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public JvmGcMetrics() {
    histogram = Histogram.build().name("jvm_gc_hist").help("garbage collection metrics as a histogram")
        .labelNames(new String[] { KEY_NAME, KEY_CAUSE, KEY_ACTION }).create();

    for (GarbageCollectorMXBean gcbean : ManagementFactory.getGarbageCollectorMXBeans()) {
        final NotificationEmitter emitter = (NotificationEmitter) gcbean;
        emitter.addNotificationListener(gcListener, null, null);
    }
}
 
开发者ID:Skatteetaten,项目名称:aurora-prometheus,代码行数:10,代码来源:JvmGcMetrics.java

示例10: getTotalCollectionTime

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static long getTotalCollectionTime() {
    List<GarbageCollectorMXBean> sunBeans = ManagementFactory.getGarbageCollectorMXBeans();
    long totalCollectionTime = 0;
    if (sunBeans.size() == 0) {
        return -1;
    }
    for (Iterator<GarbageCollectorMXBean> iterator = sunBeans.iterator(); iterator.hasNext();) {
        GarbageCollectorMXBean garbageCollectorMXBean = iterator.next();
        long collectionTime = garbageCollectorMXBean.getCollectionTime();
        if( collectionTime != -1) {
            totalCollectionTime += collectionTime;
        }
    }
    return totalCollectionTime;
}
 
开发者ID:RuntimeTools,项目名称:javametrics,代码行数:16,代码来源:GCDataProvider.java

示例11: getGCStats

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static String getGCStats() {
    long totalGC = 0;
    long gcTime = 0;

    for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
        long count = gc.getCollectionCount();

        if (count >= 0) {
            totalGC += count;
        }

        long time = gc.getCollectionTime();

        if (time >= 0) {
            gcTime += time;
        }
    }

    StringBuilder sb = new StringBuilder();

    sb.append(banner("memory stats"));
    sb.append("\n- total collections: " + totalGC);
    sb.append("\n- total collection time: " + formatTime(gcTime));

    Runtime runtime = Runtime.getRuntime();
    sb.append("\n- total memory: " + printMem(runtime.totalMemory()));

    return sb.toString();
}
 
开发者ID:weiboad,项目名称:fiery,代码行数:30,代码来源:Toolbox.java

示例12: getGarbageCollectorTimeMillis

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
long getGarbageCollectorTimeMillis()
{
    long t=0;
    List<GarbageCollectorMXBean> gcs = ManagementFactory.getGarbageCollectorMXBeans();
    for (GarbageCollectorMXBean gc :gcs) {
        t +=gc.getCollectionTime();
    }
    return t;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:10,代码来源:VMPerformanceTest.java

示例13: logParams

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private String logParams() {
        StringBuilder sb = new StringBuilder(500);
        sb.append("Diagnostic information\n");
        try {
            RuntimeMXBean         rmBean     = ManagementFactory.getRuntimeMXBean();
            CompilationMXBean     cmpMBean   = ManagementFactory.getCompilationMXBean();
//            ThreadMXBean          tmBean     = ManagementFactory.getThreadMXBean();
            MemoryMXBean          memoryBean = ManagementFactory.getMemoryMXBean();
            ClassLoadingMXBean    clMBean    = ManagementFactory.getClassLoadingMXBean();

//            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
//            ObjectName hsDiag = new ObjectName("com.sun.management:name=HotSpotDiagnostic");
//            com.sun.management.OperatingSystemMXBean sunOSMBean  =
//               ManagementFactory.getSunOperatingSystemMXBean();

//            Map<String, String> props = new TreeMap<String, String>(rmBean.getSystemProperties());
//            System.out.println("System properties");
//            for (Map.Entry<String, String> entry: props.entrySet()) {
//                System.out.println("Property: "+entry.getKey()+" Value: "+entry.getValue());
//            }
            sb.append("Input arguments:");
            for (String s: rmBean.getInputArguments()) {
                sb.append("\n\t").append(s);
            }
            
            if (cmpMBean != null) {
                sb.append("\nCompiler: "+cmpMBean.getName()).append('\n');
            }
            
            // Memory
            MemoryUsage usage = memoryBean.getHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Heap memory");
            usage = memoryBean.getNonHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Non heap memory");
            for (GarbageCollectorMXBean gcMBean: ManagementFactory.getGarbageCollectorMXBeans()) {
                sb.append("Garbage collector: ").append(gcMBean.getName())
                        .append(" (Collections=").append(gcMBean.getCollectionCount())
                        .append(" Total time spent=").append(formatTime(gcMBean.getCollectionTime()))
                        .append(")\n");
            }
            
            // classes
            int clsLoaded;
            long clsTotal, clsUnloaded;
            clsLoaded = clMBean.getLoadedClassCount();
            clsTotal = clMBean.getTotalLoadedClassCount();
            clsUnloaded = clMBean.getUnloadedClassCount();
            sb.append("Classes: loaded=").append(clsLoaded)
                    .append(" total loaded=").append(clsTotal)
                    .append(" unloaded ").append(clsUnloaded).append('\n');

//        } catch (MalformedObjectNameException ex) {
//            Logger.getLogger("global").log(Level.WARNING, null, ex);
        } catch (NullPointerException ex) {
            LOG.log(Level.WARNING, null, ex);
        }
        return sb.toString();
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:59,代码来源:DiagnosticTask.java

示例14: getTotalGcCount

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private long getTotalGcCount() {
    List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
    return gcMxBeans.stream().mapToLong(GarbageCollectorMXBean::getCollectionCount).sum();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AbstractBenchmark.java

示例15: jvmStats

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static JvmStats jvmStats() {
    MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
    long heapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
    long heapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
    long heapMax = memUsage.getMax() < 0 ? 0 : memUsage.getMax();
    memUsage = memoryMXBean.getNonHeapMemoryUsage();
    long nonHeapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
    long nonHeapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    List<MemoryPool> pools = new ArrayList<>();
    for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
        try {
            MemoryUsage usage = memoryPoolMXBean.getUsage();
            MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
            String name = GcNames.getByMemoryPoolName(memoryPoolMXBean.getName(), null);
            if (name == null) { // if we can't resolve it, its not interesting.... (Per Gen, Code Cache)
                continue;
            }
            pools.add(new MemoryPool(name,
                    usage.getUsed() < 0 ? 0 : usage.getUsed(),
                    usage.getMax() < 0 ? 0 : usage.getMax(),
                    peakUsage.getUsed() < 0 ? 0 : peakUsage.getUsed(),
                    peakUsage.getMax() < 0 ? 0 : peakUsage.getMax()
            ));
        } catch (Exception ex) {
            /* ignore some JVMs might barf here with:
             * java.lang.InternalError: Memory Pool not found
             * we just omit the pool in that case!*/
        }
    }
    Mem mem = new Mem(heapCommitted, heapUsed, heapMax, nonHeapCommitted, nonHeapUsed, Collections.unmodifiableList(pools));
    Threads threads = new Threads(threadMXBean.getThreadCount(), threadMXBean.getPeakThreadCount());

    List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
    GarbageCollector[] collectors = new GarbageCollector[gcMxBeans.size()];
    for (int i = 0; i < collectors.length; i++) {
        GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
        collectors[i] = new GarbageCollector(GcNames.getByGcName(gcMxBean.getName(), gcMxBean.getName()),
                gcMxBean.getCollectionCount(), gcMxBean.getCollectionTime());
    }
    GarbageCollectors garbageCollectors = new GarbageCollectors(collectors);
    List<BufferPool> bufferPoolsList = Collections.emptyList();
    try {
        List<BufferPoolMXBean> bufferPools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
        bufferPoolsList = new ArrayList<>(bufferPools.size());
        for (BufferPoolMXBean bufferPool : bufferPools) {
            bufferPoolsList.add(new BufferPool(bufferPool.getName(), bufferPool.getCount(),
                    bufferPool.getTotalCapacity(), bufferPool.getMemoryUsed()));
        }
    } catch (Exception e) {
        // buffer pools are not available
    }

    Classes classes = new Classes(classLoadingMXBean.getLoadedClassCount(), classLoadingMXBean.getTotalLoadedClassCount(),
            classLoadingMXBean.getUnloadedClassCount());

    return new JvmStats(System.currentTimeMillis(), runtimeMXBean.getUptime(), mem, threads,
            garbageCollectors, bufferPoolsList, classes);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:60,代码来源:JvmStats.java


注:本文中的java.lang.management.ManagementFactory.getGarbageCollectorMXBeans方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。