[jboss-cvs] JBoss Messaging SVN: r7731 - in trunk/src/main/org/jboss/messaging: utils and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 14 11:39:00 EDT 2009
Author: jmesnil
Date: 2009-08-14 11:39:00 -0400 (Fri, 14 Aug 2009)
New Revision: 7731
Added:
trunk/src/main/org/jboss/messaging/utils/SizeFormatterUtil.java
Modified:
trunk/src/main/org/jboss/messaging/core/server/impl/MemoryManagerImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerInfo.java
Log:
Memory info
* fixed computation of free memory percentage in MemoryManagerImpl
* moved code to display pretty memory sizes in SizeFormatterUtil
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MemoryManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MemoryManagerImpl.java 2009-08-14 14:51:58 UTC (rev 7730)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MemoryManagerImpl.java 2009-08-14 15:39:00 UTC (rev 7731)
@@ -23,6 +23,7 @@
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.server.MemoryManager;
+import org.jboss.messaging.utils.SizeFormatterUtil;
/**
* A MemoryManager
@@ -142,20 +143,26 @@
long totalMemory = runtime.totalMemory();
- long availableMemory = maxMemory - totalMemory;
+ long freeMemory = runtime.freeMemory();
- double currentFreeMemoryPercent = 100 * (double)availableMemory / maxMemory;
+ double currentFreeMemoryPercent = 100.0 * freeMemory / totalMemory;
- log.info("Free memory " + currentFreeMemoryPercent + "% " +
- " Calculated available memory " + availableMemory +
- " Total mem " + totalMemory);
+ String info = "";
+ info += String.format("free memory: %s\n", SizeFormatterUtil.sizeof(freeMemory));
+ info += String.format("max memory: %s\n", SizeFormatterUtil.sizeof(maxMemory));
+ info += String.format("total memory: %s\n", SizeFormatterUtil.sizeof(totalMemory));
+ info += String.format("available memory: %.2f%%\n", currentFreeMemoryPercent);
+
+ if (log.isDebugEnabled())
+ {
+ log.debug(info);
+ }
if (currentFreeMemoryPercent <= freeMemoryPercent)
{
- log.warn("Less than " + freeMemoryPercent + "% (" + currentFreeMemoryPercent + "% total: " + totalMemory +
- " available " + availableMemory
- + ") of total available memory free. " +
- "You are in danger of running out of RAM. Have you set paging parameters " +
+ log.warn("Less than " + freeMemoryPercent + "%\n"
+ + info +
+ "\nYou are in danger of running out of RAM. Have you set paging parameters " +
"on your addresses? (See user manual \"Paging\" chapter)");
low = true;
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerInfo.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerInfo.java 2009-08-14 14:51:58 UTC (rev 7730)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerInfo.java 2009-08-14 15:39:00 UTC (rev 7731)
@@ -32,6 +32,7 @@
import org.jboss.messaging.core.paging.PagingStore;
import org.jboss.messaging.core.server.MessagingServer;
import org.jboss.messaging.utils.SimpleString;
+import org.jboss.messaging.utils.SizeFormatterUtil;
/**
* A ServerInfo
@@ -71,11 +72,11 @@
String info = "\n**** Server Dump ****\n";
info += String.format("date: %s\n", new Date());
info += String.format("heap memory: used=%s, max=%s\n",
- sizeof(heapMemory.getUsed()),
- sizeof(heapMemory.getMax()));
+ SizeFormatterUtil.sizeof(heapMemory.getUsed()),
+ SizeFormatterUtil.sizeof(heapMemory.getMax()));
info += String.format("non-heap memory: used=%s, max=%s\n",
- sizeof(nonHeapMemory.getUsed()),
- sizeof(nonHeapMemory.getMax()));
+ SizeFormatterUtil.sizeof(nonHeapMemory.getUsed()),
+ SizeFormatterUtil.sizeof(nonHeapMemory.getMax()));
info += appendPagingInfos();
info += String.format("# of thread: %d\n", threadMXBean.getThreadCount());
info += String.format("# of conns: %d\n", server.getConnectionCount());
@@ -92,14 +93,14 @@
private String appendPagingInfos()
{
String info = "";
- info += String.format("total paging memory: %s\n", sizeof(pagingManager.getTotalMemory()));
+ info += String.format("total paging memory: %s\n", SizeFormatterUtil.sizeof(pagingManager.getTotalMemory()));
for (SimpleString storeName : pagingManager.getStoreNames())
{
PagingStore pageStore;
try
{
pageStore = pagingManager.getPageStore(storeName);
- info += String.format("\t%s: %s\n", storeName, sizeof(pageStore.getPageSizeBytes() * pageStore.getNumberOfPages()));
+ info += String.format("\t%s: %s\n", storeName, SizeFormatterUtil.sizeof(pageStore.getPageSizeBytes() * pageStore.getNumberOfPages()));
}
catch (Exception e)
{
@@ -109,34 +110,6 @@
return info;
}
- private static long oneKiB = 1024;
-
- private static long oneMiB = oneKiB * 1024;
-
- private static long oneGiB = oneMiB * 1024;
-
- private static String sizeof(long size)
- {
- double s = Long.valueOf(size).doubleValue();
- String suffix = "B";
- if (s > oneGiB)
- {
- s /= oneGiB;
- suffix = "GiB";
- }
- else if (s > oneMiB)
- {
- s /= oneMiB;
- suffix = "MiB";
- }
- else if (s > oneKiB)
- {
- s /= oneKiB;
- suffix = "kiB";
- }
- return String.format("%.2f %s", s, suffix);
- }
-
// Inner classes -------------------------------------------------
}
Added: trunk/src/main/org/jboss/messaging/utils/SizeFormatterUtil.java
===================================================================
--- trunk/src/main/org/jboss/messaging/utils/SizeFormatterUtil.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/utils/SizeFormatterUtil.java 2009-08-14 15:39:00 UTC (rev 7731)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.utils;
+
+/**
+ * A SizeFormatterUtil
+ *
+ * @author <a href="mailto:jmesnil at gmail.com>Jeff Mesnil</a>
+ *
+ *
+ */
+public class SizeFormatterUtil
+{
+
+ // Constants -----------------------------------------------------
+
+ private static long oneKiB = 1024;
+
+ private static long oneMiB = oneKiB * 1024;
+
+ private static long oneGiB = oneMiB * 1024;
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ public static String sizeof(long size)
+ {
+ double s = Long.valueOf(size).doubleValue();
+ String suffix = "B";
+ if (s > oneGiB)
+ {
+ s /= oneGiB;
+ suffix = "GiB";
+ }
+ else if (s > oneMiB)
+ {
+ s /= oneMiB;
+ suffix = "MiB";
+ }
+ else if (s > oneKiB)
+ {
+ s /= oneKiB;
+ suffix = "kiB";
+ }
+ return String.format("%.2f %s", s, suffix);
+ }
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
More information about the jboss-cvs-commits
mailing list