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());
      }
    }
  }
Beispiel #2
0
  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);
    }
  }