コード例 #1
0
  private void createRuntimeProps(MemberStateImpl memberState) {
    Runtime runtime = Runtime.getRuntime();
    ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
    ClassLoadingMXBean clMxBean = ManagementFactory.getClassLoadingMXBean();
    MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heapMemory = memoryMxBean.getHeapMemoryUsage();
    MemoryUsage nonHeapMemory = memoryMxBean.getNonHeapMemoryUsage();

    Map<String, Long> map = new HashMap<String, Long>();
    map.put(
        "runtime.availableProcessors", Integer.valueOf(runtime.availableProcessors()).longValue());
    map.put("date.startTime", runtimeMxBean.getStartTime());
    map.put("seconds.upTime", runtimeMxBean.getUptime());

    map.put("memory.maxMemory", runtime.maxMemory());
    map.put("memory.freeMemory", runtime.freeMemory());
    map.put("memory.totalMemory", runtime.totalMemory());
    map.put("memory.heapMemoryMax", heapMemory.getMax());
    map.put("memory.heapMemoryUsed", heapMemory.getUsed());
    map.put("memory.nonHeapMemoryMax", nonHeapMemory.getMax());
    map.put("memory.nonHeapMemoryUsed", nonHeapMemory.getUsed());
    map.put("runtime.totalLoadedClassCount", clMxBean.getTotalLoadedClassCount());
    map.put(
        "runtime.loadedClassCount", Integer.valueOf(clMxBean.getLoadedClassCount()).longValue());
    map.put("runtime.unloadedClassCount", clMxBean.getUnloadedClassCount());
    map.put("runtime.totalStartedThreadCount", threadMxBean.getTotalStartedThreadCount());
    map.put("runtime.threadCount", Integer.valueOf(threadMxBean.getThreadCount()).longValue());
    map.put(
        "runtime.peakThreadCount", Integer.valueOf(threadMxBean.getPeakThreadCount()).longValue());
    map.put(
        "runtime.daemonThreadCount",
        Integer.valueOf(threadMxBean.getDaemonThreadCount()).longValue());
    memberState.setRuntimeProps(map);
  }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see com.orientechnologies.common.test.SpeedTest#startTimer(java.lang.String)
   */
  public void startTimer(final String iName) {
    Runtime.getRuntime().runFinalization();
    Runtime.getRuntime().gc();

    try {
      Thread.sleep(TIME_WAIT);
    } catch (InterruptedException e) {
    }

    final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    final MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
    final MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();

    currentTestName = iName;

    currentTestHeapCommittedMemory = heapMemoryUsage.getCommitted();
    currentTestHeapUsedMemory = heapMemoryUsage.getUsed();
    currentTestHeapMaxMemory = heapMemoryUsage.getMax();

    currentTestNonHeapCommittedMemory = nonHeapMemoryUsage.getCommitted();
    currentTestNonHeapUsedMemory = nonHeapMemoryUsage.getUsed();
    currentTestNonHeapMaxMemory = nonHeapMemoryUsage.getMax();

    System.out.println("-> Started the test of '" + currentTestName + "' (" + cycles + " cycles)");

    currentTestTimer = System.currentTimeMillis();
  }
コード例 #3
0
 /**
  * Creates a new instance. This can't be called outside of container b/c agents have no refs to
  * the singleton container. So we can be sure this method is going to create services just once.
  *
  * @param c Reference to the container.
  * @return The sole instance.
  * @throws NullPointerException If the reference to the {@link Container} is <code>null</code>.
  */
 public static PixelsServicesFactory getInstance(Container c) {
   if (c == null) throw new NullPointerException(); // An agent called this method?
   if (singleton == null) {
     registry = c.getRegistry();
     singleton = new PixelsServicesFactory();
     // Retrieve the maximum heap size.
     MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
     String message = "Heap memory usage: max " + usage.getMax();
     registry.getLogger().info(singleton, message);
     // percentage of memory used for caching.
     maxSize = (int) (RATIO * usage.getMax()) / FACTOR;
   }
   return singleton;
 }
コード例 #4
0
 /** Add JVM heap metrics. */
 protected void addHeapMetrics(Collection<Metric<?>> result) {
   MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
   result.add(new Metric<Long>("heap.committed", memoryUsage.getCommitted() / 1024));
   result.add(new Metric<Long>("heap.init", memoryUsage.getInit() / 1024));
   result.add(new Metric<Long>("heap.used", memoryUsage.getUsed() / 1024));
   result.add(new Metric<Long>("heap", memoryUsage.getMax() / 1024));
 }
