You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ma...@apache.org on 2009/06/25 17:28:54 UTC
svn commit: r788392 - in /lucene/solr/trunk: CHANGES.txt
src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
Author: markrmiller
Date: Thu Jun 25 15:28:53 2009
New Revision: 788392
URL: http://svn.apache.org/viewvc?rev=788392&view=rev
Log:
SOLR-1242: Human readable JVM info from system handler does integer cutoff rounding, even when dealing with GB. Fixed to round to one decimal place.
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=788392&r1=788391&r2=788392&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Thu Jun 25 15:28:53 2009
@@ -422,6 +422,9 @@
49. SOLR-1207: equals method should compare this and other of DocList in DocSetBase (koji)
+50. SOLR-1242: Human readable JVM info from system handler does integer cutoff rounding, even when dealing
+ with GB. Fixed to round to one decimal place. (Jay Hill, Mark Miller)
+
Other Changes
----------------------
Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java?rev=788392&r1=788391&r2=788392&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java Thu Jun 25 15:28:53 2009
@@ -26,9 +26,9 @@
import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.text.DecimalFormat;
import java.util.Date;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.LucenePackage;
import org.apache.solr.common.util.NamedList;
@@ -192,15 +192,16 @@
jvm.add( "processors", runtime.availableProcessors() );
long used = runtime.totalMemory() - runtime.freeMemory();
- int percentUsed = (int)(((double)(used)/(double)runtime.maxMemory())*100);
+ // not thread safe, but could be thread local
+ DecimalFormat df = new DecimalFormat("#.#");
+ double percentUsed = ((double)(used)/(double)runtime.maxMemory())*100;
-
SimpleOrderedMap<Object> mem = new SimpleOrderedMap<Object>();
- mem.add( "free", FileUtils.byteCountToDisplaySize( runtime.freeMemory() ) );
- mem.add( "total", FileUtils.byteCountToDisplaySize( runtime.totalMemory() ) );
- mem.add( "max", FileUtils.byteCountToDisplaySize( runtime.maxMemory() ) );
- mem.add( "used", FileUtils.byteCountToDisplaySize( used ) + " (%"+percentUsed+")");
- jvm.add( "memory", mem );
+ mem.add("free", humanReadableUnits(runtime.freeMemory(), df));
+ mem.add("total", humanReadableUnits(runtime.totalMemory(), df));
+ mem.add("max", humanReadableUnits(runtime.maxMemory(), df));
+ mem.add("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")");
+ jvm.add("memory", mem);
// JMX properties -- probably should be moved to a different handler
SimpleOrderedMap<Object> jmx = new SimpleOrderedMap<Object>();
@@ -292,6 +293,30 @@
public String getSource() {
return "$URL$";
}
+
+ private static final long ONE_KB = 1024;
+ private static final long ONE_MB = ONE_KB * ONE_KB;
+ private static final long ONE_GB = ONE_KB * ONE_MB;
+
+ /**
+ * Return good default units based on byte size.
+ */
+ private static String humanReadableUnits(long bytes, DecimalFormat df) {
+ String newSizeAndUnits;
+
+ if (bytes / ONE_GB > 0) {
+ newSizeAndUnits = String.valueOf(df.format((float)bytes / ONE_GB)) + " GB";
+ } else if (bytes / ONE_MB > 0) {
+ newSizeAndUnits = String.valueOf(df.format((float)bytes / ONE_MB)) + " MB";
+ } else if (bytes / ONE_KB > 0) {
+ newSizeAndUnits = String.valueOf(df.format((float)bytes / ONE_KB)) + " KB";
+ } else {
+ newSizeAndUnits = String.valueOf(bytes) + " bytes";
+ }
+
+ return newSizeAndUnits;
+ }
+
}