use millis precision + javadoc

This commit is contained in:
Guillaume Polaert 2017-07-27 10:48:35 +02:00
parent ebb3cde32c
commit 4ed46cec39
2 changed files with 24 additions and 2 deletions

View File

@ -46,8 +46,7 @@ public abstract class DDBaseSpan<S extends BaseSpan> implements BaseSpan<S> {
} }
public final void finish() { public final void finish() {
this.durationNano = Clock.currentNanoTicks() - startTimeNano; finish(Clock.currentMicroTime() - startTimeMicro);
afterFinish();
} }
public final void finish(final long stoptimeMicros) { public final void finish(final long stoptimeMicros) {

View File

@ -2,12 +2,35 @@ package com.datadoghq.trace.util;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/**
* A simple wrapper for system clock that aims to provide the current time
*
* <p>
*
* <p>The JDK provides two clocks:
* <li>one in nanoseconds, for precision, but it can only use to measure durations
* <li>one in milliseconds, for accuracy, useful to provide epoch time
* <p>
* <p>At this time, we are using a millis precision (converted to micros) in order to guarantee
* consistency between the span start times and the durations
*/
public class Clock { public class Clock {
/**
* Get the current nanos ticks, this method can't be use for date accuracy (only duration
* calculations)
*
* @return The current nanos ticks
*/
public static synchronized long currentNanoTicks() { public static synchronized long currentNanoTicks() {
return System.nanoTime(); return System.nanoTime();
} }
/**
* Get the current time in micros. The actual precision is the millis
*
* @return the current epoch time in micros
*/
public static synchronized long currentMicroTime() { public static synchronized long currentMicroTime() {
return TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); return TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
} }