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


Java GarbageCollectorMXBean.getCollectionCount方法代码示例

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


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

示例1: run

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
@Override
public void run() {
    List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
    GarbageCollectorMXBean garbageCollectorMXBean = CollectionUtils.findFirst(garbageCollectorMXBeans, new Spec<GarbageCollectorMXBean>() {
        @Override
        public boolean isSatisfiedBy(GarbageCollectorMXBean mbean) {
            return mbean.getName().equals(garbageCollector);
        }
    });

    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
        String pool = memoryPoolMXBean.getName();
        if (memoryPools.contains(pool)) {
            GarbageCollectionEvent event = new GarbageCollectionEvent(System.currentTimeMillis(), memoryPoolMXBean.getCollectionUsage(), garbageCollectorMXBean.getCollectionCount());
            events.get(pool).slideAndInsert(event);
        }
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:20,代码来源:GarbageCollectionCheck.java

示例2: sense

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的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

示例3: getGcUsage

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
private void getGcUsage(MetricsRecordBuilder rb) {
  long count = 0;
  long timeMillis = 0;
  for (GarbageCollectorMXBean gcBean : gcBeans) {
    long c = gcBean.getCollectionCount();
    long t = gcBean.getCollectionTime();
    MetricsInfo[] gcInfo = getGcInfo(gcBean.getName());
    rb.addCounter(gcInfo[0], c).addCounter(gcInfo[1], t);
    count += c;
    timeMillis += t;
  }
  rb.addCounter(GcCount, count)
    .addCounter(GcTimeMillis, timeMillis);
  
  if (pauseMonitor != null) {
    rb.addCounter(GcNumWarnThresholdExceeded,
        pauseMonitor.getNumGcWarnThresholdExceeded());
    rb.addCounter(GcNumInfoThresholdExceeded,
        pauseMonitor.getNumGcInfoThresholdExceeded());
    rb.addCounter(GcTotalExtraSleepTime,
        pauseMonitor.getTotalGcExtraSleepTime());
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:JvmMetrics.java

示例4: printGCStats

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
public static void printGCStats() {
    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;
        }
    }

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

示例5: printGCStats

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的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

示例6: getGcUsage

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
private void getGcUsage(MetricsRecordBuilder rb) {
  long count = 0;
  long timeMillis = 0;
  for (GarbageCollectorMXBean gcBean : gcBeans) {
    long c = gcBean.getCollectionCount();
    long t = gcBean.getCollectionTime();
    MetricsInfo[] gcInfo = getGcInfo(gcBean.getName());
    rb.addCounter(gcInfo[0], c).addCounter(gcInfo[1], t);
    count += c;
    timeMillis += t;
  }
  rb.addCounter(GcCount, count)
    .addCounter(GcTimeMillis, timeMillis);
  
  if (pauseMonitor != null) {
    rb.addCounter(GcNumWarnThresholdExceeded,
        pauseMonitor.getNumGcWarnThreadholdExceeded());
    rb.addCounter(GcNumInfoThresholdExceeded,
        pauseMonitor.getNumGcInfoThresholdExceeded());
    rb.addCounter(GcTotalExtraSleepTime,
        pauseMonitor.getTotalGcExtraSleepTime());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:JvmMetrics.java

示例7: main

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
public static void main(String [] args) throws Exception {
  if (args.length != 1) {
    throw new IllegalArgumentException("Usage: <MetaspaceSize>");
  }

  WhiteBox wb = WhiteBox.getWhiteBox();

  // Allocate past the MetaspaceSize limit.
  long metaspaceSize = Long.parseLong(args[0]);
  long allocationBeyondMetaspaceSize  = metaspaceSize * 2;
  long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);

  // Wait for at least one GC to occur. The caller will parse the log files produced.
  GarbageCollectorMXBean cmsGCBean = getCMSGCBean();
  while (cmsGCBean.getCollectionCount() == 0) {
    Thread.sleep(100);
  }

  wb.freeMetaspace(null, metaspace, metaspace);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TestCMSClassUnloadingEnabledHWM.java

示例8: getGCStatst

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
/**
 * Returns a map of garbage collectors and their stats.
 * The first object in the array is the total count since JVM start and the
 * second is the total time (ms) since JVM start.
 * If a garbage collectors does not support the collector MXBean, then it
 * will not be represented in the map.
 * @return A non-null map of garbage collectors and their metrics. The map
 * may be empty.
 */
public static Map<String, Long[]> getGCStatst() {
  final List<GarbageCollectorMXBean> gcBeans =
      ManagementFactory.getGarbageCollectorMXBeans();
  final Map<String, Long[]> map = new HashMap<String, Long[]>(gcBeans.size());
  for (final GarbageCollectorMXBean bean : gcBeans) {
    if (!bean.isValid() || bean.getCollectionCount() < 0 ||
        bean.getCollectionTime() < 0) {
      continue;
    }

    final Long[] measurements = new Long[]{
        bean.getCollectionCount(),
        bean.getCollectionTime()
    };
    map.put(bean.getName().replace(" ", "_"), measurements);
  }
  return map;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:28,代码来源:Utils.java

示例9: allocateMemory

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
/**
 * Allocate (<b>ratio</b> * <b>maxSize</b> / 100) bytes of objects
 * and force at least "MaxTenuringThreshold" minor GCs.
 *
 * @param ratio ratio used to calculate how many objects should be allocated
 * @param maxSize estimated max survivor space size
 */
public static void allocateMemory(double ratio, long maxSize) throws Exception {
    GarbageCollectorMXBean youngGCBean = GCTypes.YoungGCType.getYoungGCBean();
    long garbageSize = (long) (maxSize * (ratio / 100.0));
    int arrayLength = (int) (garbageSize / CHUNK_SIZE);
    AllocationHelper allocator = new AllocationHelper(1, arrayLength, ARRAY_LENGTH, null);

    System.out.println(START_TEST);
    System.gc();
    final long initialGcId = youngGCBean.getCollectionCount();
    // allocate memory
    allocator.allocateMemoryAndVerify();

    // force minor GC
    while (youngGCBean.getCollectionCount() <= initialGcId + MAX_TENURING_THRESHOLD * 2) {
        byte b[] = new byte[ARRAY_LENGTH];
    }

    allocator.release();
    System.out.println(END_TEST);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:28,代码来源:TestTargetSurvivorRatioFlag.java

示例10: getJVMInfo

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
public static JVMInfo getJVMInfo() {
  JVMInfo jvmInfo = new JVMInfo();

  Runtime runtime = Runtime.getRuntime();
  jvmInfo.setFreeMemory(runtime.freeMemory());
  jvmInfo.setTotalMemory(runtime.totalMemory());
  jvmInfo.setMaxMemory(runtime.maxMemory());

  int gcCount = 0;
  long gcTime = 0;
  for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
    long count = gc.getCollectionCount();
    if (count >= 0) {
      gcCount += count;
    }
    long time = gc.getCollectionTime();
    if (time >= 0) {
      gcTime += time;
    }
  }
  jvmInfo.setGcCount(gcCount);
  jvmInfo.setGcTime(gcTime);
  List<String> args = ManagementFactory.getRuntimeMXBean().getInputArguments();
  jvmInfo.setArguments(joiner.join(args));
  return jvmInfo;
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:27,代码来源:RuntimeInfoUtils.java

示例11: getGCStats

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
private void getGCStats() {
  long currentGcCount = 0;
  long currentGcDuration = 0;

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

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

    long time = gc.getCollectionTime();

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

  logger.trace("number of GCs: " + (currentGcCount - lastGcCount) + " and time spent in GCs: "
      + (currentGcDuration - lastGcDuration) + "ms");

  lastGcCount = currentGcCount;
  lastGcDuration = currentGcDuration;
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:25,代码来源:BaseHandler.java

示例12: doGarbageCollectionUpdates

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的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:nucypher,项目名称:hadoop-oss,代码行数:16,代码来源:JvmMetrics.java

示例13: getGCTotalCollectionCount

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
/** @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;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:15,代码来源:Utils.java

示例14: getGCStats

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的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

示例15: accumulatedInvocations

import java.lang.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
public long accumulatedInvocations()
{
    long sum = 0;
    int i = 0;
    for (GarbageCollectorMXBean bean : garbageBeans)
    {
        sum += bean.getCollectionCount() - gcInvocations[i++];
    }
    return sum;
}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:11,代码来源:GCSnapshot.java


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