コード例 #5
0
ファイル: JvmUtils.java プロジェクト: liuyong1352/mm
  public static void main(String args[]) {

    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();

    long init = heapMemoryUsage.getInit();
    long used = heapMemoryUsage.getUsed();
    long max = heapMemoryUsage.getMax();
    long committed = heapMemoryUsage.getCommitted();
    long free = max - used;
    int usedPercent = (int) (used / max);
    int freePercent = (int) (usedPercent / max);

    MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();

    List<GarbageCollectorMXBean> garbageCollectorMXBeans =
        ManagementFactory.getGarbageCollectorMXBeans();

    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();

    com.sun.management.OperatingSystemMXBean operatingSystemMXBean =
        (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    long commitVirtual = operatingSystemMXBean.getCommittedVirtualMemorySize();

    println(init, used, max, committed);
    println(commitVirtual);
  }
コード例 #6
0
ファイル: JspHelper.java プロジェクト: baggioss/hadoop-cdh3u5
  public String getInodeLimitText() {
    long inodes = fsn.dir.totalInodes();
    long blocks = fsn.getBlocksTotal();
    long maxobjects = fsn.getMaxObjects();

    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = mem.getHeapMemoryUsage();
    long totalMemory = heap.getUsed();
    long maxMemory = heap.getMax();

    long used = (totalMemory * 100) / maxMemory;

    String str =
        inodes + " files and directories, " + blocks + " blocks = " + (inodes + blocks) + " total";
    if (maxobjects != 0) {
      long pct = ((inodes + blocks) * 100) / maxobjects;
      str += " / " + maxobjects + " (" + pct + "%)";
    }
    str +=
        ".  Heap Size is "
            + StringUtils.byteDesc(totalMemory)
            + " / "
            + StringUtils.byteDesc(maxMemory)
            + " ("
            + used
            + "%) <br>";
    return str;
  }
コード例 #7
0
ファイル: SystemUtil.java プロジェクト: adamcameron/Lucee4
  public static Struct getMemoryUsageAsStruct(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    long used = 0, max = 0, init = 0;
    while (it.hasNext()) {
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if ((type == MEMORY_TYPE_HEAP && _type == MemoryType.HEAP)
          || (type == MEMORY_TYPE_NON_HEAP && _type == MemoryType.NON_HEAP)) {
        used += usage.getUsed();
        max += usage.getMax();
        init += usage.getInit();
      }
    }
    Struct sct = new StructImpl();
    sct.setEL(KeyConstants._used, Caster.toDouble(used));
    sct.setEL(KeyConstants._max, Caster.toDouble(max));
    sct.setEL(KeyConstants._init, Caster.toDouble(init));
    sct.setEL(KeyImpl.init("available"), Caster.toDouble(max - used));
    return sct;
  }
コード例 #8
0
  public Map<String, String> getProperties() {
    Map<String, String> map = new TreeMap<String, String>();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();

    List<String> aList = runtimeMXBean.getInputArguments();
    String parameters = "";
    for (int i = 0; i < aList.size(); i++) {
      parameters = parameters + " " + aList.get(i);
    }
    map.put("params", parameters);

    map.put("name", runtimeMXBean.getVmName());
    map.put("vendor", runtimeMXBean.getVmVendor());
    map.put("version", runtimeMXBean.getVmVersion());
    map.put("specification", runtimeMXBean.getSpecVersion());
    map.put("uptime", DurationFormatUtils.formatDurationHMS(runtimeMXBean.getUptime()));

    Date date = new Date(runtimeMXBean.getStartTime());
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    map.put("start time", sdf.format(date));

    MemoryMXBean memory = ManagementFactory.getMemoryMXBean();

    MemoryUsage heap = memory.getHeapMemoryUsage();
    map.put(
        "memory. (heap)",
        readableFileSize(heap.getUsed())
            + "/"
            + readableFileSize(heap.getCommitted())
            + " min:"
            + readableFileSize(heap.getInit())
            + " max:"
            + readableFileSize(heap.getMax()));
    MemoryUsage nonheap = memory.getNonHeapMemoryUsage();
    map.put(
        "memory (non heap)",
        readableFileSize(nonheap.getUsed())
            + "/"
            + readableFileSize(nonheap.getCommitted())
            + " min:"
            + readableFileSize(nonheap.getInit())
            + " max:"
            + readableFileSize(nonheap.getMax()));

    return map;
  }
コード例 #9
0
ファイル: JMServer.java プロジェクト: is00hcw/Mycat-Web
 private static JSONObject toJson(MemoryUsage useage) {
   JSONObject item = new JSONObject();
   item.put("commit", useage.getCommitted());
   item.put("used", useage.getUsed());
   item.put("init", useage.getInit());
   item.put("max", useage.getMax());
   return item;
 }
コード例 #10
0
ファイル: SystemUtil.java プロジェクト: adamcameron/Lucee4
  public static long getFreePermGenSpaceSize() {
    MemoryUsage mu = getPermGenSpaceSize(null);
    if (mu == null) return -1;

    long max = mu.getMax();
    long used = mu.getUsed();
    if (max < 0 || used < 0) return -1;
    return max - used;
  }
コード例 #11
0
ファイル: SystemUtil.java プロジェクト: adamcameron/Lucee4
  public static int getFreePermGenSpacePromille() {
    MemoryUsage mu = getPermGenSpaceSize(null);
    if (mu == null) return -1;

    long max = mu.getMax();
    long used = mu.getUsed();
    if (max < 0 || used < 0) return -1;
    return (int) (1000L - (1000L * used / max));
  }
コード例 #12
0
  /**
   * Grid-enables method only if heap utilized over 80%. Otherwise, method method will proceed with
   * local execution without calling grid at all.
   *
   * @param gridify {@inheritDoc}
   * @param arg {@inheritDoc}
   * @return {@inheritDoc}
   * @throws GridException {@inheritDoc}
   */
  @Override
  public boolean isGridify(Annotation gridify, GridifyArgument arg) throws GridException {
    MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

    // If heap memory for the local node is above 80% of maximum heap
    // memory available, return true which means that method will
    // be grid-enabled. Otherwise, return false, which means that
    // method will execute locally without grid.
    return heap.getUsed() > 0.8 * heap.getMax();
  }
コード例 #13
0
ファイル: SystemUtil.java プロジェクト: adamcameron/Lucee4
  public static int getPermGenFreeSpaceAsAPercentageOfAvailable() {
    MemoryUsage mu = getPermGenSpaceSize(null);
    if (mu == null) return -1;

    long max = mu.getMax();
    long used = mu.getUsed();
    if (max < 0 || used < 0) return -1;

    // return a value that equates to a percentage of available free memory
    return 100 - ((int) (100 * (((double) used) / ((double) max))));
  }
コード例 #14
0
ファイル: Diagnostics.java プロジェクト: xiaobao2110/tomcat
 /**
  * Format contents of a MemoryUsage object.
  *
  * @param name a text prefix used in formatting
  * @param usage the MemoryUsage object to format
  * @return the formatted contents
  */
 private static String formatMemoryUsage(String name, MemoryUsage usage) {
   if (usage != null) {
     StringBuilder sb = new StringBuilder();
     sb.append(INDENT1 + name + " init: " + usage.getInit() + CRLF);
     sb.append(INDENT1 + name + " used: " + usage.getUsed() + CRLF);
     sb.append(INDENT1 + name + " committed: " + usage.getCommitted() + CRLF);
     sb.append(INDENT1 + name + " max: " + usage.getMax() + CRLF);
     return sb.toString();
   }
   return "";
 }
コード例 #15
0
  private String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean) {
    MemoryUsage heap = memoryMXBean.getHeapMemoryUsage();
    MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage();

    int mb = 1 << 20;

    int heapUsed = (int) (heap.getUsed() / mb);
    int heapCommitted = (int) (heap.getCommitted() / mb);
    int heapMax = (int) (heap.getMax() / mb);

    int nonHeapUsed = (int) (nonHeap.getUsed() / mb);
    int nonHeapCommitted = (int) (nonHeap.getCommitted() / mb);
    int nonHeapMax = (int) (nonHeap.getMax() / mb);

    String msg =
        String.format(
            "Memory usage stats: [HEAP: %d/%d/%d MB, NON HEAP: %d/%d/%d MB (used/comitted/max)]",
            heapUsed, heapCommitted, heapMax, nonHeapUsed, nonHeapCommitted, nonHeapMax);

    return msg;
  }
