Skip to content

Commit 33b1ea3

Browse files
committed
Merge pull request #366 from praveen27/master
Added support to get command start time in Nanos
2 parents 16a1d66 + 62400a1 commit 33b1ea3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java

+21
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@ protected static class ExecutionResult {
13831383
protected final List<HystrixEventType> events;
13841384
private final int executionTime;
13851385
private final Exception exception;
1386+
private final long commandRunStartTimeInNanos;
13861387

13871388
private ExecutionResult(HystrixEventType... events) {
13881389
this(Arrays.asList(events), -1, null);
@@ -1401,7 +1402,14 @@ private ExecutionResult(List<HystrixEventType> events, int executionTime, Except
14011402
// because we control the original list in 'newEvent'
14021403
this.events = events;
14031404
this.executionTime = executionTime;
1405+
if (executionTime >= 0 ) {
1406+
this.commandRunStartTimeInNanos = System.nanoTime() - this.executionTime*1000*1000; // 1000*1000 will conver the milliseconds to nanoseconds
1407+
}
1408+
else {
1409+
this.commandRunStartTimeInNanos = -1;
1410+
}
14041411
this.exception = e;
1412+
14051413
}
14061414

14071415
// we can return a static version since it's immutable
@@ -1425,6 +1433,9 @@ public ExecutionResult addEvents(HystrixEventType... events) {
14251433
public int getExecutionTime() {
14261434
return executionTime;
14271435
}
1436+
public long getCommandRunStartTimeInNanos() {return commandRunStartTimeInNanos; }
1437+
1438+
14281439

14291440
public Exception getException() {
14301441
return exception;
@@ -1592,6 +1603,16 @@ public int getExecutionTimeInMilliseconds() {
15921603
return executionResult.getExecutionTime();
15931604
}
15941605

1606+
/**
1607+
* Time in Nanos when this command instance's run method was called, or -1 if not executed
1608+
* for e.g., command threw an exception
1609+
*
1610+
* @return long
1611+
*/
1612+
public long getCommandRunStartTimeInNanos() {
1613+
return executionResult.getCommandRunStartTimeInNanos();
1614+
}
1615+
15951616
protected Exception getExceptionFromThrowable(Throwable t) {
15961617
Exception e = null;
15971618
if (t instanceof Exception) {

hystrix-core/src/main/java/com/netflix/hystrix/HystrixInvokableInfo.java

+2
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ public interface HystrixInvokableInfo<R> {
5555

5656
public int getExecutionTimeInMilliseconds();
5757

58+
public long getCommandRunStartTimeInNanos();
59+
5860
}

0 commit comments

Comments
 (0)