commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bur...@apache.org
Subject svn commit: r156083 - 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
Date Thu, 03 Mar 2005 21:01:50 GMT
Author: burton
Date: Thu Mar  3 13:01:49 2005
New Revision: 156083

URL: http://svn.apache.org/viewcvs?view=rev&rev=156083
Log:
getTracker now supports exporting trackers based on interval.  The metadata for the tracker
is also exported including total completed and started, etc.

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

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=156082&r2=156083
==============================================================================
--- 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  3 13:01:49 2005
@@ -71,7 +71,7 @@
     /**
      * How often should we maintain/reset the benchmark.
      */
-    public static long INTERVAL = 60 * 1000;
+    public static long INTERVAL_1 = 60 * 1000;
 
     /**
      * The 5 minute benchmark interval.
@@ -99,50 +99,102 @@
      */
     private String name = null;
 
-    private BenchmarkTracker tracker = null;
-    
+    /**
+     * The current benchmark.
+     */
+    private BenchmarkTracker tracker1 = null;
+    private BenchmarkTracker tracker5 = null;
+    private BenchmarkTracker tracker15 = null;
+
+    /**
+     * Create a new benchmark with a given name.
+     */
+    private Benchmark( String name ) {
+
+        this.name = name;
+
+        tracker1 = new BenchmarkTracker( INTERVAL_1, this );
+        tracker5 = new BenchmarkTracker( INTERVAL_5, this );
+        tracker15 = new BenchmarkTracker( INTERVAL_15, this );
+        
+    }
+
     // **** metadata about this benchmark ***************************************
 
     /**
      * The total number of start()ed benchmarks since in the last rollover.
      */
     public long getTotalStarted() {
-        return tracker.totalStarted;
+        return tracker1.totalStarted;
     }
 
     /**
      * The total number of complete()ed benchmarks since in the last rollover.
      */
     public long getTotalCompleted() {
-        return tracker.totalCompleted;
+        return tracker1.totalCompleted;
     }
 
+    /**
+     * Get the tracker for this benchmark which includes all metadata related to
+     * this benchmark including total completed/started and current values.
+     *
+     */
+    public BenchmarkTracker getTracker() {
+        return tracker1;
+    }
+
+    public BenchmarkTracker getTracker( long interval ) {
+
+        if ( interval == INTERVAL_1 ) {
+            return tracker1;
+        } else if ( interval == INTERVAL_5 ) {
+            return tracker5;
+        } else if ( interval == INTERVAL_15 ) {
+            return tracker15;
+        }
+        
+        return null;
+        
+    }
+    
+    /**
+     * Get the name of this benchmark.  Usually the classname or method name of
+     * the caller.
+     */
     public String getName() {
         return name;
     }
     
     // **** implementation code for start/complete **********************************
-
-    public Benchmark( String name ) {
-        this.name = name;
-        tracker = new BenchmarkTracker( INTERVAL, this );
-        
-    }
     
+    /**
+     * Tell the benchmark that its has been started for this interval.
+     *
+     */
     public void start() {
 
         if ( DISABLED  )
             return;
 
-        tracker.start();
+        tracker1.start();
+        tracker5.start();
+        tracker15.start();
+
     }
 
+    /**
+     * Tell the benchmark that its has been completed for this interval.
+     *
+     */
     public void complete() {
 
         if ( DISABLED  )
             return;
 
-        tracker.complete();
+        tracker1.complete();
+        tracker5.complete();
+        tracker15.complete();
         
     }
 
@@ -223,7 +275,7 @@
 
         //simple testing framework
 
-        INTERVAL = 10 * 1000;
+        INTERVAL_1 = 10 * 1000;
 
         Benchmark benchmark = getBenchmark( Benchmark.class );
         benchmark = benchmark.child( "main" );
@@ -235,7 +287,7 @@
             benchmark.start();
 
             //do something slow...
-            Thread.sleep( INTERVAL + 10 );
+            Thread.sleep( INTERVAL_1 + 10 );
 
             benchmark.complete();
 

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=156082&r2=156083
==============================================================================
--- 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  3 13:01:49 2005
@@ -106,7 +106,7 @@
 
     }
 
-    public void start() {
+    void start() {
 
         if ( parent.DISABLED  )
             return;
@@ -124,7 +124,7 @@
         
     }
 
-    public void complete() {
+    void complete() {
 
         if ( parent.DISABLED  )
             return;
@@ -136,6 +136,34 @@
 
         }
         
+    }
+
+    // **** metadata ************************************************************
+
+    /**
+     * The total number of start()ed benchmarks since in the last rollover.
+     */
+    public long getTotalStarted() {
+        return totalStarted;
+    }
+
+    /**
+     * The total number of complete()ed benchmarks since in the last rollover.
+     */
+    public long getTotalCompleted() {
+        return totalCompleted;
+    }
+
+    /**
+     */
+    public long getStarted() {
+        return started;
+    }
+
+    /**
+     */
+    public long getCompleted() {
+        return completed;
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message