/** * Indicate that an elapsed time sample should be taken. The sample is the time that has passed * since the last start() call with the name timer name (the argument key). It is an error to * call stop if there has been no corresponding call to start. * * @param key The name of the timer with which to record the new elapsed time sample. * @param dataAmount The amount of data transfered during this interval. * @return The length of the measured interval, in msec. */ public static double stop(String key, long dataAmount) { if (key == null) throw new RuntimeException("ElapsedTime key can't be null"); TransferRateInterval entry = mSampleSetManager.get(key); if (entry == null || entry.mStartTime < 0) throw new RuntimeException("stop(" + key + ") called but there was no matching start"); double timeSample = (System.nanoTime() - entry.mStartTime) * MSEC_SCALE; entry.mStartTime = -1; entry.addSample(timeSample, dataAmount); return timeSample > 0.0 ? dataAmount / timeSample : Double.MAX_VALUE; }