コード例 #16
0
ファイル: ManagementUtil.java プロジェクト: iisihub/CAP
 public static String formatHeapMemoryUsage(MemoryUsage beforHeap, MemoryUsage afterHeap) {
   return afterHeap != null
       ? CapString.concat(
           "Heap Usage: Committed=",
           bytesToMegabytes(beforHeap.getCommitted()),
           "->",
           bytesToMegabytes(afterHeap.getCommitted()),
           " MB, Init=",
           bytesToMegabytes(beforHeap.getInit()),
           "->",
           bytesToMegabytes(afterHeap.getInit()),
           " MB, Max=",
           bytesToMegabytes(beforHeap.getMax()),
           "->",
           bytesToMegabytes(afterHeap.getMax()),
           " MB, Used=",
           bytesToMegabytes(beforHeap.getUsed()),
           "->",
           bytesToMegabytes(afterHeap.getUsed()),
           "=",
           (bytesToMegabytes(afterHeap.getUsed() - beforHeap.getUsed())),
           " MB ")
       : "";
 }
コード例 #17
0
ファイル: MemoryPoolMeter.java プロジェクト: bondj/spectator
  @Override
  public Iterable<Measurement> measure() {
    final long timestamp = clock.wallTime();
    final MemoryPoolMXBean mbean = ref.get();
    final List<Measurement> ms = new ArrayList<>();
    if (mbean != null) {
      final String typeKey = "memtype";
      final String type = mbean.getName();

      final MemoryUsage usage = mbean.getUsage();
      ms.add(new Measurement(usedId.withTag(typeKey, type), timestamp, usage.getUsed()));
      ms.add(new Measurement(committedId.withTag(typeKey, type), timestamp, usage.getCommitted()));
      ms.add(new Measurement(maxId.withTag(typeKey, type), timestamp, usage.getMax()));
    }
    return ms;
  }
