當前位置: 首頁>>代碼示例>>Java>>正文


Java GarbageCollectorMXBean.getCollectionTime方法代碼示例

本文整理匯總了Java中java.lang.management.GarbageCollectorMXBean.getCollectionTime方法的典型用法代碼示例。如果您正苦於以下問題:Java GarbageCollectorMXBean.getCollectionTime方法的具體用法?Java GarbageCollectorMXBean.getCollectionTime怎麽用?Java GarbageCollectorMXBean.getCollectionTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.management.GarbageCollectorMXBean的用法示例。


在下文中一共展示了GarbageCollectorMXBean.getCollectionTime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例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: 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

示例8: 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

示例9: reportTestExecutionStatistics

import java.lang.management.GarbageCollectorMXBean; //導入方法依賴的package包/類
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void reportTestExecutionStatistics() {
  System.out.println("----- TEST STATISTICS -----");
  UsefulTestCase.logSetupTeardownCosts();
  System.out.println(String.format("##teamcity[buildStatisticValue key='ideaTests.appInstancesCreated' value='%d']",
                                   MockApplication.INSTANCES_CREATED));
  System.out.println(String.format("##teamcity[buildStatisticValue key='ideaTests.projectInstancesCreated' value='%d']",
                                   ProjectManagerImpl.TEST_PROJECTS_CREATED));
  long totalGcTime = 0;
  for (GarbageCollectorMXBean mxBean : ManagementFactory.getGarbageCollectorMXBeans()) {
    totalGcTime += mxBean.getCollectionTime();
  }
  System.out.println(String.format("##teamcity[buildStatisticValue key='ideaTests.gcTimeMs' value='%d']", totalGcTime));
  System.out.println(String.format("##teamcity[buildStatisticValue key='ideaTests.classesLoaded' value='%d']",
                                   ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount()));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:LightPlatformTestCase.java

示例10: getCollectionTime

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

示例11: getElapsedGc

import java.lang.management.GarbageCollectorMXBean; //導入方法依賴的package包/類
/**
 * @return the number of milliseconds that the gc has used for CPU since the last time this
 *         method was called.
 */
protected long getElapsedGc() {
  long thisGcMillis = 0;
  for (GarbageCollectorMXBean gcBean : gcBeans) {
    thisGcMillis += gcBean.getCollectionTime();
  }

  long delta = thisGcMillis - lastGcMillis;
  this.lastGcMillis = thisGcMillis;
  return delta;
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:15,代碼來源:CounterUpdater.java

示例12: getGCTotalTime

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

示例13: 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

示例14: accumulatedTime

import java.lang.management.GarbageCollectorMXBean; //導入方法依賴的package包/類
public long accumulatedTime()
{
    long sum = 0;
    int i = 0;
    for (GarbageCollectorMXBean bean : garbageBeans)
    {
        sum += bean.getCollectionTime() - gcTimes[i++];
    }
    return sum;
}
 
開發者ID:adnanmitf09,項目名稱:Rubus,代碼行數:11,代碼來源:GCSnapshot.java

示例15: getGarbageCollectorTimeMillis

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


注:本文中的java.lang.management.GarbageCollectorMXBean.getCollectionTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。