use of java.lang.management.GarbageCollectorMXBean in project hadoop by apache.
the class JvmMetrics method getGcUsage.
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());
}
}
use of java.lang.management.GarbageCollectorMXBean in project intellij-community by JetBrains.
the class LightPlatformTestCase method reportTestExecutionStatistics.
@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()));
}
use of java.lang.management.GarbageCollectorMXBean in project eiger by wlloyd.
the class GCInspector method logGCResults.
private void logGCResults() {
for (GarbageCollectorMXBean gc : beans) {
Long previousTotal = gctimes.get(gc.getName());
Long total = gc.getCollectionTime();
if (previousTotal == null)
previousTotal = 0L;
if (previousTotal.equals(total))
continue;
gctimes.put(gc.getName(), total);
// may be zero for a really fast collection
Long duration = total - previousTotal;
Long previousCount = gccounts.get(gc.getName());
Long count = gc.getCollectionCount();
if (previousCount == null)
previousCount = 0L;
if (count.equals(previousCount))
continue;
gccounts.put(gc.getName(), count);
MemoryUsage mu = membean.getHeapMemoryUsage();
long memoryUsed = mu.getUsed();
long memoryMax = mu.getMax();
String st = String.format("GC for %s: %s ms for %s collections, %s used; max is %s", gc.getName(), duration, count - previousCount, memoryUsed, memoryMax);
long durationPerCollection = duration / (count - previousCount);
if (durationPerCollection > MIN_DURATION)
logger.info(st);
else if (logger.isDebugEnabled())
logger.debug(st);
if (durationPerCollection > MIN_DURATION_TPSTATS)
StatusLogger.log();
// if we just finished a full collection and we're still using a lot of memory, try to reduce the pressure
if (gc.getName().equals("ConcurrentMarkSweep")) {
SSTableDeletingTask.rescheduleFailedTasks();
double usage = (double) memoryUsed / memoryMax;
if (memoryUsed > DatabaseDescriptor.getReduceCacheSizesAt() * memoryMax && !cacheSizesReduced) {
cacheSizesReduced = true;
logger.warn("Heap is " + usage + " full. You may need to reduce memtable and/or cache sizes. Cassandra is now reducing cache sizes to free up memory. Adjust reduce_cache_sizes_at threshold in cassandra.yaml if you don't want Cassandra to do this automatically");
CacheService.instance.reduceCacheSizes();
}
if (memoryUsed > DatabaseDescriptor.getFlushLargestMemtablesAt() * memoryMax) {
logger.warn("Heap is " + usage + " full. You may need to reduce memtable and/or cache sizes. Cassandra will now flush up to the two largest memtables to free up memory. Adjust flush_largest_memtables_at threshold in cassandra.yaml if you don't want Cassandra to do this automatically");
StorageService.instance.flushLargestMemtables();
}
}
}
}
use of java.lang.management.GarbageCollectorMXBean in project pysonar2 by yinwang0.
the class $ method getGCStats.
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();
}
use of java.lang.management.GarbageCollectorMXBean in project zm-mailbox by Zimbra.
the class MemoryStats method getGarbageCollectorNames.
/**
* @return The name of all the Garbage Collectors in the system
*
* For the default (serial) hotspot settings, this means:
* Copy - The copy collector, Eden and Minor GCs in Survivor
* MarkSweepCompact - Major GCs
*
*/
public static String[] getGarbageCollectorNames() {
List<GarbageCollectorMXBean> gcs = ManagementFactory.getGarbageCollectorMXBeans();
String[] toRet = new String[gcs.size()];
int i = 0;
for (GarbageCollectorMXBean gc : gcs) {
toRet[i] = gc.getName();
i++;
}
return toRet;
}
Aggregations