Author: psteitz
Date: Mon Sep 20 01:24:56 2010
New Revision: 998754

URL: http://svn.apache.org/viewvc?rev=998754&view=rev
Log:
Improved javadoc, added overall summary stats using math 2.1 aggregator.

Modified:
    
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java

Modified: 
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java?rev=998754&r1=998753&r2=998754&view=diff
==============================================================================
--- 
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java
 (original)
+++ 
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java
 Mon Sep 20 01:24:56 2010
@@ -21,7 +21,9 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.io.Serializable;
+import org.apache.commons.math.stat.descriptive.AggregateSummaryStatistics;
 import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.math.stat.descriptive.StatisticalSummaryValues;
 
 /**
  * <p>Container for {...@link SummaryStatistics} accumulated during 
@@ -36,6 +38,12 @@ import org.apache.commons.math.stat.desc
  *
  */
 public class Statistics implements Serializable {
+    
+    /**
+     * Map of SummaryStatistics keyed on <process,type>, where process 
corresponds
+     * to a thread being monitored and type is a user-supplied characteristic 
being
+     * measured and tracked.  For example, <thread name, "latency">.
+     */
     private HashMap<StatisticsKey,SummaryStatistics> data = 
         new HashMap <StatisticsKey,SummaryStatistics>();
     
@@ -204,6 +212,26 @@ public class Statistics implements Seria
     }
     
     /**
+     * Returns overall SummaryStatistics, aggregating the results for metrics
+     * of the given type across processes.
+     * 
+     * @param type the metric to get overall statistics for
+     * @return a SummaryStatistics instance summarizing the combined dataset
+     * for the given metric
+     */
+    public synchronized StatisticalSummaryValues getOverallSummary(String 
type) {
+        ArrayList<SummaryStatistics> contributingStats = new 
ArrayList<SummaryStatistics>();
+        Iterator<StatisticsKey> it = data.keySet().iterator();
+        while (it.hasNext()) {
+            StatisticsKey key = it.next();
+            if (key.type.equals(type)) {
+                contributingStats.add(data.get(key));
+            }
+        }
+        return AggregateSummaryStatistics.aggregate(contributingStats);
+    }
+    
+    /**
      * Returns the List of processes corresponding to statistics.
      * 
      * @return List of processes represented in the container
@@ -268,6 +296,11 @@ public class Statistics implements Seria
             buffer.append("\n");
             buffer.append(getMaxSummary(metric).toString());
             buffer.append("********************************************\n");
+            buffer.append("Overall summary statistics (all threads combined) 
");
+            buffer.append(metric.toUpperCase());
+            buffer.append("\n");
+            buffer.append(getOverallSummary(metric).toString());
+            buffer.append("********************************************\n");
         } 
         return buffer.toString();
     }


Reply via email to