From 62400a13a0ab46bee2386ca9f77ff8efba43aaf8 Mon Sep 17 00:00:00 2001 From: Praveen Ramachandra Date: Tue, 16 Dec 2014 10:08:48 -0800 Subject: [PATCH] Added support to get command start time in Nanos --- .../com/netflix/hystrix/AbstractCommand.java | 21 +++++++++++++++++++ .../netflix/hystrix/HystrixInvokableInfo.java | 2 ++ 2 files changed, 23 insertions(+) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java index f59137a7d..139465d41 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java @@ -1383,6 +1383,7 @@ protected static class ExecutionResult { protected final List events; private final int executionTime; private final Exception exception; + private final long commandRunStartTimeInNanos; private ExecutionResult(HystrixEventType... events) { this(Arrays.asList(events), -1, null); @@ -1401,7 +1402,14 @@ private ExecutionResult(List 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 @@ -1425,6 +1433,9 @@ public ExecutionResult addEvents(HystrixEventType... events) { public int getExecutionTime() { return executionTime; } + public long getCommandRunStartTimeInNanos() {return commandRunStartTimeInNanos; } + + public Exception getException() { return exception; @@ -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) { diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixInvokableInfo.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixInvokableInfo.java index b6a1f1f97..99c08f339 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixInvokableInfo.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixInvokableInfo.java @@ -55,4 +55,6 @@ public interface HystrixInvokableInfo { public int getExecutionTimeInMilliseconds(); + public long getCommandRunStartTimeInNanos(); + } \ No newline at end of file