felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1784697 - in /felix/trunk/webconsole-plugins/memoryusage: changelog.txt src/main/java/org/apache/felix/webconsole/plugins/memoryusage/internal/MemoryUsageSupport.java
Date Tue, 28 Feb 2017 07:36:36 GMT
Author: cziegeler
Date: Tue Feb 28 07:36:36 2017
New Revision: 1784697

URL: http://svn.apache.org/viewvc?rev=1784697&view=rev
Log:
FELIX-4019 - Memory Management Plugin does not handle unknown values properly

Modified:
    felix/trunk/webconsole-plugins/memoryusage/changelog.txt
    felix/trunk/webconsole-plugins/memoryusage/src/main/java/org/apache/felix/webconsole/plugins/memoryusage/internal/MemoryUsageSupport.java

Modified: felix/trunk/webconsole-plugins/memoryusage/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/memoryusage/changelog.txt?rev=1784697&r1=1784696&r2=1784697&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/memoryusage/changelog.txt (original)
+++ felix/trunk/webconsole-plugins/memoryusage/changelog.txt Tue Feb 28 07:36:36 2017
@@ -2,6 +2,7 @@ Changes from 1.0.6 to 1.0.8
 ---------------------------
 ** Bug
     * [FELIX-5552] - Handle MemoryPoolMXBean.getUsed returning -1
+    * [FELIX-4019] - Memory Management Plugin does not handle unknown values properly
 
 
 Changes from 1.0.4 to 1.0.6

Modified: felix/trunk/webconsole-plugins/memoryusage/src/main/java/org/apache/felix/webconsole/plugins/memoryusage/internal/MemoryUsageSupport.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/memoryusage/src/main/java/org/apache/felix/webconsole/plugins/memoryusage/internal/MemoryUsageSupport.java?rev=1784697&r1=1784696&r2=1784697&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/memoryusage/src/main/java/org/apache/felix/webconsole/plugins/memoryusage/internal/MemoryUsageSupport.java
(original)
+++ felix/trunk/webconsole-plugins/memoryusage/src/main/java/org/apache/felix/webconsole/plugins/memoryusage/internal/MemoryUsageSupport.java
Tue Feb 28 07:36:36 2017
@@ -366,19 +366,33 @@ final class MemoryUsageSupport implement
             buf.append(",'type':'").append(pool.getType()).append('\'');
 
             MemoryUsage usage = pool.getUsage();
-            usedTotal += formatNumber(buf, "used", usage.getUsed());
-            initTotal += formatNumber(buf, "init", usage.getInit());
-            committedTotal += formatNumber(buf, "committed", usage.getCommitted());
-            maxTotal += formatNumber(buf, "max", usage.getMax());
+            final long used = usage.getUsed();
+            formatNumber(buf, "used", used);
+            if ( used > -1 )
+            {
+                usedTotal += used;
+            }
+            final long init = usage.getInit();
+            formatNumber(buf, "init", init);
+            if ( init > - 1 )
+            {
+                initTotal +=  init;
+            }
+            final long committed = usage.getCommitted();
+            formatNumber(buf, "committed", committed);
+            committedTotal += committed;
+            final long max = usage.getMax();
+            formatNumber(buf, "max", usage.getMax());
 
             final long score;
-            if ( usage.getMax() == -1 )
+            if ( max == -1 || used == -1 )
             {
                 score = 100;
             }
             else
             {
-                score = 100L * usage.getUsed() / usage.getMax();
+                maxTotal += max;
+                score = 100L * used / max;
             }
             buf.append(",'score':'").append(score).append("%'");
 
@@ -402,7 +416,7 @@ final class MemoryUsageSupport implement
         return buf.toString();
     }
 
-    long formatNumber(final StringBuilder buf, final String title, final long value)
+    void formatNumber(final StringBuilder buf, final String title, final long value)
     {
 
         final BigDecimal KB = new BigDecimal(1000L);
@@ -426,13 +440,25 @@ final class MemoryUsageSupport implement
             bd = bd.divide(KB);
             suffix = "kB";
         }
-        else
+        else if (value >= 0 )
         {
             suffix = "B";
         }
-        bd = bd.setScale(2, RoundingMode.UP);
-        buf.append(",'").append(title).append("':'").append(bd).append(suffix).append('\'');
-        return value;
+        else
+        {
+            suffix = null;
+        }
+        buf.append(",'").append(title).append("':'");
+        if ( suffix == null )
+        {
+            buf.append("unknown");
+        }
+        else
+        {
+            bd = bd.setScale(2, RoundingMode.UP);
+            buf.append(bd).append(suffix);
+        }
+        buf.append('\'');
     }
 
     final String getDefaultDumpLocation()



Mime
View raw message