コード例 #18
0
 @Override
 public long[] getMaxSystemParameters() {
   long[] systemData = new long[3];
   MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
   systemData[0] = memoryMXBean.getHeapMemoryUsage().getMax();
   systemData[1] = memoryMXBean.getNonHeapMemoryUsage().getMax();
   List<MemoryPoolMXBean> mbeans = ManagementFactory.getMemoryPoolMXBeans();
   if (mbeans != null) {
     for (MemoryPoolMXBean mbean : mbeans) {
       MemoryUsage memUsage = mbean.getUsage();
       if (mbean.getName().equals(PERMGEN_MEMORY_POOL_NAME)) {
         systemData[2] = memUsage.getMax();
       }
     }
   }
   return systemData;
 }
コード例 #19
0
ファイル: JMXNodeTool.java プロジェクト: kinzer1/Priam
 @SuppressWarnings("unchecked")
 public JSONObject info() throws JSONException {
   JSONObject object = new JSONObject();
   object.put("gossip_active", isInitialized());
   object.put("thrift_active", isThriftServerRunning());
   object.put("token", getTokens().toString());
   object.put("load", getLoadString());
   object.put("generation_no", getCurrentGenerationNumber());
   object.put("uptime", getUptime() / 1000);
   MemoryUsage heapUsage = getHeapMemoryUsage();
   double memUsed = (double) heapUsage.getUsed() / (1024 * 1024);
   double memMax = (double) heapUsage.getMax() / (1024 * 1024);
   object.put("heap_memory_mb", memUsed + "/" + memMax);
   object.put("data_center", getDataCenter());
   object.put("rack", getRack());
   return object;
 }
コード例 #20
0
ファイル: MemoryMonitor.java プロジェクト: press0/jmx-monitor
 private void setThreshold(float fltThresholdPercent, MemoryPoolMXBean memPool) {
   MemoryUsage memUsage = memPool.getUsage();
   long max = memUsage.getMax();
   long threshold = (long) (max * fltThresholdPercent);
   String strThresholdPercent = Integer.toString(Math.round(fltThresholdPercent * 100)) + "%";
   log.info(
       "setting threshold on pool "
           + memPool.getName()
           + " to "
           + strThresholdPercent
           + " of "
           + max
           + "("
           + threshold
           + ")");
   memPool.setUsageThreshold(threshold);
 }
コード例 #21
0
ファイル: SystemUtil.java プロジェクト: adamcameron/Lucee4
  public static Struct getMemoryUsageCompact(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    Struct sct = new StructImpl();
    while (it.hasNext()) {
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP) continue;
      if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP) continue;

      double d = ((int) (100D / usage.getMax() * usage.getUsed())) / 100D;
      sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
    }
    return sct;
  }
コード例 #22
0
ファイル: Monitoring.java プロジェクト: hamsadasa/javasrc
  public static void memUsage(PrintWriter out) {

    // Overall
    MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = memBean.getHeapMemoryUsage();
    MemoryUsage nonHeap = memBean.getNonHeapMemoryUsage();
    out.println("Heap: " + heap);
    out.println("Non-heap: " + nonHeap);

    // Generations details
    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean mbean : memoryPoolMXBeans) {
      println(out, "Memory Group", mbean.getName());
      MemoryUsage memUsage = mbean.getUsage();
      println(out, "Used", memUsage.getUsed());
      println(out, "Committed", memUsage.getCommitted());
      println(out, "High water", memUsage.getMax());
      out.println();
    }
  }
コード例 #23
0
ファイル: JMXMonitor.java プロジェクト: endisd/penrose-server
  public void handleNotification(Notification notification, Object handback) {

    log.warn("================================================================================");

    String message = notification.getMessage();
    log.warn("Message: " + message);

    String type = notification.getType();
    log.warn("Type: " + type);

    if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)
        || type.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {

      CompositeData cd = (CompositeData) notification.getUserData();
      MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);

      String poolName = info.getPoolName();
      log.warn("Pool Name: " + poolName);

      long count = info.getCount();
      log.warn("Count: " + count);

      MemoryUsage usage = info.getUsage();

      long maxMemory = usage.getMax();
      long maxMB = maxMemory / (1024 * 1024);

      long usedMemory = usage.getUsed();
      long usedMB = usedMemory / (1024 * 1024);

      double percentUsed = (double) usedMemory / maxMemory;
      log.debug(
          "Used Memory : "
              + usedMB
              + "/"
              + maxMB
              + " MB ("
              + percentFormat.format(percentUsed)
              + ")");
    }
  }
コード例 #24
0
  /**
   * Returns the size of the cache.
   *
   * @return See above.
   */
  private static int getCacheSize() {
    MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    // percentage of memory used for caching.
    maxSize = (int) (RATIO * (usage.getMax() - usage.getUsed())) / FACTOR;
    int m = singleton.rndSvcProxies.size();
    int n = 0;
    int sizeCache = 0;
    RenderingControlProxy proxy;
    Entry<Long, RenderingControl> entry;
    Iterator<Entry<Long, RenderingControl>> i;
    if (singleton.pixelsSource != null) n = 1;
    if (n == 0 && m == 0) return maxSize * FACTOR;
    else if (n == 0 && m > 0) {
      sizeCache = (maxSize / (m + 1)) * FACTOR;
      // reset all the image caches.
      i = singleton.rndSvcProxies.entrySet().iterator();
      while (i.hasNext()) {
        entry = i.next();
        proxy = (RenderingControlProxy) entry.getValue();
        proxy.setCacheSize(sizeCache);
      }
      return sizeCache;
    } else if (m == 0 && n > 0) {
      sizeCache = (maxSize / (n + 1)) * FACTOR;
      return sizeCache;
    }
    sizeCache = (maxSize / (m + n + 1)) * FACTOR;
    // reset all the image caches.
    i = singleton.rndSvcProxies.entrySet().iterator();
    while (i.hasNext()) {
      entry = i.next();
      proxy = (RenderingControlProxy) entry.getValue();
      proxy.setCacheSize(sizeCache);
    }

    return sizeCache;
  }
コード例 #25
0
ファイル: SystemUtil.java プロジェクト: adamcameron/Lucee4
  public static Query getMemoryUsageAsQuery(int type) throws DatabaseException {

    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();
    Query qry =
        new QueryImpl(
            new Collection.Key[] {
              KeyConstants._name,
              KeyConstants._type,
              KeyConstants._used,
              KeyConstants._max,
              KeyConstants._init
            },
            0,
            "memory");

    int row = 0;
    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    while (it.hasNext()) {
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP) continue;
      if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP) continue;

      row++;
      qry.addRow();
      qry.setAtEL(KeyConstants._name, row, bean.getName());
      qry.setAtEL(KeyConstants._type, row, _type.name());
      qry.setAtEL(KeyConstants._max, row, Caster.toDouble(usage.getMax()));
      qry.setAtEL(KeyConstants._used, row, Caster.toDouble(usage.getUsed()));
      qry.setAtEL(KeyConstants._init, row, Caster.toDouble(usage.getInit()));
    }
    return qry;
  }
コード例 #26
0
ファイル: GCInspector.java プロジェクト: sdgdsffdsfff/icloud
  private void logIntervalGCStats() {
    for (Object gc : beans) {
      SunGcWrapper gcw = new SunGcWrapper(gc);
      if (gcw.isLastGcInfoNull()) continue;

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

      long previousMemoryUsed = 0;
      long memoryUsed = 0;
      long memoryMax = 0;
      for (Map.Entry<String, MemoryUsage> entry : gcw.getMemoryUsageBeforeGc().entrySet()) {
        previousMemoryUsed += entry.getValue().getUsed();
      }
      for (Map.Entry<String, MemoryUsage> entry : gcw.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",
              gcw.getName(),
              gcw.getDuration(),
              previousMemoryUsed - memoryUsed,
              memoryUsed,
              memoryMax);
      if (gcw.getDuration() > MIN_DURATION) logger.info(st);
      else if (logger.isDebugEnabled()) logger.debug(st);
      if (gcw.getDuration() > MIN_DURATION_TPSTATS) {
        logStats();
      }
    }
  }
コード例 #27
0
ファイル: SummaryTab.java プロジェクト: summerpulse/openjdk7
  synchronized Result formatSummary() {
    Result result = new Result();
    ProxyClient proxyClient = vmPanel.getProxyClient();
    if (proxyClient.isDead()) {
      return null;
    }

    buf = new StringBuilder();
    append("<table cellpadding=1>");

    try {
      RuntimeMXBean rmBean = proxyClient.getRuntimeMXBean();
      CompilationMXBean cmpMBean = proxyClient.getCompilationMXBean();
      ThreadMXBean tmBean = proxyClient.getThreadMXBean();
      MemoryMXBean memoryBean = proxyClient.getMemoryMXBean();
      ClassLoadingMXBean clMBean = proxyClient.getClassLoadingMXBean();
      OperatingSystemMXBean osMBean = proxyClient.getOperatingSystemMXBean();
      com.sun.management.OperatingSystemMXBean sunOSMBean =
          proxyClient.getSunOperatingSystemMXBean();

      append("<tr><td colspan=4>");
      append("<center><b>" + Messages.SUMMARY_TAB_TAB_NAME + "</b></center>");
      String dateTime = headerDateTimeFormat.format(System.currentTimeMillis());
      append("<center>" + dateTime + "</center>");

      append(newDivider);

      { // VM info
        append(newLeftTable);
        append(Messages.CONNECTION_NAME, vmPanel.getDisplayName());
        append(
            Messages.VIRTUAL_MACHINE,
            Resources.format(
                Messages.SUMMARY_TAB_VM_VERSION, rmBean.getVmName(), rmBean.getVmVersion()));
        append(Messages.VENDOR, rmBean.getVmVendor());
        append(Messages.NAME, rmBean.getName());
        append(endTable);

        append(newRightTable);
        result.upTime = rmBean.getUptime();
        append(Messages.UPTIME, formatTime(result.upTime));
        if (sunOSMBean != null) {
          result.processCpuTime = sunOSMBean.getProcessCpuTime();
          append(Messages.PROCESS_CPU_TIME, formatNanoTime(result.processCpuTime));
        }

        if (cmpMBean != null) {
          append(Messages.JIT_COMPILER, cmpMBean.getName());
          append(
              Messages.TOTAL_COMPILE_TIME,
              cmpMBean.isCompilationTimeMonitoringSupported()
                  ? formatTime(cmpMBean.getTotalCompilationTime())
                  : Messages.UNAVAILABLE);
        } else {
          append(Messages.JIT_COMPILER, Messages.UNAVAILABLE);
        }
        append(endTable);
      }

      append(newDivider);

      { // Threads and Classes
        append(newLeftTable);
        int tlCount = tmBean.getThreadCount();
        int tdCount = tmBean.getDaemonThreadCount();
        int tpCount = tmBean.getPeakThreadCount();
        long ttCount = tmBean.getTotalStartedThreadCount();
        String[] strings1 =
            formatLongs(
                tlCount, tpCount,
                tdCount, ttCount);
        append(Messages.LIVE_THREADS, strings1[0]);
        append(Messages.PEAK, strings1[1]);
        append(Messages.DAEMON_THREADS, strings1[2]);
        append(Messages.TOTAL_THREADS_STARTED, strings1[3]);
        append(endTable);

        append(newRightTable);
        long clCount = clMBean.getLoadedClassCount();
        long cuCount = clMBean.getUnloadedClassCount();
        long ctCount = clMBean.getTotalLoadedClassCount();
        String[] strings2 = formatLongs(clCount, cuCount, ctCount);
        append(Messages.CURRENT_CLASSES_LOADED, strings2[0]);
        append(Messages.TOTAL_CLASSES_LOADED, strings2[2]);
        append(Messages.TOTAL_CLASSES_UNLOADED, strings2[1]);
        append(null, "");
        append(endTable);
      }

      append(newDivider);

      { // Memory
        MemoryUsage u = memoryBean.getHeapMemoryUsage();

        append(newLeftTable);
        String[] strings1 = formatKByteStrings(u.getUsed(), u.getMax());
        append(Messages.CURRENT_HEAP_SIZE, strings1[0]);
        append(Messages.MAXIMUM_HEAP_SIZE, strings1[1]);
        append(endTable);

        append(newRightTable);
        String[] strings2 = formatKByteStrings(u.getCommitted());
        append(Messages.COMMITTED_MEMORY, strings2[0]);
        append(
            Messages.SUMMARY_TAB_PENDING_FINALIZATION_LABEL,
            Messages.SUMMARY_TAB_PENDING_FINALIZATION_VALUE,
            memoryBean.getObjectPendingFinalizationCount());
        append(endTable);

        append(newTable);
        Collection<GarbageCollectorMXBean> garbageCollectors =
            proxyClient.getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
          String gcName = garbageCollectorMBean.getName();
          long gcCount = garbageCollectorMBean.getCollectionCount();
          long gcTime = garbageCollectorMBean.getCollectionTime();

          append(
              Messages.GARBAGE_COLLECTOR,
              Resources.format(
                  Messages.GC_INFO,
                  gcName,
                  gcCount,
                  (gcTime >= 0) ? formatTime(gcTime) : Messages.UNAVAILABLE),
              4);
        }
        append(endTable);
      }

      append(newDivider);

      { // Operating System info
        append(newLeftTable);
        String osName = osMBean.getName();
        String osVersion = osMBean.getVersion();
        String osArch = osMBean.getArch();
        result.nCPUs = osMBean.getAvailableProcessors();
        append(Messages.OPERATING_SYSTEM, osName + " " + osVersion);
        append(Messages.ARCHITECTURE, osArch);
        append(Messages.NUMBER_OF_PROCESSORS, result.nCPUs + "");

        if (pathSeparator == null) {
          // Must use separator of remote OS, not File.pathSeparator
          // from this local VM. In the future, consider using
          // RuntimeMXBean to get the remote system property.
          pathSeparator = osName.startsWith("Windows ") ? ";" : ":";
        }

        if (sunOSMBean != null) {
          String[] kbStrings1 = formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());

          String[] kbStrings2 =
              formatKByteStrings(
                  sunOSMBean.getTotalPhysicalMemorySize(),
                  sunOSMBean.getFreePhysicalMemorySize(),
                  sunOSMBean.getTotalSwapSpaceSize(),
                  sunOSMBean.getFreeSwapSpaceSize());

          append(Messages.COMMITTED_VIRTUAL_MEMORY, kbStrings1[0]);
          append(endTable);

          append(newRightTable);
          append(Messages.TOTAL_PHYSICAL_MEMORY, kbStrings2[0]);
          append(Messages.FREE_PHYSICAL_MEMORY, kbStrings2[1]);
          append(Messages.TOTAL_SWAP_SPACE, kbStrings2[2]);
          append(Messages.FREE_SWAP_SPACE, kbStrings2[3]);
        }

        append(endTable);
      }

      append(newDivider);

      { // VM arguments and paths
        append(newTable);
        String args = "";
        java.util.List<String> inputArguments = rmBean.getInputArguments();
        for (String arg : inputArguments) {
          args += arg + " ";
        }
        append(Messages.VM_ARGUMENTS, args, 4);
        append(Messages.CLASS_PATH, rmBean.getClassPath(), 4);
        append(Messages.LIBRARY_PATH, rmBean.getLibraryPath(), 4);
        append(
            Messages.BOOT_CLASS_PATH,
            rmBean.isBootClassPathSupported() ? rmBean.getBootClassPath() : Messages.UNAVAILABLE,
            4);
        append(endTable);
      }
    } catch (IOException e) {
      if (JConsole.isDebug()) {
        e.printStackTrace();
      }
      proxyClient.markAsDead();
      return null;
    } catch (UndeclaredThrowableException e) {
      if (JConsole.isDebug()) {
        e.printStackTrace();
      }
      proxyClient.markAsDead();
      return null;
    }

    append("</table>");

    result.timeStamp = System.currentTimeMillis();
    result.summary = buf.toString();

    return result;
  }
コード例 #28
0
  /**
   * Show ring
   *
   * @param model
   * @throws Exception
   */
  @SuppressWarnings({"rawtypes", "unchecked"})
  @RequestMapping(value = "/ring/", method = RequestMethod.GET)
  public void describeRing(ModelMap model) throws Exception {

    NodeProbe probe = clientProvider.getProbe();
    if (probe == null) {
      // TODO JMX Connection failed
      throw new RuntimeException("JMX Connection failed.");
    }

    Set<String> liveNodes = probe.getLiveNodes();
    Set<String> deadNodes = probe.getUnreachableNodes();
    Set<String> joiningNodes = probe.getJoiningNodes();
    Set<String> leavingNodes = probe.getLeavingNodes();
    Map<String, String> loadMap = probe.getLoadMap();

    Map<Token, String> endpointMap = probe.getTokenToEndpointMap();
    List<Node> nodes = new ArrayList<Node>(endpointMap.size());
    List<Token> sortedTokens = new ArrayList<Token>(endpointMap.keySet());
    Collections.sort(sortedTokens);

    for (Object token : sortedTokens) {

      String primaryEndpoint = endpointMap.get(token);

      Node node = new Node();
      node.address = primaryEndpoint;
      node.token = token.toString();
      node.load = loadMap.get(node.address);
      node.up =
          liveNodes.contains(primaryEndpoint)
              ? "up"
              : deadNodes.contains(primaryEndpoint) ? "down" : "?";

      node.state =
          joiningNodes.contains(primaryEndpoint)
              ? "Joining"
              : leavingNodes.contains(primaryEndpoint) ? "Leaving" : "Normal";

      if (node.load == null) {
        node.load = "?";
      }
      nodes.add(node);

      NodeProbe inProbe = clientProvider.getProbe(node.address);
      if (inProbe != null) {
        node.operationMode = inProbe.getOperationMode();
        node.uptime = getUptimeString(inProbe.getUptime());
        node.jmx = true;

        MemoryUsage memory = inProbe.getHeapMemoryUsage();

        node.memoryUsed = String.format("%.2f MB", (double) memory.getUsed() / (1024 * 1024));
        node.memoryMax = String.format("%.2f MB", (double) memory.getMax() / (1024 * 1024));
        node.memoryCommited =
            String.format("%.2f MB", (double) memory.getCommitted() / (1024 * 1024));
      }
    }

    // List live nodes which are not in range.
    for (String deadAddress : deadNodes) {
      Node deadNode = new Node();
      deadNode.address = deadAddress;
      deadNode.load = loadMap.get(deadAddress);
      NodeProbe inProbe = clientProvider.getProbe(deadAddress);
      if (inProbe != null) {
        deadNode.operationMode = inProbe.getOperationMode();
        deadNode.uptime = getUptimeString(inProbe.getUptime());
      }
    }

    model.put("nodes", nodes);
    model.put("menu_ring", Boolean.TRUE);
  }
