karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-2688) Karaf info - Add memory details about perm gen pool
Date Sun, 18 Feb 2018 06:31:00 GMT

    [ https://issues.apache.org/jira/browse/KARAF-2688?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16368450#comment-16368450
] 

ASF GitHub Bot commented on KARAF-2688:
---------------------------------------

jbonofre closed pull request #452: [KARAF-2688] Adding information about memory pools.
URL: https://github.com/apache/karaf/pull/452
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/InfoAction.java
b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/InfoAction.java
index 3311bd9720..22dea86509 100644
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/InfoAction.java
+++ b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/InfoAction.java
@@ -20,6 +20,9 @@
 import java.lang.management.GarbageCollectorMXBean;
 import java.lang.management.ManagementFactory;
 import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.MemoryType;
+import java.lang.management.MemoryUsage;
 import java.lang.management.OperatingSystemMXBean;
 import java.lang.management.RuntimeMXBean;
 import java.lang.management.ThreadMXBean;
@@ -40,6 +43,7 @@
 import org.apache.karaf.shell.commands.info.InfoProvider;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.apache.karaf.shell.support.ansi.SimpleAnsi;
 import org.osgi.framework.Bundle;
@@ -51,17 +55,26 @@
 public class InfoAction implements Action {
 
     private NumberFormat fmtI = new DecimalFormat("###,###", new DecimalFormatSymbols(Locale.ENGLISH));
+    private NumberFormat fmtDec = new DecimalFormat("###,###.##", new DecimalFormatSymbols(Locale.ENGLISH));
     private NumberFormat fmtD = new DecimalFormat("###,##0.000", new DecimalFormatSymbols(Locale.ENGLISH));
 
+    private OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
+
+    @Option(name="--memory-pools", aliases= {"-mp"}, description="Includes detailed information
about memory pools")
+    protected boolean showMemoryPools;
+
 //    @Reference
     List<InfoProvider> infoProviders;
 
+    public InfoAction() {
+        fmtDec.setMinimumFractionDigits(2);
+    }
+
     @Override
     public Object execute() throws Exception {
         int maxNameLen;
 
         RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
-        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
         ThreadMXBean threads = ManagementFactory.getThreadMXBean();
         MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
         ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
@@ -87,7 +100,16 @@ public Object execute() throws Exception {
         printValue("Pid", maxNameLen, getPid());
         printValue("Uptime", maxNameLen, printDuration(runtime.getUptime()));
         try {
-            printValue("Process CPU time", maxNameLen, printDuration(getSunOsValueAsLong(os,
"getProcessCpuTime") / 1000000));
+            Class< ? > sunOS = Class.forName("com.sun.management.OperatingSystemMXBean");
+            printValue("Process CPU time", maxNameLen, printDuration(getValueAsLong(sunOS,
"getProcessCpuTime") / 1000000));
+            printValue("Process CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS,
"getProcessCpuLoad")));
+            printValue("System CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS,
"getSystemCpuLoad")));
+        } catch (Throwable t) {
+        }
+        try {
+            Class<?> unixOS = Class.forName("com.sun.management.UnixOperatingSystemMXBean");
+            printValue("Open file descriptors", maxNameLen, printLong(getValueAsLong(unixOS,
"getOpenFileDescriptorCount")));
+            printValue("Max file descriptors", maxNameLen, printLong(getValueAsLong(unixOS,
"getMaxFileDescriptorCount")));
         } catch (Throwable t) {
         }
         printValue("Total compile time", maxNameLen, printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime()));
@@ -108,6 +130,45 @@ public Object execute() throws Exception {
             printValue("Garbage collector", maxNameLen, val);
         }
 
+        if (showMemoryPools) {
+            List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
+            System.out.println("Memory Pools");
+            printValue("Total Memory Pools", maxNameLen, printLong(memoryPools.size()));
+            String spaces4 = "   ";
+            for (MemoryPoolMXBean pool : memoryPools)
+            {
+                String name = pool.getName();
+                MemoryType type = pool.getType();
+                printValue(spaces4 + "Pool (" + type + ")", maxNameLen, name);
+
+                // PeakUsage/CurrentUsage
+                MemoryUsage peakUsage = pool.getPeakUsage();
+                MemoryUsage usage = pool.getUsage();
+
+                if (usage != null && peakUsage != null) {
+                    long init = peakUsage.getInit();
+                    long used = peakUsage.getUsed();
+                    long committed = peakUsage.getCommitted();
+                    long max = peakUsage.getMax();
+                    System.out.println(spaces4 + spaces4 + "Peak Usage");
+                    printValue(spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
+                    printValue(spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
+                    printValue(spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
+                    printValue(spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
+
+                    init = usage.getInit();
+                    used = usage.getUsed();
+                    committed = usage.getCommitted();
+                    max = usage.getMax();
+                    System.out.println(spaces4 + spaces4 + "Current Usage");
+                    printValue(spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
+                    printValue(spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
+                    printValue(spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
+                    printValue(spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
+                }
+            }
+        }
+
         System.out.println("Classes");
         printValue("Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount()));
         printValue("Total classes loaded", maxNameLen, printLong(cl.getTotalLoadedClassCount()));
@@ -156,16 +217,35 @@ public Object execute() throws Exception {
     }
 
     private String getPid() {
-    	String name = ManagementFactory.getRuntimeMXBean().getName();
-    	String[] parts = name.split("@");
-		return parts[0];
-	}
+        // In Java 9 the new process API can be used:
+        // long pid = ProcessHandle.current().getPid();
+        String name = ManagementFactory.getRuntimeMXBean().getName();
+        String[] parts = name.split("@");
+        return parts[0];
+    }
 
-	private long getSunOsValueAsLong(OperatingSystemMXBean os, String name) throws Exception
{
+    private long getSunOsValueAsLong(OperatingSystemMXBean os, String name) throws Exception
{
         Method mth = os.getClass().getMethod(name);
         return (Long) mth.invoke(os);
     }
 
+    private long getValueAsLong(Class<?> osImpl, String name) throws Exception {
+        if (osImpl.isInstance(os))
+        {
+            Method mth = osImpl.getMethod(name);
+            return (Long) mth.invoke(os);
+        }
+        return -1;
+    }
+
+    private double getValueAsDouble(Class<?> osImpl, String name) throws Exception
{
+        if (osImpl.isInstance(os)) {
+            Method mth = osImpl.getMethod(name);
+            return (Double) mth.invoke(os);
+        }
+        return -1;
+    }
+
     private String printLong(long i) {
         return fmtI.format(i);
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Karaf info - Add memory details about perm gen pool
> ---------------------------------------------------
>
>                 Key: KARAF-2688
>                 URL: https://issues.apache.org/jira/browse/KARAF-2688
>             Project: Karaf
>          Issue Type: Improvement
>          Components: karaf-core, karaf-shell
>    Affects Versions: 2.3.3
>            Reporter: Claus Ibsen
>            Assignee: Jean-Baptiste Onofré
>            Priority: Minor
>             Fix For: 4.2.0
>
>         Attachments: Screen Shot 2014-01-16 at 3.05.16 PM.png
>
>
> When running the info command you get some JVM details
> For memory you get
> {code}
> Memory
>   Current heap size           90,407 kbytes
>   Maximum heap size           521,216 kbytes
>   Committed heap size         106,496 kbytes
> {code}
> It would be good to have the perm-gen pool as well. As if you are running out of perm
gen you are fucked. The GC cannot reclaim perm gen memory.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message