mstover1 2003/02/06 20:18:54
Modified: src/components/org/apache/jmeter/visualizers Graph.java
GraphModel.java GraphVisualizer.java Sample.java
src/core/org/apache/jmeter/gui/util JMeterColor.java
src/core/org/apache/jmeter/resources messages.properties
messages_de.properties messages_ja.properties
messages_no.properties
Added: src/jorphan/org/apache/jorphan/math StatCalculator.java
Log:
Refactored calculation of statistics into its own generic class
added median data to graph results visualizer
Revision Changes Path
1.4 +27 -20
jakarta-jmeter/src/components/org/apache/jmeter/visualizers/Graph.java
Index: Graph.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/Graph.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Graph.java 5 Feb 2003 05:12:03 -0000 1.3
+++ Graph.java 7 Feb 2003 04:18:53 -0000 1.4
@@ -54,7 +54,6 @@
*/
package org.apache.jmeter.visualizers;
-
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
@@ -68,7 +67,6 @@
import org.apache.jmeter.gui.util.JMeterColor;
import org.apache.jmeter.samplers.Clearable;
-
/**
* Title: Apache JMeter Description: Implements a simple graph for displaying
* performance results Copyright: Copyright (c) 2000 Company: Apache Foundation
@@ -85,6 +83,7 @@
private boolean average = true;
private boolean deviation = true;
private boolean throughput = true;
+ private boolean median = true;
private GraphModel model;
private static int width = 2000;
@@ -203,6 +202,11 @@
this.average = value;
}
+ public void enableMedian(boolean value)
+ {
+ this.median = value;
+ }
+
/**
* Description of the Method
*
@@ -235,20 +239,18 @@
{
final int xPos = model.getSampleCount();
- SwingUtilities.invokeLater(
- new Runnable()
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ Graphics g = getGraphics();
+
+ if (g != null)
{
- public void run()
- {
- Graphics g = getGraphics();
-
- if (g != null)
- {
- drawSample(xPos, oneSample, g);
- }
- }
+ drawSample(xPos, oneSample, g);
}
- );
+ }
+ });
}
/**
@@ -303,25 +305,30 @@
if (average)
{
- int average = (int) (oneSample.average * d.height
- / model.getGraphMax());
+ int average = (int) (oneSample.average * d.height /
model.getGraphMax());
g.setColor(Color.blue);
g.drawLine(x % width, d.height - average, x % width, (d.height -
average - 1));
}
+ if (median)
+ {
+ int median = (int) (oneSample.median * d.height / model.getGraphMax());
+
+ g.setColor(JMeterColor.purple);
+ g.drawLine(x % width, d.height - median, x % width, (d.height - median
- 1));
+ }
+
if (deviation)
{
- int deviation = (int) (oneSample.deviation * d.height
- / model.getGraphMax());
+ int deviation = (int) (oneSample.deviation * d.height /
model.getGraphMax());
g.setColor(Color.red);
g.drawLine(x % width, d.height - deviation, x % width, (d.height -
deviation - 1));
}
if (throughput)
{
- int throughput = (int) (oneSample.throughput * d.height
- / model.getThroughputMax());
+ int throughput = (int) (oneSample.throughput * d.height /
model.getThroughputMax());
g.setColor(JMeterColor.dark_green);
g.drawLine(x % width, d.height - throughput, x % width, (d.height -
throughput - 1));
1.5 +26 -35
jakarta-jmeter/src/components/org/apache/jmeter/visualizers/GraphModel.java
Index: GraphModel.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/GraphModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GraphModel.java 5 Feb 2003 18:41:56 -0000 1.4
+++ GraphModel.java 7 Feb 2003 04:18:53 -0000 1.5
@@ -54,7 +54,6 @@
*/
package org.apache.jmeter.visualizers;
-
import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
@@ -63,7 +62,7 @@
import org.apache.jmeter.samplers.Clearable;
import org.apache.jmeter.samplers.SampleResult;
-
+import org.apache.jorphan.math.*;
/**
* Title: Apache JMeter Description: Copyright: Copyright (c) 2000 Company:
@@ -74,23 +73,19 @@
*@version 1.0
*/
-
public class GraphModel implements Clearable, Serializable
{
private String name;
private List samples;
private List listeners;
- private long sum = 0;
- private long sumOfSquares = 0;
- private long counter = 0;
private long previous = 0;
- private long max = 1;
private boolean bigChange = false;
- private Sample current = new Sample(0, 0, 0, 0, false);
+ private Sample current = new Sample(0, 0, 0, 0, 0,false);
private long startTime = 0;
private int throughputMax = 20;
private long graphMax = 20;
+ private StatCalculator statCalc = new StatCalculator();
/**
* Constructor for the GraphModel object
@@ -134,6 +129,11 @@
return current.average;
}
+
+ public long getCurrentMedian()
+ {
+ return current.median;
+ }
/**
* Gets the CurrentDeviation attribute of the GraphModel object
@@ -204,7 +204,7 @@
*/
public long getMaxSample()
{
- return max;
+ return statCalc.getMax().longValue();
}
public long getGraphMax()
@@ -247,14 +247,11 @@
public void clear()
{
samples.clear();
- sum = 0;
- sumOfSquares = 0;
- counter = 0;
previous = 0;
- max = 1;
graphMax = 1;
bigChange = true;
- current = new Sample(0, 0, 0, 0, false);
+ current = new Sample(0, 0, 0, 0, 0,false);
+ statCalc.clear();
this.fireDataChanged();
}
@@ -302,32 +299,28 @@
*/
protected Sample addNewSample(long sample, long timeStamp, boolean success)
{
- if (samples.size() == 0)
+ int counter = 0;
+ float average;
+ long deviation, median;
+ synchronized (statCalc)
{
- startTime = timeStamp;
+ statCalc.addValue(sample);
+ counter = statCalc.getCount();
+ average = (float) statCalc.getMean();
+ deviation = (long) statCalc.getStandardDeviation();
+ median = statCalc.getMedian().longValue();
}
- if (sample > max)
+
+ if (samples.size() == 0)
{
- max = sample;
+ startTime = timeStamp;
}
- counter++;
-
- sum += sample;
- float average = ((float)sum) / counter;
-
- sumOfSquares += sample * sample;
- // Standard deviation is the mean of the squares minus the square
- // of the mean
- long deviation = (long)Math.sqrt(
- (sumOfSquares / counter) - average * average);
-
float throughput = 0;
if (timeStamp - startTime > 0)
{
- throughput = (float) (((float) (samples.size() + 1))
- / ((float) (timeStamp - startTime)) * 60000);
+ throughput = (float) (((float) (samples.size() + 1)) / ((float)
(timeStamp - startTime)) * 60000);
}
if (throughput > throughputMax)
{
@@ -337,15 +330,14 @@
if (average > graphMax)
{
bigChange = true;
- graphMax = (long)average * 3;
+ graphMax = (long) average * 3;
}
if (deviation > graphMax)
{
bigChange = true;
graphMax = deviation * 3;
}
- Sample s = new Sample(sample, (long)average, deviation,
- throughput, !success);
+ Sample s = new Sample(sample, (long) average, deviation, throughput,
median,!success);
previous = sample;
current = s;
@@ -353,4 +345,3 @@
return s;
}
}
-
1.7 +15 -3
jakarta-jmeter/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java
Index: GraphVisualizer.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- GraphVisualizer.java 6 Feb 2003 18:53:08 -0000 1.6
+++ GraphVisualizer.java 7 Feb 2003 04:18:53 -0000 1.7
@@ -106,10 +106,12 @@
private JCheckBox average;
private JCheckBox deviation;
private JCheckBox throughput;
+ private JCheckBox median;
private JTextField dataField;
private JTextField averageField;
private JTextField deviationField;
private JTextField throughputField;
+ private JTextField medianField;
private boolean perSecond = false;
/****************************************
@@ -148,6 +150,7 @@
averageField.setText(Long.toString(model.getCurrentAverage()));
deviationField.setText(Long.toString(model.getCurrentDeviation()));
throughputField.setText(Float.toString(model.getCurrentThroughput()) + "/"
+ minute);
+ medianField.setText(Long.toString(model.getCurrentMedian()));
updateYAxis();
}
@@ -165,6 +168,7 @@
averageField.setText(Long.toString(s.average));
deviationField.setText(Long.toString(s.deviation));
throughputField.setText(Float.toString(s.throughput) + "/" + minute);
+ medianField.setText(Long.toString(s.median));
updateYAxis();
}
@@ -211,6 +215,10 @@
{
this.graph.enableThroughput(e.getStateChange() == ItemEvent.SELECTED);
}
+ else if(e.getItem() == median)
+ {
+ this.graph.enableMedian(e.getStateChange() == ItemEvent.SELECTED);
+ }
this.graph.repaint();
}
@@ -225,6 +233,7 @@
averageField.setText("0000");
deviationField.setText("0000");
throughputField.setText("0/" + minute);
+ medianField.setText("0000");
updateYAxis();
repaint();
}
@@ -377,10 +386,12 @@
deviation = createChooseCheckBox("graph_results_deviation", Color.red);
throughput = createChooseCheckBox("graph_results_throughput",
JMeterColor.dark_green);
+ median = createChooseCheckBox("graph_results_median", JMeterColor.purple);
chooseGraphsPanel.add(selectGraphsLabel);
chooseGraphsPanel.add(data);
chooseGraphsPanel.add(average);
+ chooseGraphsPanel.add(median);
chooseGraphsPanel.add(deviation);
chooseGraphsPanel.add(throughput);
return chooseGraphsPanel;
@@ -444,6 +455,7 @@
averageField = createInfoField(Color.blue, 5);
deviationField = createInfoField(Color.red, 5);
throughputField = createInfoField(JMeterColor.dark_green, 15);
+ medianField = createInfoField(JMeterColor.purple,5);
graphInfoPanel.add(createInfoColumn(
createInfoLabel("graph_results_no_samples", noSamplesField),
@@ -462,8 +474,8 @@
graphInfoPanel.add(createInfoColumn(
createInfoLabel("graph_results_average", averageField),
averageField,
- null,
- null));
+ createInfoLabel("graph_results_median", medianField),
+ medianField));
graphInfoPanel.add(Box.createHorizontalGlue());
return graphInfoPanel;
1.4 +3 -1
jakarta-jmeter/src/components/org/apache/jmeter/visualizers/Sample.java
Index: Sample.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/Sample.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Sample.java 3 Feb 2003 14:29:00 -0000 1.3
+++ Sample.java 7 Feb 2003 04:18:53 -0000 1.4
@@ -79,6 +79,7 @@
* Description of the Field
*/
public long average;
+ public long median;
/**
* Description of the Field
@@ -96,13 +97,14 @@
*@param average Description of Parameter
*@param deviation Description of Parameter
*/
- public Sample(long data, long average, long deviation, float throughput,
boolean error)
+ public Sample(long data, long average, long deviation, float throughput, long
median,boolean error)
{
this.data = data;
this.average = average;
this.deviation = deviation;
this.throughput = throughput;
this.error = error;
+ this.median = median;
}
public Sample()
1.3 +1 -0
jakarta-jmeter/src/core/org/apache/jmeter/gui/util/JMeterColor.java
Index: JMeterColor.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/util/JMeterColor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JMeterColor.java 30 Aug 2002 14:43:20 -0000 1.2
+++ JMeterColor.java 7 Feb 2003 04:18:53 -0000 1.3
@@ -67,6 +67,7 @@
public final static Color dark_green = new JMeterColor(0F,.5F,0F);
public final static Color YELLOW = new JMeterColor(1F,1F,0);
public final static Color LAVENDER = new JMeterColor(206F/255F,207F/255F,1F);
+ public final static Color purple = new JMeterColor(150/255F,0,150/255F);
public JMeterColor(float r,float g,float b)
{
1.26 +1 -0
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties
Index: messages.properties
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- messages.properties 5 Feb 2003 05:12:08 -0000 1.25
+++ messages.properties 7 Feb 2003 04:18:53 -0000 1.26
@@ -105,6 +105,7 @@
graph_results_title=Graph Results
graph_results_data=Data
graph_results_average=Average
+graph_results_median=Median
graph_results_deviation=Deviation
graph_results_no_samples=No of Samples
graph_results_ms=ms
1.23 +2 -1
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_de.properties
Index: messages_de.properties
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_de.properties,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- messages_de.properties 5 Feb 2003 05:12:08 -0000 1.22
+++ messages_de.properties 7 Feb 2003 04:18:53 -0000 1.23
@@ -330,4 +330,5 @@
default_value_field=Default Value:
ref_name_field=Reference Name:
match_num_field=Match No. (0 for Random):
-menu_extractors=Extractors and Post Request Processors
\ No newline at end of file
+menu_extractors=Extractors and Post Request Processors
+graph_results_median=Median
\ No newline at end of file
1.20 +2 -1
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_ja.properties
Index: messages_ja.properties
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_ja.properties,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- messages_ja.properties 5 Feb 2003 05:12:08 -0000 1.19
+++ messages_ja.properties 7 Feb 2003 04:18:53 -0000 1.20
@@ -325,4 +325,5 @@
default_value_field=Default Value:
ref_name_field=Reference Name:
match_num_field=Match No. (0 for Random):
-menu_extractors=Extractors and Post Request Processors
\ No newline at end of file
+menu_extractors=Extractors and Post Request Processors
+graph_results_median=Median
\ No newline at end of file
1.20 +2 -1
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_no.properties
Index: messages_no.properties
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_no.properties,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- messages_no.properties 5 Feb 2003 05:12:08 -0000 1.19
+++ messages_no.properties 7 Feb 2003 04:18:53 -0000 1.20
@@ -317,4 +317,5 @@
default_value_field=Default Value:
ref_name_field=Reference Name:
match_num_field=Match No. (0 for Random):
-menu_extractors=Extractors and Post Request Processors
\ No newline at end of file
+menu_extractors=Extractors and Post Request Processors
+graph_results_median=Median
\ No newline at end of file
1.1
jakarta-jmeter/src/jorphan/org/apache/jorphan/math/StatCalculator.java
Index: StatCalculator.java
===================================================================
package org.apache.jorphan.math;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import junit.framework.TestCase;
/**
* This class serves as a way to calculate the median of a list of values. It
* is not threadsafe.
*/
public class StatCalculator implements Serializable
{
List values = new ArrayList();
double sum = 0;
double sumOfSquares = 0;
double mean = 0;
double deviation = 0;
int count = 0;
public void clear()
{
values.clear();
sum = 0;
sumOfSquares = 0;
mean = 0;
deviation = 0;
count = 0;
}
public void addValue(long newValue)
{
Number val = new Long(newValue);
addValue(val);
}
public void addValue(int newValue)
{
Number val = new Integer(newValue);
addValue(val);
}
public void addValue(float newValue)
{
Number val = new Float(newValue);
addValue(val);
}
public void addValue(double newValue)
{
Number val = new Double(newValue);
addValue(val);
}
public Number getMedian()
{
return (Number) values.get(values.size() / 2);
}
public double getMean()
{
return mean;
}
public double getStandardDeviation()
{
return deviation;
}
public Number getMin()
{
return (Number)values.get(0);
}
public Number getMax()
{
return (Number)values.get(count-1);
}
public int getCount()
{
return count;
}
public void addValue(Number val)
{
int index = Collections.binarySearch(values, val);
if (index >= 0 && index < values.size())
{
values.add(index, val);
}
else if (index == values.size() || values.size() == 0)
{
values.add(val);
}
else
{;
values.add((index * (-1)) - 1, val);
}
count++;
double currentVal = val.doubleValue();
sum += currentVal;
sumOfSquares += currentVal * currentVal;
mean = sum / count;
deviation = Math.sqrt( (sumOfSquares / count) - (mean * mean) );
}
public static class Test extends TestCase
{
StatCalculator calc;
public Test(String name)
{
super(name);
}
public void setUp()
{
calc = new StatCalculator();
}
public void testCalculation()
{
calc.addValue(18);
calc.addValue(10);
calc.addValue(9);
calc.addValue(11);
calc.addValue(28);
calc.addValue(3);
calc.addValue(30);
calc.addValue(15);
calc.addValue(15);
calc.addValue(21);
assertEquals(16,(int)calc.getMean());
assertEquals(8.0622577F,(float)calc.getStandardDeviation(),0F);
assertEquals(30,calc.getMax().intValue());
assertEquals(3,calc.getMin().intValue());
assertEquals(15,calc.getMedian().intValue());
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]