use of java.lang.management.GarbageCollectorMXBean in project phoenix by apache.
the class GarbageCollectorElapsedTimeMonitor method getStat.
@Override
public Stat getStat() {
List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans();
long average = 0;
Stat<Long> stat = null;
if (beans.size() > 0) {
for (GarbageCollectorMXBean bean : beans) {
average += bean.getCollectionTime();
}
stat = new Stat(average / beans.size());
} else {
stat = new Stat(0);
}
return stat;
}
use of java.lang.management.GarbageCollectorMXBean in project voltdb by VoltDB.
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();
long durationPerCollection = duration / (count - previousCount);
if (durationPerCollection > MIN_DURATION) {
String st = String.format("GC for %s: %s ms for %s collections, %s used; max is %s", gc.getName(), duration, count - previousCount, memoryUsed, memoryMax);
logger.info(st);
} else if (logger.isDebugEnabled()) {
String st = String.format("GC for %s: %s ms for %s collections, %s used; max is %s", gc.getName(), duration, count - previousCount, memoryUsed, memoryMax);
logger.debug(st);
}
// if we just finished a full collection and we're still using a lot of memory, log
if (newGenGCs.contains(gc.getName())) {
m_voltGcStats.gcInspectorReport(true, (int) (count - previousCount), duration);
}
if (oldGenGCs.contains(gc.getName())) {
m_voltGcStats.gcInspectorReport(false, (int) (count - previousCount), duration);
if (memoryUsed > .5 * memoryMax) {
double usage = (double) memoryUsed / memoryMax;
String usageStr = String.format("%.2f", usage * 100);
//2^20 Bytes
String memoryMaxStr = String.format("%.2f", (double) memoryMax / 1_048_576);
if (.5 <= usage && usage < .6) {
logger.info("Heap is " + usageStr + "% full out of " + memoryMaxStr + "MB.");
} else if (.6 <= usage) {
logger.warn("Heap is " + usageStr + "% full out of " + memoryMaxStr + "MB.");
}
}
}
}
}
use of java.lang.management.GarbageCollectorMXBean in project leopard by tanhaichao.
the class JvmManagement method printGC.
public static void printGC() {
System.out.println("=======================MemoryPoolMXBean============================ ");
List<GarbageCollectorMXBean> gcmList = ManagementFactory.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean gcm : gcmList) {
System.out.println("getName " + gcm.getName() + " count:" + gcm.getCollectionCount() + " time:" + gcm.getCollectionTime());
// System.out.println("getMemoryPoolNames " + gcm.getMemoryPoolNames());
}
}
use of java.lang.management.GarbageCollectorMXBean in project Payara by payara.
the class GarbageCollectorHealthCheck method doCheck.
@Override
public HealthCheckResult doCheck() {
HealthCheckResult result = new HealthCheckResult();
List<GarbageCollectorMXBean> gcBeanList = ManagementFactory.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean gcBean : gcBeanList) {
double percentage = 0;
if (YOUNG_PS_SCAVENGE.equals(gcBean.getName()) || YOUNG_G1GC.equals(gcBean.getName()) || YOUNG_COPY.equals(gcBean.getName()) || YOUNG_PARNEW.equals(gcBean.getName())) {
long diffCount = gcBean.getCollectionCount() - youngLastCollectionCount;
long diffTime = gcBean.getCollectionTime() - youngLastCollectionTime;
if (diffTime > 0 && youngLastCollectionCount > 0) {
percentage = ((diffCount) / (youngLastCollectionCount)) * 100;
result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(percentage), diffCount + " times Young GC (" + gcBean.getName() + ") after " + prettyPrintDuration(diffTime)));
}
youngLastCollectionCount = gcBean.getCollectionCount();
youngLastCollectionTime = gcBean.getCollectionTime();
} else if (OLD_PS_MARKSWEEP.equals(gcBean.getName()) || OLD_G1GC.equals(gcBean.getName()) || OLD_MARK_SWEEP_COMPACT.equals(gcBean.getName()) || OLD_CONCURRENTMARKSWEEP.equals(gcBean.getName())) {
long diffCount = gcBean.getCollectionCount() - oldLastCollectionCount;
long diffTime = gcBean.getCollectionTime() - oldLastCollectionTime;
if (diffTime > 0 && oldLastCollectionCount > 0) {
percentage = ((diffCount) / (oldLastCollectionCount)) * 100;
result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(percentage), diffCount + " times Old GC (" + gcBean.getName() + ") after " + prettyPrintDuration(diffTime)));
}
oldLastCollectionCount = gcBean.getCollectionCount();
oldLastCollectionTime = gcBean.getCollectionTime();
} else {
result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "Could not identify " + "GarbageCollectorMXBean with name: " + gcBean.getName()));
}
}
return result;
}
use of java.lang.management.GarbageCollectorMXBean in project Payara by payara.
the class MemoryReporter method getGarbageCollectionReport.
private String getGarbageCollectionReport() {
final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder());
for (final GarbageCollectorMXBean m : gcmbeans) {
final String name = sm.getString("gc.name", m.getName());
sb.append(name);
final String cc = sm.getString("gc.numcol", JVMInformationCollector.formatLong(m.getCollectionCount()));
sb.append(cc);
final String gct = sm.getString("gc.coltime", JVMInformationCollector.millis2SecondsMillis(m.getCollectionTime()));
sb.append(gct);
}
return (sb.toString());
}
Aggregations