| 1 | |
package kg.apc.jmeter.vizualizers; |
| 2 | |
|
| 3 | |
import java.awt.Color; |
| 4 | |
import kg.apc.charting.AbstractGraphRow; |
| 5 | |
import kg.apc.jmeter.JMeterPluginsUtils; |
| 6 | |
import kg.apc.jmeter.graphs.AbstractOverTimeVisualizer; |
| 7 | |
import org.apache.jmeter.samplers.SampleResult; |
| 8 | |
|
| 9 | |
public class TransactionsPerSecondGui |
| 10 | |
extends AbstractOverTimeVisualizer { |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | 1 | private static String labelAggSuccess = "Successful Transactions per Second"; |
| 17 | 1 | private static String labelAggFailure = "Failed Transactions per Second"; |
| 18 | |
|
| 19 | |
public TransactionsPerSecondGui() { |
| 20 | 6 | super(); |
| 21 | 6 | setGranulation(1000); |
| 22 | 6 | graphPanel.getGraphObject().setYAxisLabel("Number of transactions /sec"); |
| 23 | 6 | } |
| 24 | |
|
| 25 | |
private void addTransaction(boolean isSuccess, String rowName, long time, double count) { |
| 26 | |
String realRowName; |
| 27 | |
String rowAggName; |
| 28 | |
|
| 29 | 2 | if (isSuccess) { |
| 30 | 0 | realRowName = rowName + " (success)"; |
| 31 | 0 | rowAggName = labelAggSuccess; |
| 32 | |
} else { |
| 33 | 2 | realRowName = rowName + " (failure)"; |
| 34 | 2 | rowAggName = labelAggFailure; |
| 35 | |
} |
| 36 | |
|
| 37 | 2 | AbstractGraphRow row = model.get(realRowName); |
| 38 | 2 | AbstractGraphRow rowAgg = modelAggregate.get(rowAggName); |
| 39 | |
|
| 40 | 2 | if (row == null) { |
| 41 | 1 | row = getNewRow(model, AbstractGraphRow.ROW_SUM_VALUES, realRowName, AbstractGraphRow.MARKER_SIZE_SMALL, false, false, false, true, true); |
| 42 | |
} |
| 43 | |
|
| 44 | 2 | if (rowAgg == null) { |
| 45 | 1 | rowAgg = getNewRow(modelAggregate, AbstractGraphRow.ROW_SUM_VALUES, rowAggName, AbstractGraphRow.MARKER_SIZE_SMALL, false, false, false, true, isSuccess ? Color.GREEN : Color.RED, true); |
| 46 | |
} |
| 47 | |
|
| 48 | |
|
| 49 | 2 | if (getGranulation() > 0) { |
| 50 | 2 | double tps = count * 1000.0 / getGranulation(); |
| 51 | 2 | row.add(time, tps); |
| 52 | 2 | rowAgg.add(time, tps); |
| 53 | |
|
| 54 | 2 | if (isSuccess) { |
| 55 | 0 | rowAgg = modelAggregate.get(labelAggFailure); |
| 56 | 0 | if (rowAgg == null) { |
| 57 | 0 | rowAgg = getNewRow(modelAggregate, AbstractGraphRow.ROW_SUM_VALUES, labelAggFailure, AbstractGraphRow.MARKER_SIZE_SMALL, false, false, false, true, Color.RED, true); |
| 58 | |
} |
| 59 | 0 | rowAgg.add(time, 0); |
| 60 | |
} |
| 61 | |
} |
| 62 | 2 | } |
| 63 | |
|
| 64 | |
@Override |
| 65 | |
public String getLabelResource() { |
| 66 | 1 | return this.getClass().getSimpleName(); |
| 67 | |
} |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
public String getStaticLabel() { |
| 71 | 13 | return JMeterPluginsUtils.prefixLabel("Transactions per Second"); |
| 72 | |
} |
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public void add(SampleResult res) { |
| 76 | 2 | if (!isSampleIncluded(res)) { |
| 77 | 0 | return; |
| 78 | |
} |
| 79 | 2 | super.add(res); |
| 80 | 2 | if (res.isSuccessful()) { |
| 81 | 0 | addTransaction(true, res.getSampleLabel(), normalizeTime(res.getEndTime()), 1); |
| 82 | |
|
| 83 | |
} else { |
| 84 | 2 | addTransaction(false, res.getSampleLabel(), normalizeTime(res.getEndTime()), 1); |
| 85 | |
} |
| 86 | 2 | updateGui(null); |
| 87 | 2 | } |
| 88 | |
|
| 89 | |
@Override |
| 90 | |
protected JSettingsPanel createSettingsPanel() { |
| 91 | 8 | return new JSettingsPanel(this, |
| 92 | |
JSettingsPanel.TIMELINE_OPTION |
| 93 | |
| JSettingsPanel.GRADIENT_OPTION |
| 94 | |
| JSettingsPanel.FINAL_ZEROING_OPTION |
| 95 | |
| JSettingsPanel.LIMIT_POINT_OPTION |
| 96 | |
| JSettingsPanel.AGGREGATE_OPTION |
| 97 | |
| JSettingsPanel.MAXY_OPTION |
| 98 | |
| JSettingsPanel.RELATIVE_TIME_OPTION |
| 99 | |
| JSettingsPanel.MARKERS_OPTION); |
| 100 | |
} |
| 101 | |
|
| 102 | |
@Override |
| 103 | |
public String getWikiPage() { |
| 104 | 7 | return "TransactionsPerSecond"; |
| 105 | |
} |
| 106 | |
} |