• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Timer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.netflix.spectator.api.Timer的典型用法代码示例。如果您正苦于以下问题:Java Timer类的具体用法?Java Timer怎么用?Java Timer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Timer类属于com.netflix.spectator.api包,在下文中一共展示了Timer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
    }
  }
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:27,代码来源:GcLogger.java


示例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());
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:17,代码来源:DefaultPlaceholderTimerTest.java


示例3: testRecordCallableException

import com.netflix.spectator.api.Timer; //导入依赖的package包/类
@Test
public void testRecordCallableException() throws Exception {
  Timer timer = factory.timer(factory.createId("testRecordCallableException"));
  clock.setMonotonicTime(100L);
  boolean seen = false;
  try {
    timer.record(() -> {
      clock.setMonotonicTime(500L);
      throw new Exception("foo");
    });
  } catch (Exception e) {
    seen = true;
  }
  Assert.assertTrue(seen);
  Assert.assertEquals(1L, timer.count());
  Assert.assertEquals(400L, timer.totalTime());
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:18,代码来源:DefaultPlaceholderTimerTest.java


示例4: 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);
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:19,代码来源:DefaultPlaceholderTimerTest.java


示例5: 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());
    }
  }
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:17,代码来源:DefaultPlaceholderTimerTest.java


示例6: 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);
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:18,代码来源:ServoTimerTest.java


示例7: 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);
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:18,代码来源:ServoTimerTest.java


示例8: 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);
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:18,代码来源:ServoTimerTest.java


示例9: 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);
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:20,代码来源:ServoTimerTest.java


示例10: 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);
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:22,代码来源:ServoTimerTest.java


示例11: 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());
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:21,代码来源:ServoTimerTest.java


示例12: getTimer

import com.netflix.spectator.api.Timer; //导入依赖的package包/类
public static Timer getTimer(String className, String name, String... additionalTags) {
	Map<String, String> tags = toMap(className, additionalTags);
	tags.put("unit", TimeUnit.SECONDS.name());
	return timers.computeIfAbsent(name, s -> new ConcurrentHashMap<>()).computeIfAbsent(tags, t -> {
		Id id = registry.createId(name, tags);
		return PercentileTimer.get(registry, id);
	});
}
 
开发者ID:Netflix,项目名称:conductor,代码行数:9,代码来源:Monitors.java


示例13: 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;
	}
 
开发者ID:Netflix,项目名称:conductor,代码行数:16,代码来源:Monitors.java


示例14: 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);
}
 
开发者ID:Netflix,项目名称:metacat,代码行数:9,代码来源:SNSNotificationMetric.java


示例15: 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


示例16: record

import com.netflix.spectator.api.Timer; //导入依赖的package包/类
private static void record(Timer t) throws Exception {
  long startingCount = t.count();
  long startingTime = t.totalTime();

  t.record(42, TimeUnit.MICROSECONDS);
  t.record(42, TimeUnit.HOURS);
  t.record(Integer.valueOf(42), TimeUnit.SECONDS);
  t.record(Long.valueOf(42), TimeUnit.SECONDS);

  t.record(new Runnable() {
    @Override public void run() {
    }
  });

  final String v = t.record(new Callable<String>() {
    @Override public String call() throws Exception {
      return "foo";
    }
  });
  assert "foo".equals(v);

  t.record(Main::methodToTime);
  assert "bar".equals(t.record(Main::getBar));

  assert t.count() == startingCount + 8;
  assert t.totalTime() == startingTime + 151284000042000L;
}
 
开发者ID:brharrington,项目名称:spectator-examples,代码行数:28,代码来源:Main.java


示例17: meterIsTimer

import com.netflix.spectator.api.Timer; //导入依赖的package包/类
/**
 * Determine if meter is a Timer or not.
 */
public boolean meterIsTimer(Registry registry, Meter meter) {
  return idToTimer.computeIfAbsent(meter.id(), k -> {
      try {
        return registry.timers().anyMatch(m -> m.id().equals(meter.id()));
      } catch (ArrayIndexOutOfBoundsException aoex) {
        // !!! 20160929
        // !!! I dont know if this is a bug or what
        // !!! but the tests all get an array out of bounds calling stream()
        return meter instanceof Timer;
      }
      });
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:16,代码来源:MetricDescriptorCache.java


示例18: 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());
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:12,代码来源:StackdriverWriterTest.java


示例19: testInit

import com.netflix.spectator.api.Timer; //导入依赖的package包/类
@Test
public void testInit() {
  Timer timer = new DefaultPlaceholderTimer(new DefaultPlaceholderId("testInit", registry), registry);

  Assert.assertEquals(0L, timer.count());
  Assert.assertEquals(0L, timer.totalTime());
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:8,代码来源:DefaultPlaceholderTimerTest.java


示例20: 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());
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:8,代码来源:DefaultPlaceholderTimerTest.java



注:本文中的com.netflix.spectator.api.Timer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RestClientException类代码示例发布时间:2022-05-23
下一篇:
Java ILineScatterCandleRadarDataSet类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap