本文整理汇总了Java中com.sun.management.GcInfo.getMemoryUsageBeforeGc方法的典型用法代码示例。如果您正苦于以下问题:Java GcInfo.getMemoryUsageBeforeGc方法的具体用法?Java GcInfo.getMemoryUsageBeforeGc怎么用?Java GcInfo.getMemoryUsageBeforeGc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.management.GcInfo
的用法示例。
在下文中一共展示了GcInfo.getMemoryUsageBeforeGc方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printGcInfo
import com.sun.management.GcInfo; //导入方法依赖的package包/类
private static void printGcInfo(CompositeData cd) throws Exception {
GcInfo info = GcInfo.from(cd);
System.out.print("GC #" + info.getId());
System.out.print(" start:" + info.getStartTime());
System.out.print(" end:" + info.getEndTime());
System.out.println(" (" + info.getDuration() + "ms)");
Map<String,MemoryUsage> usage = info.getMemoryUsageBeforeGc();
for (Map.Entry<String,MemoryUsage> entry : usage.entrySet()) {
String poolname = entry.getKey();
MemoryUsage busage = entry.getValue();
MemoryUsage ausage = info.getMemoryUsageAfterGc().get(poolname);
if (ausage == null) {
throw new RuntimeException("After Gc Memory does not exist" +
" for " + poolname);
}
System.out.println("Usage for pool " + poolname);
System.out.println(" Before GC: " + busage);
System.out.println(" After GC: " + ausage);
}
}
示例2: printGcInfo
import com.sun.management.GcInfo; //导入方法依赖的package包/类
private static void printGcInfo(GcInfo info) throws Exception {
System.out.print("GC #" + info.getId());
System.out.print(" start:" + info.getStartTime());
System.out.print(" end:" + info.getEndTime());
System.out.println(" (" + info.getDuration() + "ms)");
Map<String,MemoryUsage> usage = info.getMemoryUsageBeforeGc();
for (Map.Entry<String,MemoryUsage> entry : usage.entrySet()) {
String poolname = entry.getKey();
MemoryUsage busage = entry.getValue();
MemoryUsage ausage = info.getMemoryUsageAfterGc().get(poolname);
if (ausage == null) {
throw new RuntimeException("After Gc Memory does not exist" +
" for " + poolname);
}
System.out.println("Usage for pool " + poolname);
System.out.println(" Before GC: " + busage);
System.out.println(" After GC: " + ausage);
}
}
示例3: handleNotification
import com.sun.management.GcInfo; //导入方法依赖的package包/类
public void handleNotification(final Notification notification, final Object handback)
{
String type = notification.getType();
if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
{
// retrieve the garbage collection notification information
CompositeData cd = (CompositeData) notification.getUserData();
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(cd);
String gcName = info.getGcName();
GcInfo gcInfo = info.getGcInfo();
long duration = gcInfo.getDuration();
/*
* The duration supplied in the notification info includes more than just
* application stopped time for concurrent GCs. Try and do a better job coming up with a good stopped time
* value by asking for and tracking cumulative time spent blocked in GC.
*/
GCState gcState = gcStates.get(gcName);
if (gcState.assumeGCIsPartiallyConcurrent)
{
long previousTotal = gcState.lastGcTotalDuration;
long total = gcState.gcBean.getCollectionTime();
gcState.lastGcTotalDuration = total;
duration = total - previousTotal; // may be zero for a really fast collection
}
StringBuilder sb = new StringBuilder();
sb.append(info.getGcName()).append(" GC in ").append(duration).append("ms. ");
long bytes = 0;
Map<String, MemoryUsage> beforeMemoryUsage = gcInfo.getMemoryUsageBeforeGc();
Map<String, MemoryUsage> afterMemoryUsage = gcInfo.getMemoryUsageAfterGc();
for (String key : gcState.keys(info))
{
MemoryUsage before = beforeMemoryUsage.get(key);
MemoryUsage after = afterMemoryUsage.get(key);
if (after != null && after.getUsed() != before.getUsed())
{
sb.append(key).append(": ").append(before.getUsed());
sb.append(" -> ");
sb.append(after.getUsed());
if (!key.equals(gcState.keys[gcState.keys.length - 1]))
sb.append("; ");
bytes += before.getUsed() - after.getUsed();
}
}
while (true)
{
State prev = state.get();
if (state.compareAndSet(prev, new State(duration, bytes, prev)))
break;
}
String st = sb.toString();
if (GC_WARN_THRESHOLD_IN_MS != 0 && duration > GC_WARN_THRESHOLD_IN_MS)
logger.warn(st);
else if (duration > MIN_LOG_DURATION)
logger.info(st);
else if (logger.isTraceEnabled())
logger.trace(st);
if (duration > STAT_THRESHOLD)
StatusLogger.log();
// if we just finished an old gen collection and we're still using a lot of memory, try to reduce the pressure
if (gcState.assumeGCIsOldGen)
LifecycleTransaction.rescheduleFailedDeletions();
}
}
示例4: checkGarbageCollectionNotificationInfoContent
import com.sun.management.GcInfo; //导入方法依赖的package包/类
private static void checkGarbageCollectionNotificationInfoContent(GarbageCollectionNotificationInfo notif) throws Exception {
System.out.println("GC notification for "+notif.getGcName());
System.out.print("Action: "+notif.getGcAction());
System.out.println(" Cause: "+notif.getGcCause());
GcInfo info = notif.getGcInfo();
System.out.print("GC Info #" + info.getId());
System.out.print(" start:" + info.getStartTime());
System.out.print(" end:" + info.getEndTime());
System.out.println(" (" + info.getDuration() + "ms)");
Map<String, MemoryUsage> usage = info.getMemoryUsageBeforeGc();
List<String> pnames = new ArrayList<String>();
for (Map.Entry entry : usage.entrySet() ) {
String poolname = (String) entry.getKey();
pnames.add(poolname);
MemoryUsage busage = (MemoryUsage) entry.getValue();
MemoryUsage ausage = (MemoryUsage) info.getMemoryUsageAfterGc().get(poolname);
if (ausage == null) {
throw new RuntimeException("After Gc Memory does not exist" +
" for " + poolname);
}
System.out.println("Usage for pool " + poolname);
System.out.println(" Before GC: " + busage);
System.out.println(" After GC: " + ausage);
}
// check if memory usage for all memory pools are returned
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p : pools ) {
if (!pnames.contains(p.getName())) {
throw new RuntimeException("GcInfo does not contain " +
"memory usage for pool " + p.getName());
}
}
}
示例5: checkGcInfo
import com.sun.management.GcInfo; //导入方法依赖的package包/类
private static void checkGcInfo(String name, GcInfo info) throws Exception {
System.out.println("GC statistic for : " + name);
System.out.print("GC #" + info.getId());
System.out.print(" start:" + info.getStartTime());
System.out.print(" end:" + info.getEndTime());
System.out.println(" (" + info.getDuration() + "ms)");
Map usage = info.getMemoryUsageBeforeGc();
List pnames = new ArrayList();
for (Iterator iter = usage.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
String poolname = (String) entry.getKey();
pnames.add(poolname);
MemoryUsage busage = (MemoryUsage) entry.getValue();
MemoryUsage ausage = (MemoryUsage) info.getMemoryUsageAfterGc().get(poolname);
if (ausage == null) {
throw new RuntimeException("After Gc Memory does not exist" +
" for " + poolname);
}
System.out.println("Usage for pool " + poolname);
System.out.println(" Before GC: " + busage);
System.out.println(" After GC: " + ausage);
}
// check if memory usage for all memory pools are returned
List pools = ManagementFactory.getMemoryPoolMXBeans();
for (Iterator iter = pools.iterator(); iter.hasNext(); ) {
MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
if (!pnames.contains(p.getName())) {
throw new RuntimeException("GcInfo does not contain " +
"memory usage for pool " + p.getName());
}
}
}