You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2013/05/11 12:48:33 UTC

svn commit: r1481288 - /tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java

Author: rjung
Date: Sat May 11 10:48:33 2013
New Revision: 1481288

URL: http://svn.apache.org/r1481288
Log:
Make remaining MXBean methods that trigger
an action or change data available in
Diagnostics API.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java?rev=1481288&r1=1481287&r2=1481288&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java Sat May 11 10:48:33 2013
@@ -19,13 +19,18 @@
 // XXX TODO: More JavaDoc
 // XXX Optional: Add support for com.sun.management specific mbean
 //               (http://docs.oracle.com/javase/7/docs/jre/api/management/extension/index.html)
-// XXX Optional: Wire setters to the manager:
-//               log level setter, verbose class loading setter,
-//               setVerbose() and gc() in MemoryMXBean,
-//               resetPeakUsage(), setUsageThreshold() and
-//               setCollectionUsageThreshold() in MemoryPoolMXBean,
-//               and threadMXBean setters, probably even for
-//               com.sun.management like HotSpotDiagnosticMXBean.
+// XXX Optional: Wire additional public static methods implemented here
+//               to the manager (think about manager access roles!)
+//                 setLoggerLevel(),
+//                 setVerboseClassLoading(),
+//                 setThreadContentionMonitoringEnabled(),
+//                 setThreadCpuTimeEnabled(),
+//                 resetPeakThreadCount(),
+//                 setVerboseGarbageCollection()
+//                 gc(),
+//                 resetPeakUsage(),
+//                 setUsageThreshold(),
+//                 setCollectionUsageThreshold()
 
 package org.apache.tomcat.util;
 
