本文整理汇总了Java中io.micrometer.core.instrument.Timer.record方法的典型用法代码示例。如果您正苦于以下问题:Java Timer.record方法的具体用法?Java Timer.record怎么用?Java Timer.record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.micrometer.core.instrument.Timer
的用法示例。
在下文中一共展示了Timer.record方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: record
import io.micrometer.core.instrument.Timer; //导入方法依赖的package包/类
@Test
@DisplayName("total time and count are preserved for a single timing")
default void record(MeterRegistry registry) {
Timer t = registry.timer("myTimer");
t.record(42, TimeUnit.MILLISECONDS);
clock(registry).add(step());
assertAll(() -> assertEquals(1L, t.count()),
() -> assertEquals(42, t.totalTime(TimeUnit.MILLISECONDS), 1.0e-12));
}
示例2: recordDuration
import io.micrometer.core.instrument.Timer; //导入方法依赖的package包/类
@Test
@DisplayName("record durations")
default void recordDuration(MeterRegistry registry) {
Timer t = registry.timer("myTimer");
t.record(Duration.ofMillis(42));
clock(registry).add(step());
assertAll(() -> assertEquals(1L, t.count()),
() -> assertEquals(42, t.totalTime(TimeUnit.MILLISECONDS), 1.0e-12));
}
示例3: recordNegative
import io.micrometer.core.instrument.Timer; //导入方法依赖的package包/类
@Test
@DisplayName("negative times are discarded by the Timer")
default void recordNegative(MeterRegistry registry) {
Timer t = registry.timer("myTimer");
t.record(-42, TimeUnit.MILLISECONDS);
assertAll(() -> assertEquals(0L, t.count()),
() -> assertEquals(0, t.totalTime(TimeUnit.NANOSECONDS), 1.0e-12));
}
示例4: recordZero
import io.micrometer.core.instrument.Timer; //导入方法依赖的package包/类
@Test
@DisplayName("zero times contribute to the count of overall events but do not add to total time")
default void recordZero(MeterRegistry registry) {
Timer t = registry.timer("myTimer");
t.record(0, TimeUnit.MILLISECONDS);
clock(registry).add(step());
assertAll(() -> assertEquals(1L, t.count()),
() -> assertEquals(0L, t.totalTime(TimeUnit.NANOSECONDS)));
}
示例5: recordWithRunnable
import io.micrometer.core.instrument.Timer; //导入方法依赖的package包/类
@Test
@DisplayName("record a runnable task")
default void recordWithRunnable(MeterRegistry registry) throws Exception {
Timer t = registry.timer("myTimer");
try {
t.record(() -> clock(registry).add(10, TimeUnit.NANOSECONDS));
clock(registry).add(step());
} finally {
assertAll(() -> assertEquals(1L, t.count()),
() -> assertEquals(10, t.totalTime(TimeUnit.NANOSECONDS) ,1.0e-12));
}
}
示例6: recordMax
import io.micrometer.core.instrument.Timer; //导入方法依赖的package包/类
@Test
default void recordMax(MeterRegistry registry) {
Timer timer = registry.timer("my.timer");
timer.record(10, TimeUnit.MILLISECONDS);
timer.record(1, TimeUnit.SECONDS);
clock(registry).add(step()); // for Atlas, which is step rather than ring-buffer based
assertThat(timer.max(TimeUnit.SECONDS)).isEqualTo(1);
assertThat(timer.max(TimeUnit.MILLISECONDS)).isEqualTo(1000);
clock(registry).add(Duration.ofMillis(step().toMillis() * HistogramConfig.DEFAULT.getHistogramBufferLength()));
assertThat(timer.max(TimeUnit.SECONDS)).isEqualTo(0);
}
示例7: recordThrowable
import io.micrometer.core.instrument.Timer; //导入方法依赖的package包/类
private Object recordThrowable(Timer timer, ThrowableCallable f) throws Throwable {
long start = registry.config().clock().monotonicTime();
try {
return f.call();
} finally {
timer.record(registry.config().clock().monotonicTime() - start, TimeUnit.NANOSECONDS);
}
}
示例8: timerMax
import io.micrometer.core.instrument.Timer; //导入方法依赖的package包/类
@Test
void timerMax() {
AtlasConfig atlasConfig = k -> null;
AtlasMeterRegistry registry = new AtlasMeterRegistry(atlasConfig, new MockClock());
Timer timer = registry.timer("timer");
timer.record(1, TimeUnit.SECONDS);
clock(registry).add(atlasConfig.step());
assertThat(timer.max(TimeUnit.MILLISECONDS)).isEqualTo(1000);
}