You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2005/09/07 23:41:41 UTC
cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/visualizers SamplingStatCalculator.java
sebb 2005/09/07 14:41:41
Modified: src/core/org/apache/jmeter/visualizers Tag: rel-2-1
SamplingStatCalculator.java
Log:
Add fixes as per bug 33403
Revision Changes Path
No revision
No revision
1.7.2.1 +46 -30 jakarta-jmeter/src/core/org/apache/jmeter/visualizers/SamplingStatCalculator.java
Index: SamplingStatCalculator.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/visualizers/SamplingStatCalculator.java,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -u -r1.7 -r1.7.2.1
--- SamplingStatCalculator.java 12 Jul 2005 20:51:00 -0000 1.7
+++ SamplingStatCalculator.java 7 Sep 2005 21:41:41 -0000 1.7.2.1
@@ -1,6 +1,6 @@
// $Header$
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +20,10 @@
import java.io.Serializable;
import java.text.DecimalFormat;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.Vector;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jorphan.logging.LoggingManager;
@@ -47,9 +47,9 @@
private static DecimalFormat kbFormatter = new DecimalFormat("#0.00");
- private StatCalculator calculator = new StatCalculator();
+ private final StatCalculator calculator = new StatCalculator();
- private ArrayList storedValues = new ArrayList();
+ private final List storedValues = new Vector();
private double maxThroughput;
@@ -89,9 +89,12 @@
public void addSamples(SamplingStatCalculator ssc) {
calculator.addAll(ssc.calculator);
- storedValues.addAll(ssc.storedValues);
- Collections.sort(storedValues);
- if (firstTime > ssc.firstTime) {
+ synchronized( storedValues )
+ {
+ storedValues.addAll(ssc.storedValues);
+ Collections.sort(storedValues);
+ }
+ if (firstTime > ssc.firstTime) {
firstTime = ssc.firstTime;
}
}
@@ -105,10 +108,13 @@
}
public Sample getCurrentSample() {
- if (storedValues.size() == 0) {
- return new Sample();
- }
- return (Sample) storedValues.get(storedValues.size() - 1);
+ synchronized( storedValues )
+ {
+ if (storedValues.size() == 0) {
+ return new Sample();
+ }
+ return (Sample) storedValues.get(storedValues.size() - 1);
+ }
}
/**
@@ -206,8 +212,10 @@
*
*/
public Sample addSample(SampleResult res) {
- Sample s = null;
- synchronized (calculator) {
+ long rtime, cmean, cstdv, cmedian, cpercent, eCount, endTime;
+ double throughput;
+ boolean rbool;
+ synchronized (calculator) {
long byteslength = 0;
// in case the sampler doesn't return the contents
// we see if the bytes was set
@@ -230,26 +238,32 @@
calculator.addBytes(byteslength);
}
setStartTime(res);
- long eCount = getCurrentSample().errorCount;
+ eCount = getCurrentSample().errorCount;
if (!res.isSuccessful()) {
eCount++;
}
- long endTime = getEndTime(res);
+ endTime = getEndTime(res);
long howLongRunning = endTime - firstTime;
- double throughput = 0;
- if (howLongRunning <= 0) {
- throughput = Double.MAX_VALUE;
- }
throughput = ((double) calculator.getCount() / (double) howLongRunning) * 1000.0;
if (throughput > maxThroughput) {
maxThroughput = throughput;
}
- s = new Sample(null, res.getTime(), (long) calculator.getMean(), (long) calculator.getStandardDeviation(),
- calculator.getMedian().longValue(), calculator.getPercentPoint(0.500).longValue(), throughput,
- eCount, res.isSuccessful(), storedValues.size() + 1, endTime);
- storedValues.add(s);
- }
- return s;
+
+ rtime = res.getTime();
+ cmean = (long)calculator.getMean();
+ cstdv = (long)calculator.getStandardDeviation();
+ cmedian = calculator.getMedian().longValue();
+ cpercent = calculator.getPercentPoint( 0.500 ).longValue();
+ rbool = res.isSuccessful();
+ }
+
+ synchronized( storedValues ){
+ int count = storedValues.size() + 1;
+ Sample s =
+ new Sample( null, rtime, cmean, cstdv, cmedian, cpercent, throughput, eCount, rbool, count, endTime );
+ storedValues.add( s );
+ return s;
+ }
}
public List getSamples() {
@@ -257,10 +271,12 @@
}
public Sample getSample(int index) {
- if (index < storedValues.size()) {
- return (Sample) storedValues.get(index);
- }
+ synchronized( storedValues ){
+ if (index < storedValues.size()) {
+ return (Sample) storedValues.get(index);
+ }
return null;
+ }
}
private long getEndTime(SampleResult res) {
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org