You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/03/04 10:18:41 UTC
svn commit: r156147 - in jakarta/commons/sandbox/benchmark/trunk/src:
java/org/apache/commons/benchmark/Benchmark.java
java/org/apache/commons/benchmark/BenchmarkTracker.java
test/org/apache/commons/benchmark/Test1.java
Author: burton
Date: Fri Mar 4 01:18:36 2005
New Revision: 156147
URL: http://svn.apache.org/viewcvs?view=rev&rev=156147
Log:
bug fix for long timeouts with benchmarks....
Modified:
jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java
jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java
jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java
Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java?view=diff&r1=156146&r2=156147
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java (original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java Fri Mar 4 01:18:36 2005
@@ -61,6 +61,7 @@
*
* </code>
*
+ * <p>
* The method overhead is very light. One a modern machine you can perform about
* 1M benchmarks per second. For code thats only called a few thousand times
* you won't notice any performance overhead.
@@ -325,8 +326,8 @@
//FIXME: we should also support benchmarking of code regions and whether
//we're IN a code region. That would be interesting to. Have a bunch
- //of start() complete() methods and then I could benchmark how many are open
- //at a given time.
+ //of start() complete() methods and then I could benchmark how many are
+ //open at a given time.
//
// This would support total number of completed operations and total
// number of pending operations within a given timeframe.
Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java?view=diff&r1=156146&r2=156147
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java (original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java Fri Mar 4 01:18:36 2005
@@ -84,9 +84,16 @@
BenchmarkTracker reset( long now ) {
//need to perform a swap and save the current benchmark.
+
lastStarted = started;
lastCompleted = completed;
-
+
+ //if we've slept for too long we have to start fresh
+ if ( now - timestamp > interval ) {
+ lastStarted = 0;
+ lastCompleted = 0;
+ }
+
//reset the benchmark
timestamp = now;
started = 0;
Modified: jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java?view=diff&r1=156146&r2=156147
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java (original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java Fri Mar 4 01:18:36 2005
@@ -30,10 +30,39 @@
//FIXME: test with using really short intervals but with diff values.
+ public void testLongSleep() throws Exception {
+
+ // - Potential bug. If we don't log anything > 5 minutes the LAST benchmark
+ // will be rotated. I actually have to check if the last benchmark was more
+ // than INTERVAL ago and if so then delete the last benchmark
+
+ // - A unit test for this would be easy... I'd just have to sleep TWICE.
+
+ //this is cheating a bit. We set the intervals smaller so that we can
+ //get through the tests quickly
+ Benchmark.INTERVAL_1 = 1000;
+ Benchmark.INTERVAL_5 = 5000;
+ Benchmark.INTERVAL_15 = 15000;
+
+ Benchmark benchmark = Benchmark.getBenchmark( Test1.class );
+ benchmark = benchmark.child( "testLongSleep" );
+
+ benchmark.start();
+ benchmark.complete();
+
+ Thread.sleep( 1000 );
+ Thread.sleep( 1000 );
+
+ assertEquals( 0, benchmark.getTracker1().getStarted() );
+ assertEquals( 0, benchmark.getTracker1().getLastStarted() );
+
+ benchmark.reset();
+
+ }
+
public void testList() throws Exception {
List list = new LinkedList();
-
list = (List)Benchmark.getBenchmarkAsProxy( list, List.class );
list.add( "hello" );
@@ -65,7 +94,7 @@
assertEquals( 1, benchmark.getTracker1().getCompleted() );
System.out.println( Benchmark.getBenchmarks() );
-
+
}
public void testIntervalReset() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org