commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r663078 - in /commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring: ./ impl/stopwatches/ support/java13/java/lang/management/
Date Wed, 04 Jun 2008 12:50:11 GMT
Author: nicolas
Date: Wed Jun  4 05:50:11 2008
New Revision: 663078

URL: http://svn.apache.org/viewvc?rev=663078&view=rev
Log:
use ThreadMxBean to compute CPU time

Added:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ManagementFactory_.java
  (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ThreadMXBean_.java
  (with props)
Modified:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java?rev=663078&r1=663077&r2=663078&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
Wed Jun  4 05:50:11 2008
@@ -55,6 +55,9 @@
     /** default role key for code performances */
     Role<Counter> PERFORMANCES = new Role<Counter>( "performances", Unit.NANOS,
Counter.class );
 
+    /** default role key for cpu time */
+    Role<Counter> CPU = new Role<Counter>( "cpu", Unit.NANOS, Counter.class );
+
     /** default role for multi-thread concurrency */
     Role<Gauge> CONCURRENCY = new Role<Gauge>( "concurrency", Unit.UNARY, Gauge.class
);
 

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java?rev=663078&r1=663077&r2=663078&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java
Wed Jun  4 05:50:11 2008
@@ -17,6 +17,9 @@
 
 package org.apache.commons.monitoring.impl.stopwatches;
 
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.StopWatch;
 import org.apache.commons.monitoring.Unit;
@@ -32,9 +35,11 @@
 {
     /** Time the probe was started */
     private final long startedAt;
+    private long cpuStartedAt;
 
     /** Time the probe was stopped */
     private long stopedAt;
+    private long cpuStopedAt;
 
     /** Time the probe was paused */
     private long pauseDelay;
@@ -64,6 +69,11 @@
         if ( monitor != null )
         {
             monitor.getGauge( Monitor.CONCURRENCY ).increment( Unit.UNARY );
+            ThreadMXBean mx = ManagementFactory.getThreadMXBean();
+            if ( mx.isCurrentThreadCpuTimeSupported() )
+            {
+                cpuStartedAt = mx.getCurrentThreadCpuTime();
+            }
         }
     }
 
@@ -134,6 +144,12 @@
             {
                 monitor.getGauge( Monitor.CONCURRENCY ).decrement( Unit.UNARY );
                 monitor.getCounter( Monitor.PERFORMANCES ).add( getElapsedTime(), Unit.NANOS
);
+                ThreadMXBean mx = ManagementFactory.getThreadMXBean();
+                if ( mx.isCurrentThreadCpuTimeSupported() )
+                {
+                    long cpu = mx.getCurrentThreadCpuTime() - cpuStartedAt;
+                    monitor.getCounter( Monitor.CPU ).add( cpu, Unit.NANOS );
+                }
             }
         }
     }

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ManagementFactory_.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ManagementFactory_.java?rev=663078&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ManagementFactory_.java
(added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ManagementFactory_.java
Wed Jun  4 05:50:11 2008
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.monitoring.support.java13.java.lang.management;
+
+/**
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class ManagementFactory_
+{
+    public static ThreadMXBean_ getThreadMXBean()
+    {
+        return ThreadMXBean_.instance;
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ManagementFactory_.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ManagementFactory_.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ManagementFactory_.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ThreadMXBean_.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ThreadMXBean_.java?rev=663078&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ThreadMXBean_.java
(added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ThreadMXBean_.java
Wed Jun  4 05:50:11 2008
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.monitoring.support.java13.java.lang.management;
+
+/**
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class ThreadMXBean_
+{
+    static ThreadMXBean_ instance = new ThreadMXBean_();
+
+    public static boolean isCurrentThreadCpuTimeSupported( ThreadMXBean_ mx )
+    {
+        return false;
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ThreadMXBean_.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ThreadMXBean_.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/java/lang/management/ThreadMXBean_.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message