You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2010/07/07 06:12:07 UTC
svn commit: r961159 - in
/activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util:
IntMetricCounter.scala LongMetricCounter.scala TimeCounter.scala
Author: chirino
Date: Wed Jul 7 04:12:06 2010
New Revision: 961159
URL: http://svn.apache.org/viewvc?rev=961159&view=rev
Log:
Adding a couple more handy MetricProducers
Added:
activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/IntMetricCounter.scala
activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/LongMetricCounter.scala
- copied, changed from r961158, activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala
Modified:
activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala
Added: activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/IntMetricCounter.scala
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/IntMetricCounter.scala?rev=961159&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/IntMetricCounter.scala (added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/IntMetricCounter.scala Wed Jul 7 04:12:06 2010
@@ -0,0 +1,65 @@
+/**
+ * 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.activemq.apollo.util
+
+import java.util.concurrent.TimeUnit
+
+/**
+ * <p>Produces a IntMetric which track Int events</p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+class IntMetricCounter extends MetricProducer[IntMetric] {
+
+ private var max = Int.MinValue
+ private var min = Int.MaxValue
+ private var total = 0
+ private var count = 0
+
+ def apply(reset: Boolean):IntMetric = {
+ val rc = IntMetric(count, total, min, max)
+ if (reset) {
+ clear()
+ }
+ rc
+ }
+
+ def clear() = {
+ max = Int.MinValue
+ min = Int.MaxValue
+ total = 0
+ count = 0
+ }
+
+ /**
+ * Adds a duration to our current Timing.
+ */
+ def +=(value: Int): Unit = {
+ if (value > -1) {
+ max = value max max
+ min = value min min
+ total += value
+ count += 1
+ }
+ }
+
+}
+
+case class IntMetric(count:Int, total:Int, min:Int, max:Int) {
+ def avg = if( count==0 ) 0f else total.toFloat / count
+ def frequency = 1.toFloat / avg
+}
Copied: activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/LongMetricCounter.scala (from r961158, activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala)
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/LongMetricCounter.scala?p2=activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/LongMetricCounter.scala&p1=activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala&r1=961158&r2=961159&rev=961159&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/LongMetricCounter.scala Wed Jul 7 04:12:06 2010
@@ -19,19 +19,19 @@ package org.apache.activemq.apollo.util
import java.util.concurrent.TimeUnit
/**
- * <p>A Timer collects time durations and produces a TimeMetric.</p>
+ * <p>Produces a LongMetric which track Long events</p>
*
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
-class TimeCounter extends MetricProducer[TimeMetric] {
+class LongMetricCounter extends MetricProducer[LongMetric] {
- private var maximum = Long.MinValue
- private var minimum = Long.MaxValue
+ private var max = Long.MinValue
+ private var min = Long.MaxValue
private var total = 0L
private var count = 0
- def apply(reset: Boolean):TimeMetric = {
- val rc = TimeMetric(count, total, minimum, maximum)
+ def apply(reset: Boolean):LongMetric = {
+ val rc = LongMetric(count, total, min, max)
if (reset) {
clear()
}
@@ -39,8 +39,8 @@ class TimeCounter extends MetricProducer
}
def clear() = {
- maximum = Long.MinValue
- minimum = Long.MaxValue
+ max = Long.MinValue
+ min = Long.MaxValue
total = 0L
count = 0
}
@@ -50,42 +50,16 @@ class TimeCounter extends MetricProducer
*/
def +=(value: Long): Unit = {
if (value > -1) {
- maximum = value max maximum
- minimum = value min minimum
+ max = value max max
+ min = value min min
total += value
count += 1
}
}
- /**
- *
- */
- def time[T](func: => T): T = {
- val startTime = System.nanoTime
- try {
- func
- } finally {
- this += System.nanoTime - startTime
- }
- }
-
- /**
- *
- */
- def start[T](func: ( ()=>Unit )=> T): T = {
- val startTime = System.nanoTime
- def endFunc():Unit = {
- val end = System.nanoTime
- this += System.nanoTime - startTime
- }
- func(endFunc)
- }
}
-case class TimeMetric(count:Int, total:Long, minimum:Long, maximum:Long) {
- def maxTime(unit:TimeUnit) = (maximum).toFloat / unit.toNanos(1)
- def minTime(unit:TimeUnit) = (minimum).toFloat / unit.toNanos(1)
- def totalTime(unit:TimeUnit) = (total).toFloat / unit.toNanos(1)
- def avgTime(unit:TimeUnit) = if( count==0 ) 0f else totalTime(unit) / count
- def avgFrequency(unit:TimeUnit) = 1.toFloat / avgTime(unit)
-}
\ No newline at end of file
+case class LongMetric(count:Long, total:Long, min:Long, max:Long) {
+ def avg = if( count==0 ) 0f else total.toFloat / count
+ def frequency = 1.toFloat / avg
+}
Modified: activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala?rev=961159&r1=961158&r2=961159&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala Wed Jul 7 04:12:06 2010
@@ -25,13 +25,13 @@ import java.util.concurrent.TimeUnit
*/
class TimeCounter extends MetricProducer[TimeMetric] {
- private var maximum = Long.MinValue
- private var minimum = Long.MaxValue
+ private var max = Long.MinValue
+ private var min = Long.MaxValue
private var total = 0L
private var count = 0
def apply(reset: Boolean):TimeMetric = {
- val rc = TimeMetric(count, total, minimum, maximum)
+ val rc = TimeMetric(count, total, min, max)
if (reset) {
clear()
}
@@ -39,8 +39,8 @@ class TimeCounter extends MetricProducer
}
def clear() = {
- maximum = Long.MinValue
- minimum = Long.MaxValue
+ max = Long.MinValue
+ min = Long.MaxValue
total = 0L
count = 0
}
@@ -50,8 +50,8 @@ class TimeCounter extends MetricProducer
*/
def +=(value: Long): Unit = {
if (value > -1) {
- maximum = value max maximum
- minimum = value min minimum
+ max = value max max
+ min = value min min
total += value
count += 1
}
@@ -82,10 +82,10 @@ class TimeCounter extends MetricProducer
}
}
-case class TimeMetric(count:Int, total:Long, minimum:Long, maximum:Long) {
- def maxTime(unit:TimeUnit) = (maximum).toFloat / unit.toNanos(1)
- def minTime(unit:TimeUnit) = (minimum).toFloat / unit.toNanos(1)
+case class TimeMetric(count:Int, total:Long, min:Long, max:Long) {
+ def maxTime(unit:TimeUnit) = (max).toFloat / unit.toNanos(1)
+ def minTime(unit:TimeUnit) = (min).toFloat / unit.toNanos(1)
def totalTime(unit:TimeUnit) = (total).toFloat / unit.toNanos(1)
def avgTime(unit:TimeUnit) = if( count==0 ) 0f else totalTime(unit) / count
- def avgFrequency(unit:TimeUnit) = 1.toFloat / avgTime(unit)
+ def frequencyTime(unit:TimeUnit) = 1.toFloat / avgTime(unit)
}
\ No newline at end of file