Author: burton
Date: Thu Mar 10 17:15:53 2005
New Revision: 157022
URL: http://svn.apache.org/viewcvs?view=rev&rev=157022
Log:
duration enabled via threadlocal and assertions that its only using required
memory
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=157021&r2=157022
==============================================================================
---
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
Thu Mar 10 17:15:53 2005
@@ -98,7 +98,7 @@
* feature uses threadlocal variables so there's a constant overhead per
* thread.
*/
- public static boolean DISABLE_LOCAL = true;
+ public static boolean DISABLE_LOCAL = false;
/**
* Maintain a metadata map between the name and BMeta classes.
@@ -183,9 +183,19 @@
public String getName() {
return name;
}
-
+
// **** implementation code for start/complete
**********************************
-
+
+ public void start( String name ) {
+ Benchmark child = child( name );
+ child.start();
+ }
+
+ public void complete( String name ) {
+ Benchmark child = child( name );
+ child.complete();
+ }
+
/**
* Tell the benchmark that its has been started for this interval.
*
@@ -221,6 +231,7 @@
* return a benchmark for a specific method based on a benchmark for a
* class. The resulting name will have parent#name semantics.
*
+ * @deprecated use start( String ) completed( String )
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton</a>
*/
public Benchmark child( String name ) {
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=157021&r2=157022
==============================================================================
---
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
Thu Mar 10 17:15:53 2005
@@ -64,6 +64,11 @@
this.parent = parent;
}
+ BenchmarkTracker rollover() {
+ rollover( System.currentTimeMillis() );
+ return this;
+ }
+
/**
* Do a physical rollover from now to -> last .
*
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=157021&r2=157022
==============================================================================
---
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
Thu Mar 10 17:15:53 2005
@@ -33,6 +33,66 @@
super(testName);
}
+ public void testThreads() throws Exception {
+
+ int count = 100;
+
+ ThreadGroup tg = new ThreadGroup( "foo" );
+
+ System.gc();
+ long before = getUsedMemory();
+
+ for ( int i = 0; i < count; ++i ) {
+ TestThread tt = new TestThread( tg );
+ tt.start();
+ }
+
+ while ( tg.activeCount() > 0 ) {
+
+ System.out.print( "." );
+ Thread.sleep( 100 );
+
+ }
+
+ System.out.println();
+
+ System.gc();
+ long after = getUsedMemory();
+
+ System.out.println( "Done thread test" );
+
+ //500k bytes is only 500 bytes per benchmark. We should try to thin
+ //this down a bit. I could do MUCH better I think. Maybe NOT keep
+ //references to strings?
+ long usedMemory = after - before;
+ System.out.println( "Total bytes used by benchmark: " + usedMemory );
+ assertTrue( usedMemory < 500 * count );
+
+ }
+
+ private long getUsedMemory() {
+ return Runtime.getRuntime().totalMemory() -
Runtime.getRuntime().freeMemory();
+ }
+
+ public void testNewChild() {
+
+ Benchmark b = Benchmark.getBenchmark();
+
+ b.start( "foo" );
+ b.complete( "foo" );
+
+ b = (Benchmark)Benchmark.benchmarks.get(
"org.apache.commons.benchmark.Test1.foo" );
+
+ assertNotNull( b );
+
+ assertEquals( 1, b.getTracker1().now.completed );
+
+ b.getTracker1().rollover();
+
+ assertEquals( 1, b.getTracker1().last.completed );
+
+ }
+
public void testBenchmarkWithCaller() {
Benchmark b = Benchmark.getBenchmark( this, "foo" );
@@ -73,14 +133,11 @@
long after = Runtime.getRuntime().totalMemory() -
Runtime.getRuntime().freeMemory();
- long usedMemory = after - before;
-
//500k bytes is only 500 bytes per benchmark. We should try to thin
//this down a bit. I could do MUCH better I think. Maybe NOT keep
//references to strings?
-
+ long usedMemory = after - before;
System.out.println( "Total bytes used by benchmark: " + usedMemory );
-
assertTrue( usedMemory < 500 * count );
Benchmark.benchmarks = new HashMap();
@@ -156,7 +213,7 @@
public void testDuration() throws Exception {
- Benchmark.DISABLE_LOCAL = false;
+ //Benchmark.DISABLE_LOCAL = false;
Benchmark benchmark = Benchmark.getBenchmark( Test1.class );
benchmark = benchmark.child( "testDuration" );
@@ -354,3 +411,30 @@
public void doSomething() { }
}
+
+class TestThread extends Thread {
+
+ public TestThread( ThreadGroup tg ) {
+ super( tg, "foo" );
+ }
+
+ public void run() {
+ try {
+
+ Random r = new Random();
+
+ Benchmark b = Benchmark.getBenchmark( "foo" + r.nextInt());
+
+ b.start();
+ Thread.sleep( 100 );
+ b.complete();
+
+ } catch ( Throwable t ) {
+
+ t.printStackTrace();
+
+ }
+
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]