Skip to content

Commit

Permalink
Merge pull request #366 from praveen27/master
Browse files Browse the repository at this point in the history
Added support to get command start time in Nanos
  • Loading branch information
mattrjacobs committed Jan 7, 2015
2 parents 16a1d66 + 62400a1 commit 33b1ea3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,7 @@ protected static class ExecutionResult {
protected final List<HystrixEventType> events;
private final int executionTime;
private final Exception exception;
private final long commandRunStartTimeInNanos;

private ExecutionResult(HystrixEventType... events) {
this(Arrays.asList(events), -1, null);
Expand All @@ -1401,7 +1402,14 @@ private ExecutionResult(List<HystrixEventType> events, int executionTime, Except
// because we control the original list in 'newEvent'
this.events = events;
this.executionTime = executionTime;
if (executionTime >= 0 ) {
this.commandRunStartTimeInNanos = System.nanoTime() - this.executionTime*1000*1000; // 1000*1000 will conver the milliseconds to nanoseconds
}
else {
this.commandRunStartTimeInNanos = -1;
}
this.exception = e;

}

// we can return a static version since it's immutable
Expand All @@ -1425,6 +1433,9 @@ public ExecutionResult addEvents(HystrixEventType... events) {
public int getExecutionTime() {
return executionTime;
}
public long getCommandRunStartTimeInNanos() {return commandRunStartTimeInNanos; }



public Exception getException() {
return exception;
Expand Down Expand Up @@ -1592,6 +1603,16 @@ public int getExecutionTimeInMilliseconds() {
return executionResult.getExecutionTime();
}

/**
* Time in Nanos when this command instance's run method was called, or -1 if not executed
* for e.g., command threw an exception
*
* @return long
*/
public long getCommandRunStartTimeInNanos() {
return executionResult.getCommandRunStartTimeInNanos();
}

protected Exception getExceptionFromThrowable(Throwable t) {
Exception e = null;
if (t instanceof Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ public interface HystrixInvokableInfo<R> {

public int getExecutionTimeInMilliseconds();

public long getCommandRunStartTimeInNanos();

}

0 comments on commit 33b1ea3

Please sign in to comment.