本文整理了Java中com.netflix.servo.monitor.Timer
类的一些代码示例,展示了Timer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timer
类的具体详情如下:
包路径:com.netflix.servo.monitor.Timer
类名称:Timer
[英]Monitor type for tracking how much time something is taking.
[中]监视器类型,用于跟踪某件事情花费的时间。
代码示例来源:origin: Netflix/eureka
public Value(String payload) {
this.payload = payload;
if (!EMPTY_PAYLOAD.equals(payload)) {
Stopwatch tracer = compressPayloadTimer.start();
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GZIPOutputStream out = new GZIPOutputStream(bos);
byte[] rawBytes = payload.getBytes();
out.write(rawBytes);
// Finish creation of gzip file
out.finish();
out.close();
bos.close();
gzipped = bos.toByteArray();
} catch (IOException e) {
gzipped = null;
} finally {
if (tracer != null) {
tracer.stop();
}
}
} else {
gzipped = null;
}
}
代码示例来源:origin: Netflix/servo
/**
* Record a duration to the dynamic timer indicated by the provided config.
* The units in which the timer is reported and the duration unit are the same.
*
* @deprecated Use {@link DynamicTimer#record(MonitorConfig, java.util.concurrent.TimeUnit,
* long, java.util.concurrent.TimeUnit)} instead.
* The new method allows you to be specific about the units used for reporting the timer and
* the units in which the duration is measured.
*/
public static void record(MonitorConfig config, long duration, TimeUnit unit) {
INSTANCE.get(config, unit).record(duration, unit);
}
代码示例来源: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/servo
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public void record(long duration) {
Timer monitor = getMonitorForCurrentContext();
monitor.record(duration, monitor.getTimeUnit());
}
代码示例来源:origin: com.netflix.blitz4j/blitz4j
/** Process the batch. */
public void run() {
try {
if (batch == null) {
return;
}
int inProcess = stream.concurrentBatches.incrementAndGet();
try {
avgConcurrentBatches.record(inProcess);
Stopwatch s = processMessagesTracer.start();
stream.target.process(batch);
s.stop();
} finally {
stream.concurrentBatches.decrementAndGet();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: Netflix/servo
/**
* {@inheritDoc}
*/
@Override
public Long getValue(int pollerIndex) {
return getMonitorForCurrentContext().getValue();
}
}
代码示例来源:origin: Netflix/servo
/**
* {@inheritDoc}
*/
@Override
public TimeUnit getTimeUnit() {
return getMonitorForCurrentContext().getTimeUnit();
}
代码示例来源:origin: com.netflix.servo/servo-core
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public void record(long duration) {
Timer monitor = getMonitorForCurrentContext();
monitor.record(duration, monitor.getTimeUnit());
}
代码示例来源: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: com.netflix.servo/servo-core
/**
* {@inheritDoc}
*/
@Override
public TimeUnit getTimeUnit() {
return getMonitorForCurrentContext().getTimeUnit();
}
代码示例来源:origin: Netflix/servo
/**
* Returns a stopwatch that has been started and will automatically
* record its result to the dynamic timer specified by the given config. The timer
* will report the times in milliseconds to observers.
*
* @see #start(MonitorConfig, TimeUnit)
*/
public static Stopwatch start(MonitorConfig config) {
return INSTANCE.get(config, TimeUnit.MILLISECONDS).start();
}
代码示例来源:origin: Netflix/servo
/**
* {@inheritDoc}
*/
@Override
public void record(long duration, TimeUnit timeUnit) {
getMonitorForCurrentContext().record(duration, timeUnit);
}
代码示例来源: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/servo
/**
* Returns a stopwatch that has been started and will automatically
* record its result to the dynamic timer specified by the given config.
*
* @param config Config to identify a particular timer instance to update.
* @param unit The unit to use when reporting values to observers. For example if sent to
* a typical time series graphing system this would be the unit for the y-axis.
* It is generally recommended to use base units for reporting, so
* {@link TimeUnit#SECONDS} is the preferred value.
*/
public static Stopwatch start(MonitorConfig config, TimeUnit unit) {
return INSTANCE.get(config, unit).start();
}
代码示例来源:origin: Netflix/servo
/**
* Record result to the dynamic timer indicated by the provided config
* with a TimeUnit of milliseconds.
*/
public static void record(MonitorConfig config, long duration) {
INSTANCE.get(config, TimeUnit.MILLISECONDS).record(duration, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: com.netflix.servo/servo-core
/**
* {@inheritDoc}
*/
@Override
public Long getValue(int pollerIndex) {
return getMonitorForCurrentContext().getValue();
}
}
代码示例来源:origin: Netflix/eureka
@Override
protected BasicPoolEntry getEntryBlocking(HttpRoute route, Object state,
long timeout, TimeUnit tunit, WaitingThreadAborter aborter)
throws ConnectionPoolTimeoutException, InterruptedException {
Stopwatch stopWatch = requestTimer.start();
try {
return super.getEntryBlocking(route, state, timeout, tunit, aborter);
} finally {
stopWatch.stop();
}
}
代码示例来源:origin: Netflix/servo
/**
* Record a duration to the dynamic timer indicated by the provided config/reportUnit.
*
* @param config Config to identify a particular timer instance to update.
* @param reportUnit The unit to use when reporting values to observers. For example if sent to
* a typical time series graphing system this would be the unit
* for the y-axis.
* It is generally recommended to use base units for reporting, so
* {@link TimeUnit#SECONDS} is the preferred value.
* @param duration Measured duration to record.
* @param durationUnit Unit for the measured duration. This should typically be the unit used for
* timing source. For example if using {@link System#nanoTime()}
* the unit would be nanoseconds.
*/
public static void record(MonitorConfig config, TimeUnit reportUnit, long duration,
TimeUnit durationUnit) {
INSTANCE.get(config, reportUnit).record(duration, durationUnit);
}
代码示例来源:origin: Netflix/servo
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// if the method is one of the CompositeMonitor interface
final Class<?> declaringClass = method.getDeclaringClass();
if (declaringClass.isAssignableFrom(CompositeMonitor.class)) {
return method.invoke(this, args);
}
final String methodName = method.getName();
final Timer timer = timers.get(methodName);
final Stopwatch stopwatch = timer.start();
try {
return method.invoke(concrete, args);
} finally {
stopwatch.stop();
}
}
}
代码示例来源:origin: Netflix/servo
/**
* {@inheritDoc}
*/
@Override
public void stop() {
super.stop();
timer.record(getDuration(), TimeUnit.NANOSECONDS);
}
}
内容来源于网络,如有侵权,请联系作者删除!