コード例 #29
0
ファイル: StatsUtil.java プロジェクト: alokhan/l2walker
 public static long getMemFree() {
   MemoryUsage heapMemoryUsage = memMXbean.getHeapMemoryUsage();
   return (heapMemoryUsage.getMax() - heapMemoryUsage.getUsed());
 }
コード例 #30
0
  /*
   * (non-Javadoc)
   *
   * @see com.orientechnologies.common.test.SpeedTest#collectResults(long)
   */
  public void collectResults(final long elapsed) {
    Runtime.getRuntime().runFinalization();
    Runtime.getRuntime().gc();

    final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    final MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
    final MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
    final int objectsPendingFinalizationCount = memoryMXBean.getObjectPendingFinalizationCount();

    final long nowHeapCommittedMemory = heapMemoryUsage.getCommitted();
    final long nowHeapUsedMemory = heapMemoryUsage.getUsed();
    final long nowHeapMaxMemory = heapMemoryUsage.getMax();

    final long heapCommittedMemory = nowHeapCommittedMemory - currentTestHeapCommittedMemory;
    final long heapUsedMemory = nowHeapUsedMemory - currentTestHeapUsedMemory;
    final long heapMaxMemory = nowHeapMaxMemory - currentTestHeapMaxMemory;

    final long nowNonHeapCommittedMemory = nonHeapMemoryUsage.getCommitted();
    final long nowNonHeapUsedMemory = nonHeapMemoryUsage.getUsed();
    final long nowNonHeapMaxMemory = nonHeapMemoryUsage.getMax();

    final long nonHeapCommittedMemory =
        nowNonHeapCommittedMemory - currentTestNonHeapCommittedMemory;
    final long nonHeapUsedMemory = nowNonHeapUsedMemory - currentTestNonHeapUsedMemory;
    final long nonHeapMaxMemory = nowNonHeapMaxMemory - currentTestNonHeapMaxMemory;

    if (printResults) {
      System.out.println();
      System.out.println(
          "   Completed the test of '"
              + currentTestName
              + "' in "
              + elapsed
              + " ms. Heap memory used: "
              + nowHeapUsedMemory
              + " bytes. Non heap memory used: "
              + nowNonHeapUsedMemory
              + " .");
      System.out.println("   Cycles done.......................: " + cyclesDone + "/" + cycles);
      System.out.println("   Cycles Elapsed....................: " + cyclesElapsed + " ms");
      System.out.println("   Elapsed...........................: " + elapsed + " ms");
      System.out.println(
          "   Medium cycle elapsed:.............: "
              + (cyclesDone > 0 && elapsed > 0
                  ? new BigDecimal((float) elapsed / cyclesDone).toPlainString()
                  : 0));
      System.out.println(
          "   Cycles per second.................: "
              + new BigDecimal((float) cyclesDone / elapsed * 1000).toPlainString());
      System.out.println(
          "   Committed heap memory diff........: "
              + heapCommittedMemory
              + " ("
              + currentTestHeapCommittedMemory
              + "->"
              + nowHeapCommittedMemory
              + ")");
      System.out.println(
          "   Used heap memory diff.............: "
              + heapUsedMemory
              + " ("
              + currentTestHeapUsedMemory
              + "->"
              + nowHeapUsedMemory
              + ")");
      System.out.println(
          "   Max heap memory diff..............: "
              + heapMaxMemory
              + " ("
              + currentTestHeapMaxMemory
              + "->"
              + nowHeapMaxMemory
              + ")");
      System.out.println(
          "   Committed non heap memory diff....: "
              + nonHeapCommittedMemory
              + " ("
              + currentTestNonHeapCommittedMemory
              + "->"
              + nowNonHeapCommittedMemory
              + ")");
      System.out.println(
          "   Used non heap memory diff.........: "
              + nonHeapUsedMemory
              + " ("
              + currentTestNonHeapUsedMemory
              + "->"
              + nowNonHeapUsedMemory
              + ")");
      System.out.println(
          "   Max non heap memory diff..........: "
              + nonHeapMaxMemory
              + " ("
              + currentTestNonHeapMaxMemory
              + "->"
              + nowNonHeapMaxMemory
              + ")");
      System.out.println(
          "   Objects pending finalization......: " + objectsPendingFinalizationCount);

      System.out.println();
    }

    if (testGroup != null) {
      testGroup.setResult("Execution time", currentTestName, elapsed);
      testGroup.setResult("Free memory", currentTestName, heapCommittedMemory);
    }

    currentTestHeapCommittedMemory = heapCommittedMemory;
    currentTestHeapUsedMemory = heapUsedMemory;
    currentTestHeapMaxMemory = heapMaxMemory;

    currentTestNonHeapCommittedMemory = nonHeapCommittedMemory;
    currentTestNonHeapUsedMemory = nonHeapUsedMemory;
    currentTestNonHeapMaxMemory = nonHeapMaxMemory;
  }