Author: sebb Date: Wed Dec 16 00:02:46 2009 New Revision: 891076 URL: http://svn.apache.org/viewvc?rev=891076&view=rev Log: Remove cache of samples from SamplingStatCalculator and move into new subclass CachingStatCalculator. Only a few visualisers actually need the cache, which can take lots of memory. Aggregate Report now uses far less memory.
Added: jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/CachingStatCalculator.java (with props) Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/Graph.java jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SplineModel.java jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/SamplingStatCalculator.java Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/Graph.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/Graph.java?rev=891076&r1=891075&r2=891076&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/Graph.java (original) +++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/Graph.java Wed Dec 16 00:02:46 2009 @@ -51,7 +51,7 @@ private boolean wantMedian = true; - private SamplingStatCalculator model; + private CachingStatCalculator model; private static final int width = 2000; @@ -69,17 +69,9 @@ /** * Constructor for the Graph object. */ - public Graph(SamplingStatCalculator model) { + public Graph(CachingStatCalculator model) { this(); - setModel(model); - } - - /** - * Sets the Model attribute of the Graph object. - */ - private void setModel(Object model) { - this.model = (SamplingStatCalculator) model; - repaint(); + this.model = model; } /** Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java?rev=891076&r1=891075&r2=891076&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java (original) +++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java Wed Dec 16 00:02:46 2009 @@ -58,7 +58,7 @@ private NumberFormat nf = NumberFormat.getInstance(); // OK, because used in synchronised method - private SamplingStatCalculator model; + private CachingStatCalculator model; private JTextField maxYField = null; @@ -94,7 +94,7 @@ * Constructor for the GraphVisualizer object. */ public GraphVisualizer() { - model = new SamplingStatCalculator("Graph"); + model = new CachingStatCalculator("Graph"); graph = new Graph(model); init(); } Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SplineModel.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SplineModel.java?rev=891076&r1=891075&r2=891076&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SplineModel.java (original) +++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SplineModel.java Wed Dec 16 00:02:46 2009 @@ -37,7 +37,7 @@ //@GuardedBy("this") private Spline3 dataCurve = null; - final SamplingStatCalculator samples; + final CachingStatCalculator samples; //@GuardedBy("this") private GraphListener listener; @@ -46,7 +46,7 @@ private String name; public SplineModel() { - samples = new SamplingStatCalculator("Spline"); + samples = new CachingStatCalculator("Spline"); } public synchronized void setListener(GraphListener vis) { Added: jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/CachingStatCalculator.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/CachingStatCalculator.java?rev=891076&view=auto ============================================================================== --- jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/CachingStatCalculator.java (added) +++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/CachingStatCalculator.java Wed Dec 16 00:02:46 2009 @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.visualizers; + +import java.util.List; +import java.util.Vector; + +import org.apache.jmeter.samplers.SampleResult; + +/** + * Provides storage of samples in addition to calculations + */ +public class CachingStatCalculator extends SamplingStatCalculator { + + private final List<Sample> storedValues = new Vector<Sample>(); + + public CachingStatCalculator(String string) { + super(string); + } + + public List<Sample> getSamples() { + return storedValues; + } + + public Sample getSample(int index) { + synchronized( storedValues ){ + if (index < storedValues.size()) { + return storedValues.get(index); + } + } + return null; + } + + @Override + public void clear() { + super.clear(); + storedValues.clear(); + } + /** + * Records a sample. + * + */ + @Override + public Sample addSample(SampleResult res) { + final Sample sample = super.addSample(res); + storedValues.add(sample); + return sample; + } +} Propchange: jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/CachingStatCalculator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/CachingStatCalculator.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/SamplingStatCalculator.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/SamplingStatCalculator.java?rev=891076&r1=891075&r2=891076&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/SamplingStatCalculator.java (original) +++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/visualizers/SamplingStatCalculator.java Wed Dec 16 00:02:46 2009 @@ -18,15 +18,10 @@ package org.apache.jmeter.visualizers; -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; import org.apache.jorphan.math.StatCalculatorLong; -import org.apache.log.Logger; /** * Aggegate sample data container. Just instantiate a new instance of this @@ -35,61 +30,30 @@ * */ public class SamplingStatCalculator { - private static final Logger log = LoggingManager.getLoggerForClass(); - private final StatCalculatorLong calculator = new StatCalculatorLong(); - private final List<Sample> storedValues = new Vector<Sample>(); - private double maxThroughput; private long firstTime; private String label; - /** - * @deprecated only for use by test code - */ - @Deprecated - public SamplingStatCalculator() {// Don't (can't) use this... - log.warn("Constructor only intended for use in testing"); // $NON-NLS-1$ + private Sample currentSample; + + public SamplingStatCalculator(){ // Only for use by test code + this(""); } - /** - * Use this constructor. - */ public SamplingStatCalculator(String label) { this.label = label; init(); } - /** - * Essentially a copy function - * - * @param stat - */ - public SamplingStatCalculator(SamplingStatCalculator stat) { - this(stat.label); - addSamples(stat); - } - private void init() { firstTime = Long.MAX_VALUE; calculator.clear(); - storedValues.clear(); maxThroughput = Double.MIN_VALUE; - } - - public void addSamples(SamplingStatCalculator ssc) { - calculator.addAll(ssc.calculator); - synchronized( storedValues ) - { - storedValues.addAll(ssc.storedValues); - Collections.sort(storedValues); - } - if (firstTime > ssc.firstTime) { - firstTime = ssc.firstTime; - } + currentSample = new Sample(); } /** @@ -101,13 +65,7 @@ } public Sample getCurrentSample() { - synchronized( storedValues ) - { - if (storedValues.size() == 0) { - return new Sample(); - } - return storedValues.get(storedValues.size() - 1); - } + return currentSample; } /** @@ -227,26 +185,11 @@ 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<Sample> getSamples() { - return storedValues; - } - - public Sample getSample(int index) { - synchronized( storedValues ){ - if (index < storedValues.size()) { - return storedValues.get(index); - } - return null; - } + int count = calculator.getCount(); + Sample s = + new Sample( null, rtime, cmean, cstdv, cmedian, cpercent, throughput, eCount, rbool, count, endTime ); + currentSample = s; + return s; } private long getEndTime(SampleResult res) { --------------------------------------------------------------------- To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org