Lines 26-31
Link Here
|
26 |
import java.util.HashSet; |
26 |
import java.util.HashSet; |
27 |
import java.util.List; |
27 |
import java.util.List; |
28 |
import java.util.Set; |
28 |
import java.util.Set; |
|
|
29 |
import java.lang.reflect.Method; |
30 |
import java.lang.reflect.InvocationTargetException; |
29 |
|
31 |
|
30 |
import org.apache.avalon.framework.configuration.Configuration; |
32 |
import org.apache.avalon.framework.configuration.Configuration; |
31 |
import org.apache.jmeter.assertions.AssertionResult; |
33 |
import org.apache.jmeter.assertions.AssertionResult; |
Lines 140-145
Link Here
|
140 |
private String dataEncoding;// (is this really the character set?) e.g. |
142 |
private String dataEncoding;// (is this really the character set?) e.g. |
141 |
// ISO-8895-1, UTF-8 |
143 |
// ISO-8895-1, UTF-8 |
142 |
|
144 |
|
|
|
145 |
private static Method initNanoTimeMethod() { |
146 |
try { |
147 |
return System.class.getMethod("nanoTime", null); |
148 |
} catch (NoSuchMethodException e) { |
149 |
return null; |
150 |
} |
151 |
} |
152 |
|
153 |
private static boolean haveNanoTime() { |
154 |
return nanoTimeMethod != null; |
155 |
} |
156 |
|
157 |
private static long nanoTime() { |
158 |
Long result = null; |
159 |
try { |
160 |
result = (Long) nanoTimeMethod.invoke(null, null); |
161 |
} catch (IllegalAccessException e) { |
162 |
throw new RuntimeException(e); |
163 |
} catch (InvocationTargetException e) { |
164 |
throw new RuntimeException(e); |
165 |
} |
166 |
return result.longValue(); |
167 |
} |
168 |
|
169 |
private static final Method nanoTimeMethod = initNanoTimeMethod(); |
170 |
|
171 |
// a reference time from the nanosecond clock |
172 |
private static final long referenceTimeNsClock = haveNanoTime() ? sampleNsClockInMs() : Long.MIN_VALUE; |
173 |
|
174 |
private static final long referenceTimeMsClock = System.currentTimeMillis(); // a reference time from the |
175 |
// millisecond clock |
176 |
|
143 |
private long time = 0; // elapsed time |
177 |
private long time = 0; // elapsed time |
144 |
|
178 |
|
145 |
private long latency = 0; // time to first response |
179 |
private long latency = 0; // time to first response |
Lines 228-234
Link Here
|
228 |
* create the sample finishing now, else starting now |
262 |
* create the sample finishing now, else starting now |
229 |
*/ |
263 |
*/ |
230 |
protected SampleResult(long elapsed, boolean atend) { |
264 |
protected SampleResult(long elapsed, boolean atend) { |
231 |
long now = System.currentTimeMillis(); |
265 |
long now = currentTimeInMs(); |
232 |
if (atend) { |
266 |
if (atend) { |
233 |
setTimes(now - elapsed, now); |
267 |
setTimes(now - elapsed, now); |
234 |
} else { |
268 |
} else { |
Lines 262-268
Link Here
|
262 |
* desired elapsed time |
296 |
* desired elapsed time |
263 |
*/ |
297 |
*/ |
264 |
public static SampleResult createTestSample(long elapsed) { |
298 |
public static SampleResult createTestSample(long elapsed) { |
265 |
long now = System.currentTimeMillis(); |
299 |
long now = currentTimeInMs(); |
266 |
return createTestSample(now, now + elapsed); |
300 |
return createTestSample(now, now + elapsed); |
267 |
} |
301 |
} |
268 |
|
302 |
|
Lines 280-285
Link Here
|
280 |
stampAndTime(stamp, elapsed); |
314 |
stampAndTime(stamp, elapsed); |
281 |
} |
315 |
} |
282 |
|
316 |
|
|
|
317 |
private static long sampleNsClockInMs() { |
318 |
return nanoTime() / 1000000; |
319 |
} |
320 |
|
321 |
// Helper method to get 1 ms resolution timing. |
322 |
public static long currentTimeInMs() { |
323 |
if (haveNanoTime()) { |
324 |
long elapsedInMs = sampleNsClockInMs() - referenceTimeNsClock; |
325 |
return referenceTimeMsClock + elapsedInMs; |
326 |
} else { |
327 |
return System.currentTimeMillis(); |
328 |
} |
329 |
} |
330 |
|
283 |
// Helper method to maintain timestamp relationships |
331 |
// Helper method to maintain timestamp relationships |
284 |
private void stampAndTime(long stamp, long elapsed) { |
332 |
private void stampAndTime(long stamp, long elapsed) { |
285 |
if (startTimeStamp) { |
333 |
if (startTimeStamp) { |
Lines 325-331
Link Here
|
325 |
if (startTime != 0 || endTime != 0){ |
373 |
if (startTime != 0 || endTime != 0){ |
326 |
throw new RuntimeException("Calling setTime() after start/end times have been set"); |
374 |
throw new RuntimeException("Calling setTime() after start/end times have been set"); |
327 |
} |
375 |
} |
328 |
long now = System.currentTimeMillis(); |
376 |
long now = currentTimeInMs(); |
329 |
setTimes(now - elapsed, now); |
377 |
setTimes(now - elapsed, now); |
330 |
} |
378 |
} |
331 |
|
379 |
|
Lines 805-811
Link Here
|
805 |
*/ |
853 |
*/ |
806 |
public void sampleStart() { |
854 |
public void sampleStart() { |
807 |
if (startTime == 0) { |
855 |
if (startTime == 0) { |
808 |
setStartTime(System.currentTimeMillis()); |
856 |
setStartTime(currentTimeInMs()); |
809 |
} else { |
857 |
} else { |
810 |
log.error("sampleStart called twice", new Throwable("Invalid call sequence")); |
858 |
log.error("sampleStart called twice", new Throwable("Invalid call sequence")); |
811 |
} |
859 |
} |
Lines 817-823
Link Here
|
817 |
*/ |
865 |
*/ |
818 |
public void sampleEnd() { |
866 |
public void sampleEnd() { |
819 |
if (endTime == 0) { |
867 |
if (endTime == 0) { |
820 |
setEndTime(System.currentTimeMillis()); |
868 |
setEndTime(currentTimeInMs()); |
821 |
} else { |
869 |
} else { |
822 |
log.error("sampleEnd called twice", new Throwable("Invalid call sequence")); |
870 |
log.error("sampleEnd called twice", new Throwable("Invalid call sequence")); |
823 |
} |
871 |
} |
Lines 831-837
Link Here
|
831 |
if (pauseTime != 0) { |
879 |
if (pauseTime != 0) { |
832 |
log.error("samplePause called twice", new Throwable("Invalid call sequence")); |
880 |
log.error("samplePause called twice", new Throwable("Invalid call sequence")); |
833 |
} |
881 |
} |
834 |
pauseTime = System.currentTimeMillis(); |
882 |
pauseTime = currentTimeInMs(); |
835 |
} |
883 |
} |
836 |
|
884 |
|
837 |
/** |
885 |
/** |
Lines 842-848
Link Here
|
842 |
if (pauseTime == 0) { |
890 |
if (pauseTime == 0) { |
843 |
log.error("sampleResume without samplePause", new Throwable("Invalid call sequence")); |
891 |
log.error("sampleResume without samplePause", new Throwable("Invalid call sequence")); |
844 |
} |
892 |
} |
845 |
idleTime += System.currentTimeMillis() - pauseTime; |
893 |
idleTime += currentTimeInMs() - pauseTime; |
846 |
pauseTime = 0; |
894 |
pauseTime = 0; |
847 |
} |
895 |
} |
848 |
|
896 |
|
Lines 943-949
Link Here
|
943 |
* |
991 |
* |
944 |
*/ |
992 |
*/ |
945 |
public void latencyEnd() { |
993 |
public void latencyEnd() { |
946 |
latency = System.currentTimeMillis() - startTime - idleTime; |
994 |
latency = currentTimeInMs() - startTime - idleTime; |
947 |
} |
995 |
} |
948 |
|
996 |
|
949 |
/** |
997 |
/** |