@@ -184,6 +189,84 @@ public class Diagnostics {
     }
 
     /**
+     * Set verbose garbage collection logging
+     *
+     * @param verbose whether to enable verbose gc logging
+     */
+    public static void setVerboseGarbageCollection(boolean verbose) {
+        memoryMXBean.setVerbose(verbose);
+        boolean checkValue = memoryMXBean.isVerbose();
+        if (verbose != checkValue) {
+            log.error("Could not set verbose garbage collection logging to " + verbose +
+                      ", got " + checkValue + " instead");
+        }
+    }
+
+    /**
+     * Initiate garbage collection via MX Bean
+     */
+    public static void gc() {
+        memoryMXBean.gc();
+    }
+
+    /**
+     * Reset peak memory usage data in MemoryPoolMXBean
+     *
+     * @param name name of the MemoryPoolMXBean or "all"
+     */
+    public static void resetPeakUsage(String name) {
+        for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
+            if (name.equals("all") || name.equals(mbean.getName())) {
+                mbean.resetPeakUsage();
+            }
+        }
+    }
+
+    /**
+     * Reset peak memory usage data in MemoryPoolMXBean
+     *
+     * @param name name of the MemoryPoolMXBean
+     */
+    public static boolean setUsageThreshold(String name, long threshold) {
+        for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
+            if (name.equals(mbean.getName())) {
+                try {
+                    mbean.setUsageThreshold(threshold);
+                    return true;
+                } catch (IllegalArgumentException ex) {
+                    // IGNORE
+                } catch (UnsupportedOperationException ex) {
+                    // IGNORE
+                }
+                return false;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Reset peak memory collection usage data in MemoryPoolMXBean
+     *
+     * @param name name of the MemoryPoolMXBean
+     */
+    public static boolean setCollectionUsageThreshold(String name, long threshold) {
+        for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
+            if (name.equals(mbean.getName())) {
+                try {
+                    mbean.setCollectionUsageThreshold(threshold);
+                    return true;
+                } catch (IllegalArgumentException ex) {
+                    // IGNORE
+                } catch (UnsupportedOperationException ex) {
+                    // IGNORE
+                }
+                return false;
+            }
+        }
+        return false;
+    }
+
+    /**
      * Formats the thread dump header for one thread.
      *
      * @param ti the ThreadInfo describing the thread



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1481288 - /tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java

Posted by Rainer Jung <ra...@kippdata.de>.
Thanks for this and the other mail. Should be all fixed now.
Concerning the StringManager: I had simply forgotten to
commit the changes :(

Regards,

Rainer

On 11.05.2013 20:02, Konstantin Kolinko wrote:
> 2013/5/11  <rj...@apache.org>:
>> Author: rjung
>> Date: Sat May 11 10:48:33 2013
>> New Revision: 1481288
>>
>> URL: http://svn.apache.org/r1481288
>> Log:
>> Make remaining MXBean methods that trigger
>> an action or change data available in
>> Diagnostics API.
>>
>> Modified:
>>     tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java
>>
>> Modified: tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java
>> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java?rev=1481288&r1=1481287&r2=1481288&view=diff
>> ==============================================================================
>> --- tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java (original)
>> +++ tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java Sat May 11 10:48:33 2013
>> @@ -19,13 +19,18 @@
>>  // XXX TODO: More JavaDoc
>>  // XXX Optional: Add support for com.sun.management specific mbean
>>  //               (http://docs.oracle.com/javase/7/docs/jre/api/management/extension/index.html)
>> -// XXX Optional: Wire setters to the manager:
>> -//               log level setter, verbose class loading setter,
>> -//               setVerbose() and gc() in MemoryMXBean,
>> -//               resetPeakUsage(), setUsageThreshold() and
>> -//               setCollectionUsageThreshold() in MemoryPoolMXBean,
>> -//               and threadMXBean setters, probably even for
>> -//               com.sun.management like HotSpotDiagnosticMXBean.
>> +// XXX Optional: Wire additional public static methods implemented here
>> +//               to the manager (think about manager access roles!)
>> +//                 setLoggerLevel(),
>> +//                 setVerboseClassLoading(),
>> +//                 setThreadContentionMonitoringEnabled(),
>> +//                 setThreadCpuTimeEnabled(),
>> +//                 resetPeakThreadCount(),
>> +//                 setVerboseGarbageCollection()
>> +//                 gc(),
>> +//                 resetPeakUsage(),
>> +//                 setUsageThreshold(),
>> +//                 setCollectionUsageThreshold()
>>
>>  package org.apache.tomcat.util;
>>
>> @@ -184,6 +189,84 @@ public class Diagnostics {
>>      }
>>
>>      /**
>> +     * Set verbose garbage collection logging
>> +     *
>> +     * @param verbose whether to enable verbose gc logging
>> +     */
>> +    public static void setVerboseGarbageCollection(boolean verbose) {
>> +        memoryMXBean.setVerbose(verbose);
>> +        boolean checkValue = memoryMXBean.isVerbose();
>> +        if (verbose != checkValue) {
>> +            log.error("Could not set verbose garbage collection logging to " + verbose +
>> +                      ", got " + checkValue + " instead");
>> +        }
>> +    }
>> +
>> +    /**
>> +     * Initiate garbage collection via MX Bean
>> +     */
>> +    public static void gc() {
>> +        memoryMXBean.gc();
>> +    }
>> +
>> +    /**
>> +     * Reset peak memory usage data in MemoryPoolMXBean
>> +     *
>> +     * @param name name of the MemoryPoolMXBean or "all"
>> +     */
>> +    public static void resetPeakUsage(String name) {
>> +        for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
>> +            if (name.equals("all") || name.equals(mbean.getName())) {
>> +                mbean.resetPeakUsage();
>> +            }
>> +        }
>> +    }
>> +
>> +    /**
>> +     * Reset peak memory usage data in MemoryPoolMXBean
> 
> The above Javadoc is wrong (it is the same as for the previous method).
> 
>> +     *
>> +     * @param name name of the MemoryPoolMXBean
>> +     */
>> +    public static boolean setUsageThreshold(String name, long threshold) {
>> +        for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
>> +            if (name.equals(mbean.getName())) {
>> +                try {
>> +                    mbean.setUsageThreshold(threshold);
>> +                    return true;
>> +                } catch (IllegalArgumentException ex) {
>> +                    // IGNORE
>> +                } catch (UnsupportedOperationException ex) {
>> +                    // IGNORE
>> +                }
>> +                return false;
>> +            }
>> +        }
>> +        return false;
>> +    }
>> +
>> +    /**
>> +     * Reset peak memory collection usage data in MemoryPoolMXBean
>> +     *
> 
> The same here.
> 
>> +     * @param name name of the MemoryPoolMXBean
>> +     */
>> +    public static boolean setCollectionUsageThreshold(String name, long threshold) {
>> +        for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
>> +            if (name.equals(mbean.getName())) {
>> +                try {
>> +                    mbean.setCollectionUsageThreshold(threshold);
>> +                    return true;
>> +                } catch (IllegalArgumentException ex) {
>> +                    // IGNORE
>> +                } catch (UnsupportedOperationException ex) {
>> +                    // IGNORE
>> +                }
>> +                return false;
>> +            }
>> +        }
>> +        return false;
>> +    }
>> +
>> +    /**
>>       * Formats the thread dump header for one thread.
>>       *
>>       * @param ti the ThreadInfo describing the thread
> 
> 
> Best regards,
> Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1481288 - /tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/5/11  <rj...@apache.org>:
> Author: rjung
> Date: Sat May 11 10:48:33 2013
> New Revision: 1481288
>
> URL: http://svn.apache.org/r1481288
> Log:
> Make remaining MXBean methods that trigger
> an action or change data available in
> Diagnostics API.
>
> Modified:
>     tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java
>
> Modified: tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java?rev=1481288&r1=1481287&r2=1481288&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java (original)
> +++ tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java Sat May 11 10:48:33 2013
> @@ -19,13 +19,18 @@
>  // XXX TODO: More JavaDoc
>  // XXX Optional: Add support for com.sun.management specific mbean
>  //               (http://docs.oracle.com/javase/7/docs/jre/api/management/extension/index.html)
> -// XXX Optional: Wire setters to the manager:
> -//               log level setter, verbose class loading setter,
> -//               setVerbose() and gc() in MemoryMXBean,
> -//               resetPeakUsage(), setUsageThreshold() and
> -//               setCollectionUsageThreshold() in MemoryPoolMXBean,
> -//               and threadMXBean setters, probably even for
> -//               com.sun.management like HotSpotDiagnosticMXBean.
> +// XXX Optional: Wire additional public static methods implemented here
> +//               to the manager (think about manager access roles!)
> +//                 setLoggerLevel(),
> +//                 setVerboseClassLoading(),
> +//                 setThreadContentionMonitoringEnabled(),
> +//                 setThreadCpuTimeEnabled(),
> +//                 resetPeakThreadCount(),
> +//                 setVerboseGarbageCollection()
> +//                 gc(),
> +//                 resetPeakUsage(),
> +//                 setUsageThreshold(),
> +//                 setCollectionUsageThreshold()
>
>  package org.apache.tomcat.util;
>
> @@ -184,6 +189,84 @@ public class Diagnostics {
>      }
>
>      /**
> +     * Set verbose garbage collection logging
> +     *
> +     * @param verbose whether to enable verbose gc logging
> +     */
> +    public static void setVerboseGarbageCollection(boolean verbose) {
> +        memoryMXBean.setVerbose(verbose);
> +        boolean checkValue = memoryMXBean.isVerbose();
> +        if (verbose != checkValue) {
> +            log.error("Could not set verbose garbage collection logging to " + verbose +
> +                      ", got " + checkValue + " instead");
> +        }
> +    }
> +
> +    /**
> +     * Initiate garbage collection via MX Bean
> +     */
> +    public static void gc() {
> +        memoryMXBean.gc();
> +    }
> +
> +    /**
> +     * Reset peak memory usage data in MemoryPoolMXBean
> +     *
> +     * @param name name of the MemoryPoolMXBean or "all"
> +     */
> +    public static void resetPeakUsage(String name) {
> +        for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
> +            if (name.equals("all") || name.equals(mbean.getName())) {
> +                mbean.resetPeakUsage();
> +            }
> +        }
> +    }
> +
> +    /**
> +     * Reset peak memory usage data in MemoryPoolMXBean

The above Javadoc is wrong (it is the same as for the previous method).

> +     *
> +     * @param name name of the MemoryPoolMXBean
> +     */
> +    public static boolean setUsageThreshold(String name, long threshold) {
> +        for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
> +            if (name.equals(mbean.getName())) {
> +                try {
> +                    mbean.setUsageThreshold(threshold);
> +                    return true;
> +                } catch (IllegalArgumentException ex) {
> +                    // IGNORE
> +                } catch (UnsupportedOperationException ex) {
> +                    // IGNORE
> +                }
> +                return false;
> +            }
> +        }
> +        return false;
> +    }
> +
> +    /**
> +     * Reset peak memory collection usage data in MemoryPoolMXBean
> +     *

The same here.

> +     * @param name name of the MemoryPoolMXBean
> +     */
> +    public static boolean setCollectionUsageThreshold(String name, long threshold) {
> +        for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
> +            if (name.equals(mbean.getName())) {
> +                try {
> +                    mbean.setCollectionUsageThreshold(threshold);
> +                    return true;
> +                } catch (IllegalArgumentException ex) {
> +                    // IGNORE
> +                } catch (UnsupportedOperationException ex) {
> +                    // IGNORE
> +                }
> +                return false;
> +            }
> +        }
> +        return false;
> +    }
> +
> +    /**
>       * Formats the thread dump header for one thread.
>       *
>       * @param ti the ThreadInfo describing the thread


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org