本文整理汇总了Java中com.netflix.spectator.api.Timer.record方法的典型用法代码示例。如果您正苦于以下问题:Java Timer.record方法的具体用法?Java Timer.record怎么用?Java Timer.record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.spectator.api.Timer
的用法示例。
在下文中一共展示了Timer.record方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processGcEvent
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
private void processGcEvent(GarbageCollectionNotificationInfo info) {
GcEvent event = new GcEvent(info, jvmStartTime + info.getGcInfo().getStartTime());
gcLogs.get(info.getGcName()).add(event);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(event.toString());
}
// Update pause timer for the action and cause...
Id eventId = (isConcurrentPhase(info) ? CONCURRENT_PHASE_TIME : PAUSE_TIME)
.withTag("action", info.getGcAction())
.withTag("cause", info.getGcCause());
Timer timer = Spectator.globalRegistry().timer(eventId);
timer.record(info.getGcInfo().getDuration(), TimeUnit.MILLISECONDS);
// Update promotion and allocation counters
updateMetrics(info.getGcName(), info.getGcInfo());
// Notify an event listener if registered
if (eventListener != null) {
try {
eventListener.onComplete(event);
} catch (Exception e) {
LOGGER.warn("exception thrown by event listener", e);
}
}
}
示例2: testRecord
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void testRecord() {
String[] tagValue = new String[] { "default" };
Timer timer = factory.timer(factory.createId("testRecord",
Collections.singleton(new TestTagFactory(tagValue))));
timer.record(42, TimeUnit.MILLISECONDS);
Assert.assertEquals("testRecord:tag=default", timer.id().toString());
Assert.assertEquals(timer.count(), 1L);
Assert.assertEquals(42000000L, timer.totalTime());
tagValue[0] = "value2";
Assert.assertEquals("testRecord:tag=value2", timer.id().toString());
Assert.assertEquals(0L, timer.count());
Assert.assertEquals(0L, timer.totalTime());
}
示例3: expiration
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void expiration() {
final long initTime = TimeUnit.MINUTES.toMillis(30);
final long fifteenMinutes = TimeUnit.MINUTES.toMillis(15);
// Expired on init, wait for activity to mark as active
clock.setWallTime(initTime);
Timer t = newTimer("foo");
Assert.assertTrue(t.hasExpired());
t.record(1, TimeUnit.SECONDS);
Assert.assertFalse(t.hasExpired());
// Expires with inactivity
clock.setWallTime(initTime + fifteenMinutes + 1);
Assert.assertTrue(t.hasExpired());
// Activity brings it back
t.record(42, TimeUnit.SECONDS);
Assert.assertFalse(t.hasExpired());
}
示例4: totalOfSquaresManyBigValues
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void totalOfSquaresManyBigValues() {
Timer t = newTimer("foo");
BigInteger sumOfSq = new BigInteger("0");
for (int i = 0; i < 100000; ++i) {
final long nanos = TimeUnit.SECONDS.toNanos(i);
final BigInteger s = new BigInteger("" + nanos);
final BigInteger s2 = s.multiply(s);
sumOfSq = sumOfSq.add(s2);
t.record(i, TimeUnit.SECONDS);
}
clock.setWallTime(61000L);
final double v = Utils.first(t.measure(), Statistic.totalOfSquares).value();
// Expected :3.3332833335E14
// Actual :3.3332833334999825E14
final double factor = 1e9 * 1e9;
sumOfSq = sumOfSq.divide(BigInteger.valueOf(60));
Assert.assertEquals(sumOfSq.doubleValue() / factor, v, 2.0);
}
示例5: testRecordRunnableException
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void testRecordRunnableException() throws Exception {
Timer timer = factory.timer(factory.createId("testRecordRunnableException"));
clock.setMonotonicTime(100L);
Exception expectedExc = new RuntimeException("foo");
Exception actualExc = null;
try {
timer.record(() -> {
clock.setMonotonicTime(500L);
throw expectedExc;
});
} catch (Exception e) {
actualExc = e;
}
Assert.assertSame(expectedExc, actualExc);
Assert.assertEquals(1L, timer.count());
Assert.assertEquals(timer.totalTime(), 400L);
}
示例6: testMeasure
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void testMeasure() {
Timer timer = factory.timer(factory.createId("testMeasure"));
timer.record(42, TimeUnit.MILLISECONDS);
clock.setWallTime(3712345L);
for (Measurement m : timer.measure()) {
Assert.assertEquals(m.timestamp(), 3712345L);
if (m.id().equals(timer.id().withTag(Statistic.count))) {
Assert.assertEquals(1.0, m.value(), 0.1e-12);
} else if (m.id().equals(timer.id().withTag(Statistic.totalTime))) {
Assert.assertEquals(42e6, m.value(), 0.1e-12);
} else {
Assert.fail("unexpected id: " + m.id());
}
}
}
示例7: testRecordCallableException
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void testRecordCallableException() throws Exception {
Timer t = newTimer("foo");
clock.setMonotonicTime(100L);
boolean seen = false;
try {
t.record((Callable<Integer>) () -> {
clock.setMonotonicTime(500L);
throw new RuntimeException("foo");
});
} catch (Exception e) {
seen = true;
}
Assert.assertTrue(seen);
Assert.assertEquals(t.count(), 1L);
Assert.assertEquals(t.totalTime(), 400L);
}
示例8: testRecordRunnableException
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void testRecordRunnableException() throws Exception {
Timer t = newTimer("foo");
clock.setMonotonicTime(100L);
boolean seen = false;
try {
t.record((Runnable) () -> {
clock.setMonotonicTime(500L);
throw new RuntimeException("foo");
});
} catch (Exception e) {
seen = true;
}
Assert.assertTrue(seen);
Assert.assertEquals(t.count(), 1L);
Assert.assertEquals(t.totalTime(), 400L);
}
示例9: totalOfSquaresOverflow
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void totalOfSquaresOverflow() {
final long seconds = 10;
final long nanos = TimeUnit.SECONDS.toNanos(seconds);
final BigInteger s = new BigInteger("" + nanos);
final BigInteger s2 = s.multiply(s);
Timer t = newTimer("foo");
t.record(seconds, TimeUnit.SECONDS);
clock.setWallTime(61000L);
final double v = Utils.first(t.measure(), Statistic.totalOfSquares).value();
final double factor = 1e9 * 1e9;
final BigInteger perSec = s2.divide(BigInteger.valueOf(60));
Assert.assertEquals(perSec.doubleValue() / factor, v, 1e-12);
}
示例10: totalOfSquaresManySmallValues
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void totalOfSquaresManySmallValues() {
Timer t = newTimer("foo");
BigInteger sumOfSq = new BigInteger("0");
for (int i = 0; i < 100000; ++i) {
final long nanos = i;
final BigInteger s = new BigInteger("" + nanos);
final BigInteger s2 = s.multiply(s);
sumOfSq = sumOfSq.add(s2);
t.record(i, TimeUnit.NANOSECONDS);
}
clock.setWallTime(61000L);
final double v = Utils.first(t.measure(), Statistic.totalOfSquares).value();
final double factor = 1e9 * 1e9;
sumOfSq = sumOfSq.divide(BigInteger.valueOf(60));
Assert.assertEquals(sumOfSq.doubleValue() / factor, v, 1e-12);
}
示例11: start
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
private static Stopwatch start(Timer sm) {
Stopwatch sw = new BasicStopwatch() {
@Override
public void stop() {
super.stop();
long duration = getDuration(TimeUnit.MILLISECONDS);
sm.record(duration, TimeUnit.MILLISECONDS);
}
};
sw.start();
return sw;
}
示例12: recordTime
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
void recordTime(final SNSMessage<?> message, final String timeName) {
final Timer timer = this.registry.timer(
timeName,
Metrics.TagEventsType.getMetricName(),
message.getClass().getName()
);
timer.record(this.registry.clock().wallTime() - message.getTimestamp(), TimeUnit.MILLISECONDS);
}
示例13: metricsAreSentToAtlasPeriodically
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void metricsAreSentToAtlasPeriodically() throws InterruptedException {
Timer t = registry.timer("t");
for (int i = 0; i < 1000; i++)
t.record(100, TimeUnit.MILLISECONDS);
Thread.sleep(1500);
Mockito.verify(exporter, Mockito.atLeastOnce()).export();
}
开发者ID:netflix-spring-one,项目名称:spring-cloud-netflix-contrib,代码行数:11,代码来源:AtlasAutoConfigurationIntegrationTests.java
示例14: writeRegistryWithTimer
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void writeRegistryWithTimer() throws IOException {
DefaultRegistry testRegistry = new DefaultRegistry(clock);
Timer timer = testRegistry.timer(idAXY);
timer.record(123, TimeUnit.MILLISECONDS);
// If we get the expected result then we matched the expected descriptors,
// which means the transforms occurred as expected.
List<TimeSeries> tsList = writer.registryToTimeSeries(testRegistry);
Assert.assertEquals(2, tsList.size());
}
示例15: testRecordNegative
import com.netflix.spectator.api.Timer; //导入方法依赖的package包/类
@Test
public void testRecordNegative() {
Timer timer = factory.timer(factory.createId("testRecordNegative"));
timer.record(-42, TimeUnit.MILLISECONDS);
Assert.assertEquals(timer.count(), 0L);
Assert.assertEquals(0L, timer.totalTime());
}