本文整理了Java中com.netflix.servo.monitor.Stopwatch.getDuration()
方法的一些代码示例,展示了Stopwatch.getDuration()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stopwatch.getDuration()
方法的具体详情如下:
包路径:com.netflix.servo.monitor.Stopwatch
类名称:Stopwatch
方法名:getDuration
[英]Returns the duration in nanoseconds.
[中]以纳秒为单位返回持续时间。
代码示例来源:origin: Netflix/zuul
@Override
public void stopAndLog() {
DynamicTimer.record(config, stopwatch.getDuration());
}
代码示例来源:origin: Netflix/zuul
@Override
public void stopAndLog() {
DynamicTimer.record(config, stopwatch.getDuration());
}
代码示例来源:origin: Netflix/EVCache
public long incr(String key, long by, long def, int exp) {
final Stopwatch operationDuration = getTimer(INCR_OPERATION_STRING).start();
long val = 0;
try {
val = mutate(Mutator.incr, key, by, def, exp);
} finally {
operationDuration.stop();
if (log.isDebugEnabled()) log.debug("Increment Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp
+ "; val : " + val + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS));
}
return val;
}
代码示例来源:origin: Netflix/EVCache
public long decr(String key, long by, long def, int exp) {
final Stopwatch operationDuration = getTimer(DECR_OPERATION_STRING).start();
long val = 0;
try {
val = super.decr(key, by, def, exp);
} finally {
operationDuration.stop();
if (log.isDebugEnabled()) log.debug("decrement Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp
+ "; val : " + val + "; Elapsed Time - " + (operationDuration.getDuration(TimeUnit.MILLISECONDS)));
}
return val;
}
代码示例来源:origin: Netflix/servo
@Test
public void testGetValue() throws Exception {
Stopwatch s = DynamicTimer.start("test1", tagList);
Timer c = getByName("test1");
s.stop();
// we don't call s.stop(), so we only have one recorded value
assert c != null;
assertEquals(c.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS));
c.record(13, TimeUnit.MILLISECONDS);
long expected = (13 + s.getDuration(TimeUnit.MILLISECONDS)) / 2;
assertEquals(c.getValue().longValue(), expected);
}
代码示例来源:origin: Netflix/EVCache
@Override
public void receivedStatus(OperationStatus val) {
if (val.getStatusCode().equals(StatusCode.SUCCESS)) {
if (log.isDebugEnabled()) log.debug("AddOrAppend Key (Append Operation): " + key + "; Status : " + val.getStatusCode().name()
+ "; Message : " + val.getMessage() + "; Elapsed Time - " + (operationDuration.getDuration(TimeUnit.MILLISECONDS)));
getCounter(AOA_APPEND_OPERATION_SUCCESS_STRING).increment();
rv.set(Boolean.TRUE, val);
appendSuccess = true;
} else {
getCounter("AoA-AppendOperation-"+ val.getStatusCode().name()).increment();
}
}
代码示例来源:origin: Netflix/servo
@Test
public void testByStrings() throws Exception {
Stopwatch s = DynamicTimer.start("byName");
Stopwatch s2 = DynamicTimer.start("byName2", "key", "value");
Thread.sleep(100L);
s.stop();
s2.stop();
Timer c1 = getByName("byName");
assert c1 != null;
assertEquals(c1.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS));
Timer c2 = getByName("byName2");
assert c2 != null;
assertEquals(c2.getValue().longValue(), s2.getDuration(TimeUnit.MILLISECONDS));
}
}
代码示例来源:origin: Netflix/EVCache
@Override
@SuppressWarnings("synthetic-access")
public void receivedStatus(OperationStatus status) {
operationDuration.stop();
if (log.isDebugEnabled()) log.debug("GetBulk Keys : " + keys + "; Status : " + status.getStatusCode().name()
+ "; Message : " + status.getMessage() + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS));
if (status.getStatusCode().equals(StatusCode.SUCCESS)) {
getCounter(BULK_OPERATION_STRING + "-SUCCESS").increment();
} else {
getCounter(BULK_OPERATION_STRING + "-" + status.getStatusCode().name()).increment();//First lets get some data and then we can add Host info
}
rv.setStatus(status);
}
代码示例来源:origin: Netflix/EVCache
@Override
public void receivedStatus(OperationStatus val) {
operationDuration.stop();
if (log.isDebugEnabled()) log.debug("Storing Key : " + key + "; Status : " + val.getStatusCode().name()
+ (log.isTraceEnabled() ? " Node : " + getEVCacheNode(key) : "")
+ "; Message : " + val.getMessage() + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS));
if (val.getStatusCode().equals(StatusCode.SUCCESS)) {
getCounter(operationSuccessStr).increment();
} else {
if (val.getStatusCode().equals(StatusCode.TIMEDOUT)) {
final MemcachedNode node = getEVCacheNode(key);
if(node instanceof EVCacheNodeImpl) {
if (log.isInfoEnabled()) log.info(val.getStatusCode().name() + " Storing Key : " + key + "; Status : " + val.getStatusCode().name()
+ "; Node : " + node + "; Message : " + val.getMessage() + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS), new Exception());
if(node instanceof EVCacheNodeImpl) {
getCounter(operationStr + "-" + val.getStatusCode().name(), ((EVCacheNodeImpl)node).getBaseTags()).increment();
} else {
getCounter(operationStr + "-" + val.getStatusCode().name(), BasicTagList.of("HOST", node.getSocketAddress().toString())).increment();
}
}
} else {
getCounter(operationStr + "-" + val.getStatusCode().name()).increment();
}
}
rv.set(val.isSuccess(), val);
}
代码示例来源:origin: Netflix/EVCache
public void receivedStatus(OperationStatus status) {
operationDuration .stop();
if (log.isDebugEnabled()) log.debug("Getting Key : " + key + "; Status : " + status.getStatusCode().name()
+ (log.isTraceEnabled() ? " Node : " + getEVCacheNode(key) : "")
+ "; Message : " + status.getMessage() + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS));
if (status.getStatusCode().equals(StatusCode.SUCCESS)) {
getCounter(GET_OPERATION_STRING + "-SUCCESS").increment();
} else {
if (status.getStatusCode().equals(StatusCode.TIMEDOUT)) {
final MemcachedNode node = getEVCacheNode(key);
if(node instanceof EVCacheNodeImpl) {
getCounter(GET_OPERATION_STRING + "-" + status.getStatusCode().name(), ((EVCacheNodeImpl)node).getBaseTags()).increment();
} else {
getCounter(GET_OPERATION_STRING + "-"+ status.getStatusCode().name(), BasicTagList.of("HOST", node.getSocketAddress().toString())).increment();
}
} else {
getCounter(GET_OPERATION_STRING + "-"+ status.getStatusCode().name()).increment();
}
}
try {
if (val != null) {
rv.set(val.get(), status);
} else {
rv.set(null, status);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
rv.set(null, status);
}
}
代码示例来源:origin: Netflix/servo
@Test
public void testExpiration() throws Exception {
clock.set(0L);
DynamicTimer.start("test1", tagList);
DynamicTimer.start("test2", tagList);
clock.set(500L);
DynamicTimer.start("test1", tagList);
clock.set(1000L);
Stopwatch s = DynamicTimer.start("test1", tagList);
clock.set(1200L);
s.stop();
Timer c1 = getByName("test1");
assert c1 != null;
assertEquals(c1.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS));
Thread.sleep(200L);
Timer c2 = getByName("test2");
assertNull(c2, "Timers not used in a while should expire");
}
代码示例来源:origin: Netflix/EVCache
public void receivedStatus(OperationStatus status) {
operationDuration.stop();
if (log.isDebugEnabled()) log.debug("GetAndTouch Key : " + key + "; Status : " + status.getStatusCode().name()
+ (log.isTraceEnabled() ? " Node : " + getEVCacheNode(key) : "")
+ "; Message : " + status.getMessage() + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS));
if (status.getStatusCode().equals(StatusCode.SUCCESS)) {
getCounter(GET_AND_TOUCH_OPERATION_STRING + "-SUCCESS").increment();
} else {
if (status.getStatusCode().equals(StatusCode.TIMEDOUT)) {
final MemcachedNode node = getEVCacheNode(key);
if(node instanceof EVCacheNodeImpl) {
getCounter(GET_AND_TOUCH_OPERATION_STRING + "-" + status.getStatusCode().name(), ((EVCacheNodeImpl)node).getBaseTags()).increment();
} else {
getCounter(GET_AND_TOUCH_OPERATION_STRING + "-"+ status.getStatusCode().name(), BasicTagList.of("HOST", node.getSocketAddress().toString())).increment();
}
} else {
getCounter(GET_AND_TOUCH_OPERATION_STRING + "-"+ status.getStatusCode().name()).increment();
}
}
rv.set(val, status);
}
代码示例来源:origin: Netflix/servo
@Test
public void testTimer() throws Exception {
ManualClock clock = new ManualClock(0);
DurationTimer timer = new DurationTimer(MonitorConfig.builder("test").build(), clock);
Stopwatch s = timer.start();
clock.set(10 * 1000L);
assertEquals(10, s.getDuration());
Monitor<Long> duration = getDuration(timer.getMonitors());
Monitor<Long> activeTasks = getActiveTasks(timer.getMonitors());
assertEquals(10L, duration.getValue().longValue());
assertEquals(1L, activeTasks.getValue().longValue());
clock.set(20 * 1000L);
assertEquals(20L, duration.getValue().longValue());
assertEquals(1L, activeTasks.getValue().longValue());
Stopwatch anotherTask = timer.start();
assertEquals(20L, duration.getValue().longValue());
assertEquals(2L, activeTasks.getValue().longValue());
clock.set(30 * 1000L);
assertEquals(40L, duration.getValue().longValue()); // 30s for the first, 10s for the second
assertEquals(2L, activeTasks.getValue().longValue());
s.stop();
assertEquals(10L, duration.getValue().longValue()); // 30s for the first, 10s for the second
assertEquals(1L, activeTasks.getValue().longValue());
anotherTask.stop();
assertEquals(0L, duration.getValue().longValue());
assertEquals(0L, activeTasks.getValue().longValue());
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@Override
public void stopAndLog() {
DynamicTimer.record(config, stopwatch.getDuration());
}
代码示例来源:origin: com.netflix.zuul/zuul-core
@Override
public void stopAndLog() {
DynamicTimer.record(config, stopwatch.getDuration());
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-netflix-ribbon
protected void recordStats(Object entity, Throwable exception) {
if (this.tracer != null && this.serverStats != null) {
this.tracer.stop();
long duration = this.tracer.getDuration(TimeUnit.MILLISECONDS);
this.context.noteRequestCompletion(serverStats, entity, exception, duration, null/* errorHandler */);
}
}
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
stats = new PrimeConnectionEndStats(totalCount, successCount.get(), failureCount.get(), stopWatch.getDuration(TimeUnit.MILLISECONDS));
内容来源于网络,如有侵权,请联系作者删除!