Lines 140-145
Link Here
|
140 |
private String dataEncoding;// (is this really the character set?) e.g. |
140 |
private String dataEncoding;// (is this really the character set?) e.g. |
141 |
// ISO-8895-1, UTF-8 |
141 |
// ISO-8895-1, UTF-8 |
142 |
|
142 |
|
|
|
143 |
private static long referenceTimeNsClock; // a reference time from the nanosecond clock in milliseconds |
144 |
|
145 |
private static long referenceTimeMsClock; // a reference time from the millisecond clock in milliseconds |
146 |
|
143 |
private long time = 0; // elapsed time |
147 |
private long time = 0; // elapsed time |
144 |
|
148 |
|
145 |
private long latency = 0; // time to first response |
149 |
private long latency = 0; // time to first response |
Lines 175-183
Link Here
|
175 |
} |
179 |
} |
176 |
|
180 |
|
177 |
public SampleResult() { |
181 |
public SampleResult() { |
|
|
182 |
initReferenceTime(); |
178 |
time = 0; |
183 |
time = 0; |
179 |
} |
184 |
} |
180 |
|
185 |
|
|
|
186 |
private static void initReferenceTime() { |
187 |
if (referenceTimeMsClock == 0) { |
188 |
referenceTimeNsClock = sampleNsClockInMs(); |
189 |
referenceTimeMsClock = System.currentTimeMillis(); |
190 |
} |
191 |
} |
192 |
|
181 |
/** |
193 |
/** |
182 |
* Construct a 'parent' result for an already-existing result, essentially |
194 |
* Construct a 'parent' result for an already-existing result, essentially |
183 |
* cloning it |
195 |
* cloning it |
Lines 186-191
Link Here
|
186 |
* existing sample result |
198 |
* existing sample result |
187 |
*/ |
199 |
*/ |
188 |
public SampleResult(SampleResult res) { |
200 |
public SampleResult(SampleResult res) { |
|
|
201 |
initReferenceTime(); |
189 |
//TODO - why not just copy all the fields? Do we need the calculations that some of the set() methods perform? |
202 |
//TODO - why not just copy all the fields? Do we need the calculations that some of the set() methods perform? |
190 |
//TODO - why are the following not copied: |
203 |
//TODO - why are the following not copied: |
191 |
// assertionResults, bytes, idleTime, latency, parent,pauseTime,resultFileName,sampleCount,samplerData,saveConfig |
204 |
// assertionResults, bytes, idleTime, latency, parent,pauseTime,resultFileName,sampleCount,samplerData,saveConfig |
Lines 228-234
Link Here
|
228 |
* create the sample finishing now, else starting now |
241 |
* create the sample finishing now, else starting now |
229 |
*/ |
242 |
*/ |
230 |
protected SampleResult(long elapsed, boolean atend) { |
243 |
protected SampleResult(long elapsed, boolean atend) { |
231 |
long now = System.currentTimeMillis(); |
244 |
initReferenceTime(); |
|
|
245 |
long now = currentTimeInMs(); |
232 |
if (atend) { |
246 |
if (atend) { |
233 |
setTimes(now - elapsed, now); |
247 |
setTimes(now - elapsed, now); |
234 |
} else { |
248 |
} else { |
Lines 237-272
Link Here
|
237 |
} |
251 |
} |
238 |
|
252 |
|
239 |
/** |
253 |
/** |
240 |
* Create a sample with specific start and end times for test purposes, but |
|
|
241 |
* don't allow the times to be changed later |
242 |
* |
243 |
* (used by StatVisualizerModel.Test) |
244 |
* |
245 |
* @param start |
246 |
* start time |
247 |
* @param end |
248 |
* end time |
249 |
*/ |
250 |
public static SampleResult createTestSample(long start, long end) { |
251 |
SampleResult res = new SampleResult(); |
252 |
res.setStartTime(start); |
253 |
res.setEndTime(end); |
254 |
return res; |
255 |
} |
256 |
|
257 |
/** |
258 |
* Create a sample with a specific elapsed time for test purposes, but don't |
259 |
* allow the times to be changed later |
260 |
* |
261 |
* @param elapsed - |
262 |
* desired elapsed time |
263 |
*/ |
264 |
public static SampleResult createTestSample(long elapsed) { |
265 |
long now = System.currentTimeMillis(); |
266 |
return createTestSample(now, now + elapsed); |
267 |
} |
268 |
|
269 |
/** |
270 |
* Allow users to create a sample with specific timestamp and elapsed times |
254 |
* Allow users to create a sample with specific timestamp and elapsed times |
271 |
* for cloning purposes, but don't allow the times to be changed later |
255 |
* for cloning purposes, but don't allow the times to be changed later |
272 |
* |
256 |
* |
Lines 277-285
Link Here
|
277 |
* @param elapsed |
261 |
* @param elapsed |
278 |
*/ |
262 |
*/ |
279 |
public SampleResult(long stamp, long elapsed) { |
263 |
public SampleResult(long stamp, long elapsed) { |
|
|
264 |
initReferenceTime(); |
280 |
stampAndTime(stamp, elapsed); |
265 |
stampAndTime(stamp, elapsed); |
281 |
} |
266 |
} |
282 |
|
267 |
|
|
|
268 |
private static long sampleNsClockInMs() { |
269 |
return System.nanoTime() / 1000000; |
270 |
} |
271 |
|
272 |
// Helper method to get 1 ms resolution timing. |
273 |
private static long currentTimeInMs() { |
274 |
long elapsedInMs = sampleNsClockInMs() - referenceTimeNsClock; |
275 |
return referenceTimeMsClock + elapsedInMs; |
276 |
} |
277 |
|
283 |
// Helper method to maintain timestamp relationships |
278 |
// Helper method to maintain timestamp relationships |
284 |
private void stampAndTime(long stamp, long elapsed) { |
279 |
private void stampAndTime(long stamp, long elapsed) { |
285 |
if (startTimeStamp) { |
280 |
if (startTimeStamp) { |
Lines 325-331
Link Here
|
325 |
if (startTime != 0 || endTime != 0){ |
320 |
if (startTime != 0 || endTime != 0){ |
326 |
throw new RuntimeException("Calling setTime() after start/end times have been set"); |
321 |
throw new RuntimeException("Calling setTime() after start/end times have been set"); |
327 |
} |
322 |
} |
328 |
long now = System.currentTimeMillis(); |
323 |
long now = currentTimeInMs(); |
329 |
setTimes(now - elapsed, now); |
324 |
setTimes(now - elapsed, now); |
330 |
} |
325 |
} |
331 |
|
326 |
|
Lines 805-811
Link Here
|
805 |
*/ |
800 |
*/ |
806 |
public void sampleStart() { |
801 |
public void sampleStart() { |
807 |
if (startTime == 0) { |
802 |
if (startTime == 0) { |
808 |
setStartTime(System.currentTimeMillis()); |
803 |
setStartTime(currentTimeInMs()); |
809 |
} else { |
804 |
} else { |
810 |
log.error("sampleStart called twice", new Throwable("Invalid call sequence")); |
805 |
log.error("sampleStart called twice", new Throwable("Invalid call sequence")); |
811 |
} |
806 |
} |
Lines 817-823
Link Here
|
817 |
*/ |
812 |
*/ |
818 |
public void sampleEnd() { |
813 |
public void sampleEnd() { |
819 |
if (endTime == 0) { |
814 |
if (endTime == 0) { |
820 |
setEndTime(System.currentTimeMillis()); |
815 |
setEndTime(currentTimeInMs()); |
821 |
} else { |
816 |
} else { |
822 |
log.error("sampleEnd called twice", new Throwable("Invalid call sequence")); |
817 |
log.error("sampleEnd called twice", new Throwable("Invalid call sequence")); |
823 |
} |
818 |
} |
Lines 831-837
Link Here
|
831 |
if (pauseTime != 0) { |
826 |
if (pauseTime != 0) { |
832 |
log.error("samplePause called twice", new Throwable("Invalid call sequence")); |
827 |
log.error("samplePause called twice", new Throwable("Invalid call sequence")); |
833 |
} |
828 |
} |
834 |
pauseTime = System.currentTimeMillis(); |
829 |
pauseTime = currentTimeInMs(); |
835 |
} |
830 |
} |
836 |
|
831 |
|
837 |
/** |
832 |
/** |
Lines 842-848
Link Here
|
842 |
if (pauseTime == 0) { |
837 |
if (pauseTime == 0) { |
843 |
log.error("sampleResume without samplePause", new Throwable("Invalid call sequence")); |
838 |
log.error("sampleResume without samplePause", new Throwable("Invalid call sequence")); |
844 |
} |
839 |
} |
845 |
idleTime += System.currentTimeMillis() - pauseTime; |
840 |
idleTime += currentTimeInMs() - pauseTime; |
846 |
pauseTime = 0; |
841 |
pauseTime = 0; |
847 |
} |
842 |
} |
848 |
|
843 |
|
Lines 943-949
Link Here
|
943 |
* |
938 |
* |
944 |
*/ |
939 |
*/ |
945 |
public void latencyEnd() { |
940 |
public void latencyEnd() { |
946 |
latency = System.currentTimeMillis() - startTime - idleTime; |
941 |
latency = currentTimeInMs() - startTime - idleTime; |
947 |
} |
942 |
} |
948 |
|
943 |
|
949 |
/** |
944 |
/** |