1 18 19 package org.apache.jmeter.visualizers; 20 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 25 import org.apache.jmeter.samplers.Clearable; 26 import org.apache.jmeter.samplers.SampleResult; 27 import org.apache.jmeter.util.JMeterUtils; 28 29 30 34 public class SplineModel implements Clearable 35 { 36 public final int DEFAULT_NUMBER_OF_NODES = 10; 37 public final int DEFAULT_REFRESH_PERIOD = 1; 38 39 protected final boolean SHOW_INCOMING_SAMPLES = true; 40 protected int numberOfNodes = DEFAULT_NUMBER_OF_NODES; 41 protected int refreshPeriod = DEFAULT_REFRESH_PERIOD; 42 43 44 protected Spline3 dataCurve = null; 45 46 47 protected long sum = 0; 48 49 50 protected long average = 0; 51 52 53 protected long n = 0; 54 55 ArrayList samples; 56 57 private GraphListener listener; 58 59 private long minimum = Integer.MAX_VALUE; 60 private long maximum = Integer.MIN_VALUE; 61 private long incoming; 62 63 private String name; 64 65 public SplineModel() 66 { 67 samples = new ArrayList (); 68 } 69 70 public void setListener(GraphListener vis) 71 { 72 listener = vis; 73 } 74 75 public void setName(String newName) 76 { 77 name = newName; 78 } 79 80 public boolean isEditable() 81 { 82 return true; 83 } 84 85 public Spline3 getDataCurve() 86 { 87 return dataCurve; 88 } 89 90 public Class getGuiClass() 91 { 92 return org.apache.jmeter.visualizers.SplineVisualizer.class; 93 } 94 95 public Collection getAddList() 96 { 97 return null; 98 } 99 100 public String getClassLabel() 101 { 102 return JMeterUtils.getResString("spline_visualizer_title"); 103 } 104 105 public long getMinimum() 106 { 107 return minimum; 108 } 109 110 public long getMaximum() 111 { 112 return maximum; 113 } 114 115 public long getAverage() 116 { 117 return average; 118 } 119 120 public long getCurrent() 121 { 122 return incoming; 123 } 124 125 public long[] getSamples() 126 { 127 int n = samples.size(); 128 long[] longSample = new long[n]; 129 130 for (int i = 0; i < n; i++) 131 { 132 longSample[i] = ((Long ) samples.get(i)).longValue(); 133 } 134 return longSample; 135 } 136 137 public long getSample(int i) 138 { 139 Long sample = (Long ) this.samples.get(i); 140 141 return sample.longValue(); 142 } 143 144 public int getNumberOfCollectedSamples() 145 { 146 return this.samples.size(); 147 } 148 149 public String getName() 150 { 151 return name; 152 } 153 154 public void uncompile() 155 { 156 clear(); 157 } 158 159 public synchronized void clear() 160 { 161 samples.clear(); 163 164 this.n = 0; 165 this.sum = 0; 166 this.average = 0; 167 168 minimum = Integer.MAX_VALUE; 169 maximum = Integer.MIN_VALUE; 170 171 this.dataCurve = null; 172 173 if (listener != null) 174 { 175 listener.updateGui(); 176 } 177 } 178 179 public synchronized void add(SampleResult sampleResult) 180 { 181 long sample = sampleResult.getTime(); 182 183 this.n++; 184 this.sum += sample; 185 this.average = this.sum / this.n; 186 if (SHOW_INCOMING_SAMPLES) 187 { 188 incoming = sample; 189 } 190 if (sample > maximum) 191 { 192 maximum = sample; 193 } 194 if (sample < minimum) 195 { 196 minimum = sample; 197 } 198 samples.add(new Long (sample)); 199 int n = getNumberOfCollectedSamples(); 200 201 if ((n % (numberOfNodes * refreshPeriod)) == 0) 202 { 203 float[] floatNode = new float[numberOfNodes]; 204 int loadFactor = n / numberOfNodes; 207 208 for (int i = 0; i < numberOfNodes; i++) 209 { 210 for (int j = 0; j < loadFactor; j++) 211 { 212 floatNode[i] += getSample((i * loadFactor) + j); 213 } 214 floatNode[i] = floatNode[i] / loadFactor; 215 } 216 dataCurve = new Spline3(floatNode); 218 if (listener != null) 219 { 220 listener.updateGui(); 221 } 222 } 223 else 224 { } 226 } 227 } 228 | Popular Tags |