Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Fix needed for phoenix 2178 #10

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions htrace-core4/src/main/java/org/apache/htrace/core/MilliSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public class MilliSpan implements Span {
private static final String EMPTY_STRING = "";

private long begin;
private long beginNano;
private long end;
private long endNano;
private final String description;
private SpanId parents[];
private final SpanId spanId;
Expand All @@ -62,8 +64,8 @@ public class MilliSpan implements Span {
@Override
public Span child(String childDescription) {
return new MilliSpan.Builder().
begin(System.currentTimeMillis()).
end(0).
begin(System.currentTimeMillis(),System.nanoTime()).
end(0,0).
description(childDescription).
parents(new SpanId[] {spanId}).
spanId(spanId.newChildId()).
Expand All @@ -76,7 +78,9 @@ public Span child(String childDescription) {
*/
public static class Builder {
private long begin;
private long beginNano;
private long end;
private long endNano;
private String description = EMPTY_STRING;
private SpanId parents[] = EMPTY_PARENT_ARRAY;
private SpanId spanId = SpanId.INVALID;
Expand All @@ -87,13 +91,25 @@ public static class Builder {
public Builder() {
}

public Builder begin(long begin) {
public Builder begin(long begin){
this.begin = begin;
return this;
}

public Builder end(long end) {
public Builder begin(long begin, long beginNano) {
this.begin = begin;
this.beginNano = beginNano;
return this;
}

public Builder end(long end){
this.end = end;
return this;
}

public Builder end(long end, long endNano) {
this.end = end;
this.endNano = endNano;
return this;
}

Expand Down Expand Up @@ -143,7 +159,9 @@ public MilliSpan build() {

public MilliSpan() {
this.begin = 0;
this.beginNano = 0;
this.end = 0;
this.endNano = 0;
this.description = EMPTY_STRING;
this.parents = EMPTY_PARENT_ARRAY;
this.spanId = SpanId.INVALID;
Expand All @@ -155,6 +173,8 @@ public MilliSpan() {
private MilliSpan(Builder builder) {
this.begin = builder.begin;
this.end = builder.end;
this.beginNano = builder.beginNano;
this.endNano = builder.endNano;
this.description = builder.description;
this.parents = builder.parents;
this.spanId = builder.spanId;
Expand All @@ -170,6 +190,7 @@ public synchronized void stop() {
throw new IllegalStateException("Span for " + description
+ " has not been started");
end = System.currentTimeMillis();
endNano = System.nanoTime();
}
}

Expand Down Expand Up @@ -287,11 +308,11 @@ public MilliSpan deserialize(JsonParser jp, DeserializationContext ctxt)
Builder builder = new Builder();
JsonNode bNode = root.get("b");
if (bNode != null) {
builder.begin(bNode.asLong());
builder.begin(bNode.asLong(),bNode.asLong());
}
JsonNode eNode = root.get("e");
if (eNode != null) {
builder.end(eNode.asLong());
builder.end(eNode.asLong(),eNode.asLong());
}
JsonNode dNode = root.get("d");
if (dNode != null) {
Expand Down Expand Up @@ -344,4 +365,14 @@ public MilliSpan deserialize(JsonParser jp, DeserializationContext ctxt)
public static MilliSpan fromJson(String json) throws IOException {
return JSON_READER.readValue(json);
}

@Override
public long getStartTimeNanos() {
return beginNano;
}

@Override
public long getStopTimeNanos() {
return endNano;
}
}
20 changes: 20 additions & 0 deletions htrace-core4/src/main/java/org/apache/htrace/core/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,27 @@ public interface Span {
*/
long getStartTimeMillis();

/**
* Get the span start time.
*
* @return The start time, in approximate nanoseconds since the epoch.
*/
long getStartTimeNanos();

/**
* Get the span stop time.
*
* @return The stop time, in approximate milliseconds since the epoch.
*/
long getStopTimeMillis();

/**
* Get the span stop time.
*
* @return The stop time, in approximate nanoseconds since the epoch.
*/
long getStopTimeNanos();

/**
* Return the total amount of time elapsed since start was called, if running,
* or difference between stop and start
Expand Down Expand Up @@ -176,9 +190,15 @@ public void serialize(Span span, JsonGenerator jgen, SerializerProvider provider
if (span.getStartTimeMillis() != 0) {
jgen.writeNumberField("b", span.getStartTimeMillis());
}
if(span.getStartTimeNanos() != 0){
jgen.writeNumberField("k", span.getStartTimeNanos());
}
if (span.getStopTimeMillis() != 0) {
jgen.writeNumberField("e", span.getStopTimeMillis());
}
if(span.getStopTimeNanos() != 0){
jgen.writeNumberField("l",span.getStopTimeNanos());
}
if (!span.getDescription().isEmpty()) {
jgen.writeStringField("d", span.getDescription());
}
Expand Down
8 changes: 4 additions & 4 deletions htrace-core4/src/main/java/org/apache/htrace/core/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public String getTracerId() {
private TraceScope newScopeImpl(ThreadContext context, String description) {
Span span = new MilliSpan.Builder().
tracerId(tracerId).
begin(System.currentTimeMillis()).
begin(System.currentTimeMillis(),System.nanoTime()).
description(description).
parents(EMPTY_PARENT_ARRAY).
spanId(SpanId.fromRandom()).
Expand All @@ -326,7 +326,7 @@ private TraceScope newScopeImpl(ThreadContext context, String description,
SpanId parentId = parentScope.getSpan().getSpanId();
Span span = new MilliSpan.Builder().
tracerId(tracerId).
begin(System.currentTimeMillis()).
begin(System.currentTimeMillis(),System.nanoTime()).
description(description).
parents(new SpanId[] { parentId }).
spanId(parentId.newChildId()).
Expand All @@ -338,7 +338,7 @@ private TraceScope newScopeImpl(ThreadContext context, String description,
SpanId parentId) {
Span span = new MilliSpan.Builder().
tracerId(tracerId).
begin(System.currentTimeMillis()).
begin(System.currentTimeMillis(),System.nanoTime()).
description(description).
parents(new SpanId[] { parentId }).
spanId(parentId.newChildId()).
Expand All @@ -351,7 +351,7 @@ private TraceScope newScopeImpl(ThreadContext context, String description,
SpanId parentId = parentScope.getSpan().getSpanId();
Span span = new MilliSpan.Builder().
tracerId(tracerId).
begin(System.currentTimeMillis()).
begin(System.currentTimeMillis(),System.nanoTime()).
description(description).
parents(new SpanId[] { parentId, secondParentId }).
spanId(parentId.newChildId()).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ public long getStopTimeMillis() {
return span.getStop();
}

@Override
public long getStartTimeNanos() {
//TO DO: add nano support
return 0;
}

@Override
public long getStopTimeNanos() {
//TO DO : add nano support
return 0;
}

@Override
public SpanId getSpanId() {
return new SpanId(span.getTraceId(), span.getSpanId());
Expand Down