Author: burton Date: Wed Mar 9 22:19:40 2005 New Revision: 156745 URL: http://svn.apache.org/viewcvs?view=rev&rev=156745 Log: reverted to use '.' for methods and '#' for operations
Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.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=156744&r2=156745 ============================================================================== --- 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 Wed Mar 9 22:19:40 2005 @@ -219,7 +219,7 @@ /** * Return a child benchmark of the current method. This can be used to * return a benchmark for a specific method based on a benchmark for a - * class. + * class. The resulting name will have parent#name semantics. * * @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton</a> */ @@ -231,6 +231,19 @@ // **** static code ********************************************************* + /** + * Get the name of the calling classname.. + * + */ + static String getCallerClassname() { + + Exception e = new Exception(); + String name = e.getStackTrace()[2].getClassName(); + + return name; + + } + public static Object getBenchmarkAsProxy( Object _instance, Class _interface ) { return BenchmarkProxyFactory.newBenchmarkFactory( _instance, _interface ); @@ -245,12 +258,11 @@ */ public static Benchmark getBenchmark() { - Exception e = new Exception(); - String name = e.getStackTrace()[1].getClassName(); + String name = getCallerClassname(); return getBenchmark( name ); } - + /** * Factory method for obtaining a benchmark by classname * @@ -263,12 +275,22 @@ * Create a benchmark on a the caller when performing a specific operation * on a given target object.. For example if your class is 'org.apache.Foo' * and the operation is 'bar' then the resulting benchmark name will be - * 'org.apache.Foo#bar'. + * 'org.apache.Foo#bar'. When the target is null the name of the caller is + * used. This means we won't throw an NPE and it also means we have similar + * operation to child(), */ public static Benchmark getBenchmark( Object target, String operation ) { - String name = target.getClass().getName() + "#" + operation; + String prefix = null; + + if ( target == null ) { + prefix = getCallerClassname(); + } else { + prefix = target.getClass().getName(); + } + + String name = prefix + "#" + operation; return getBenchmark( name ); 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=156744&r2=156745 ============================================================================== --- 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 Wed Mar 9 22:19:40 2005 @@ -38,7 +38,15 @@ Benchmark b = Benchmark.getBenchmark( this, "foo" ); assertEquals( "org.apache.commons.benchmark.Test1#foo", b.getName() ); - + + b = Benchmark.getBenchmark( null, "foo" ); + + assertEquals( "org.apache.commons.benchmark.Test1#foo", b.getName() ); + + b = Benchmark.getBenchmark( "string", "foo" ); + + assertEquals( "java.lang.String#foo", b.getName() ); + } //setup a test to verify that X benchmarks don't use more than Y --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]