|
What this is
Other links
The source code// $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/visualizers/RunningSample.java,v 1.2 2004/02/13 02:40:54 sebb Exp $ /* * Copyright 2001-2004 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. * 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.text.DecimalFormat; import org.apache.jmeter.samplers.SampleResult; /** * Aggegate sample data container. Just instantiate a new instance of this * class, and then call {@link #addSample(SampleResult)} a few times, and pull * the stats out with whatever methods you prefer. * * @author James Boutcher * @version $Revision: 1.2 $ */ public class RunningSample { private static DecimalFormat rateFormatter = new DecimalFormat("#.0"); private static DecimalFormat errorFormatter = new DecimalFormat("#0.00%"); private long counter; private long runningSum; private long max, min; private long errorCount; private long firstTime; private long lastTime; private String label; private int index; private RunningSample(){// Don't (can't) use this... } /** * Use this constructor. */ public RunningSample(String label, int index) { this.label = label; this.index = index; init(); } /** * Copy constructor to a duplicate of existing instance * (without the disadvantages of clone()0 * @param src RunningSample */ public RunningSample(RunningSample src){ this.counter = src.counter; this.errorCount = src.errorCount; this.firstTime = src.firstTime; this.index = src.index; this.label = src.label; this.lastTime = src.lastTime; this.max = src.max; this.min = src.min; this.runningSum = src.runningSum; } private void init(){ counter = 0L; runningSum = 0L; max = Long.MIN_VALUE; min = Long.MAX_VALUE; errorCount = 0L; firstTime = Long.MAX_VALUE; lastTime = 0L; } /** * Clear the counters (useful for differential stats) * */ public synchronized void clear(){ init(); } /** * Get the elapsed time for the samples * @return how long the samples took */ public long getElapsed(){ if (lastTime == 0) return 0;// No samples collected ... return lastTime - firstTime; } /** * Returns the throughput associated to this sampler in requests per second. * May be slightly skewed because it takes the timestamps of the first and * last samples as the total time passed, and the test may actually have * started before that start time and ended after that end time. **/ public double getRate() { if (counter == 0) return 0.0; //Better behaviour when howLong=0 or lastTime=0 long howLongRunning = lastTime - firstTime; if (howLongRunning == 0) { return Double.MAX_VALUE; } return (double) counter / howLongRunning * 1000.0; } /** * Returns the throughput associated to this sampler in requests per min. * May be slightly skewed because it takes the timestamps of the first and * last samples as the total time passed, and the test may actually have * started before that start time and ended after that end time. **/ public double getRatePerMin() { if (counter == 0) return 0.0; //Better behaviour when howLong=0 or lastTime=0 long howLongRunning = lastTime - firstTime; if (howLongRunning == 0) { return Double.MAX_VALUE; } return (double) counter / howLongRunning * 60000.0; } /** * Returns a String that represents the throughput associated for this * sampler, in units appropriate to its dimension: * |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.