Package com.sun.management

Examples of com.sun.management.GcInfo


    private void logIntervalGCStats()
    {
        for (GarbageCollectorMXBean gc : beans)
        {
            GcInfo gci = gc.getLastGcInfo();
            if (gci == null)
                continue;

            Long previous = gctimes.get(gc.getName());
            if (previous != null && previous == gc.getCollectionTime())
                continue;
            gctimes.put(gc.getName(), gc.getCollectionTime());

            long previousMemoryUsed = 0;
            long memoryUsed = 0;
            long memoryMax = 0;
            for (Map.Entry<String, MemoryUsage> entry : gci.getMemoryUsageBeforeGc().entrySet())
            {
                previousMemoryUsed += entry.getValue().getUsed();
            }
            for (Map.Entry<String, MemoryUsage> entry : gci.getMemoryUsageAfterGc().entrySet())
            {
                MemoryUsage mu = entry.getValue();
                memoryUsed += mu.getUsed();
                memoryMax += mu.getMax();
            }

            String st = String.format("GC for %s: %s ms, %s reclaimed leaving %s used; max is %s",
                                      gc.getName(), gci.getDuration(), previousMemoryUsed - memoryUsed, memoryUsed, memoryMax);
            if (gci.getDuration() > MIN_DURATION)
                logger.info(st);
            else if (logger.isDebugEnabled())
                logger.debug(st);
            if (gci.getDuration() > MIN_DURATION_TPSTATS)
            {
                try
                {
                    logThreadPoolStats();
                }
View Full Code Here


    private void logIntervalGCStats()
    {
        for (GarbageCollectorMXBean gc : beans)
        {
            GcInfo gci = gc.getLastGcInfo();
            if (gci == null)
                continue;

            Long previous = gctimes.get(gc.getName());
            if (previous != null && previous == gc.getCollectionTime())
                continue;
            gctimes.put(gc.getName(), gc.getCollectionTime());

            long previousMemoryUsed = 0;
            long memoryUsed = 0;
            long memoryMax = 0;
            for (Map.Entry<String, MemoryUsage> entry : gci.getMemoryUsageBeforeGc().entrySet())
            {
                previousMemoryUsed += entry.getValue().getUsed();
            }
            for (Map.Entry<String, MemoryUsage> entry : gci.getMemoryUsageAfterGc().entrySet())
            {
                MemoryUsage mu = entry.getValue();
                memoryUsed += mu.getUsed();
                memoryMax += mu.getMax();
            }

            String st = String.format("GC for %s: %s ms, %s reclaimed leaving %s used; max is %s",
                                      gc.getName(), gci.getDuration(), previousMemoryUsed - memoryUsed, memoryUsed, memoryMax);
            if (gci.getDuration() > MIN_DURATION)
                logger.info(st);
            else if (logger.isDebugEnabled())
                logger.debug(st);
        }
    }
View Full Code Here

    for (GarbageCollectorMXBean bean : garbageCollectorMXBeans) {
      NotificationListener listener = new NotificationListener() {
        @Override
        public void handleNotification(Notification notification, Object bean) {
          GarbageCollectorMXBean garbageCollectorMXBean = (GarbageCollectorMXBean) bean;
          GcInfo gcInfo = getGcInfo(garbageCollectorMXBean);
          long startTime = gcInfo.getStartTime();
          long endTime = gcInfo.getEndTime();
          Map<String, MemoryUsage> usageBeforeGc = gcInfo.getMemoryUsageBeforeGc();
          Map<String, MemoryUsage> usageAfterGc = gcInfo.getMemoryUsageAfterGc();
          long usedBefore = getTotal(usageBeforeGc);
          long usedAfter = getTotal(usageAfterGc);
          long totalTime = endTime - startTime;
          long totalSize = usedBefore - usedAfter;
          if (totalTime >= _1_SECOND) {
View Full Code Here

    private void logIntervalGCStats()
    {
        for (GarbageCollectorMXBean gc : beans)
        {
            GcInfo gci = gc.getLastGcInfo();
            if (gci == null)
                continue;

            Long previous = gctimes.get(gc.getName());
            if (previous != null && previous == gc.getCollectionTime())
                continue;
            gctimes.put(gc.getName(), gc.getCollectionTime());

            long previousMemoryUsed = 0;
            long memoryUsed = 0;
            long memoryMax = 0;
            for (Map.Entry<String, MemoryUsage> entry : gci.getMemoryUsageBeforeGc().entrySet())
            {
                previousMemoryUsed += entry.getValue().getUsed();
            }
            for (Map.Entry<String, MemoryUsage> entry : gci.getMemoryUsageAfterGc().entrySet())
            {
                MemoryUsage mu = entry.getValue();
                memoryUsed += mu.getUsed();
                memoryMax += mu.getMax();
            }

            String st = String.format("GC for %s: %s ms, %s reclaimed leaving %s used; max is %s",
                                      gc.getName(), gci.getDuration(), previousMemoryUsed - memoryUsed, memoryUsed, memoryMax);
            if (gci.getDuration() > MIN_DURATION)
                logger.info(st);
            else if (logger.isDebugEnabled())
                logger.debug(st);
        }
    }
View Full Code Here

            if (gcInfoBuilder == null) {
                 gcInfoBuilder = new GcInfoBuilder(this, getAllPoolNames());
            }
        }

        GcInfo info = gcInfoBuilder.getLastGcInfo();
        return info;
    }
View Full Code Here

        for (GarbageCollectorMXBean gc : gcs) {
            com.sun.management.GarbageCollectorMXBean sunGc =
               newPlatformMXBeanProxy(server,
                   GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",name=" + gc.getName(),
                   com.sun.management.GarbageCollectorMXBean.class);
            GcInfo info = sunGc.getLastGcInfo();
            if (info != null) {
                System.out.println("GC statistic for : " + gc.getName());
                printGcInfo(info);
            }
        }
View Full Code Here

            }
        }
    }

    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);
View Full Code Here

    return pools;
  }

  public void report() {
    try {
      GcInfo lastGc = gc.getLastGcInfo();
      if (lastGc == null || lastGc.getId() == gcCount) {
        return;
      }
      else {       
        int missed = (int)(lastGc.getId() - 1 - gcCount);
        if (gcCount < 0) {
          missed = 0;
        }
        long gcInterval = lastGc.getStartTime() - prevCollectionEndTime;
        prevCollectionEndTime = lastGc.getEndTime();
        if (gcCount < 0) {
          gcInterval = -1;
        }
        if (lastGc.getEndTime() == 0) {
          // no GC so far
          prevCollectionEndTime = 0;
          gcCount = lastGc.getId();
        }
        else {
          gcCount = lastGc.getId();
          sampler.report(name, missed, new Report(lastGc, gcInterval));
        }
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
View Full Code Here

        List mgrs = ManagementFactory.getGarbageCollectorMXBeans();
        for (ListIterator iter = mgrs.listIterator(); iter.hasNext(); ) {
            Object mgr = iter.next();
            if (mgr instanceof GarbageCollectorMXBean) {
                GarbageCollectorMXBean gc = (GarbageCollectorMXBean) mgr;
                GcInfo info = gc.getLastGcInfo();
                if (info != null) {
                    checkGcInfo(gc.getName(), info);
                    hasGcInfo = true;
                }
            }
View Full Code Here

TOP

Related Classes of com.sun.management.GcInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.