热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

com.google.common.base.Stopwatch.stop()方法的使用及代码示例

本文整理了Java中com.google.common.base.Stopwatch.stop()方法的一些代码示例,展示了Stopwatch.stop()

本文整理了Java中com.google.common.base.Stopwatch.stop()方法的一些代码示例,展示了Stopwatch.stop()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stopwatch.stop()方法的具体详情如下:
包路径:com.google.common.base.Stopwatch
类名称:Stopwatch
方法名:stop

Stopwatch.stop介绍

[英]Stops the stopwatch. Future reads will return the fixed duration that had elapsed up to this point.
[中]停止秒表。未来的读取将返回到目前为止经过的固定持续时间。

代码示例

代码示例来源:origin: stackoverflow.com

Stopwatch stopwatch = Stopwatch.createStarted();
myCall();
stopwatch.stop(); // optional
System.out.println("Time elapsed for myCall() is "+ stopwatch.elapsed(MILLISECONDS));

代码示例来源:origin: Graylog2/graylog2-server

@Override
public void retain(String indexName, IndexSet indexSet) {
final Stopwatch sw = Stopwatch.createStarted();
indices.close(indexName);
auditEventSender.success(AuditActor.system(nodeId), ES_INDEX_RETENTION_CLOSE, ImmutableMap.of(
"index_name", indexName,
"retention_strategy", this.getClass().getCanonicalName()
));
LOG.info("Finished index retention strategy [close] for index <{}> in {}ms.", indexName,
sw.stop().elapsed(TimeUnit.MILLISECONDS));
}

代码示例来源:origin: thinkaurelius/titan

@Override
public IDBlock call() {
Stopwatch running = Stopwatch.createStarted();
try {
if (stopRequested) {
log.debug("Aborting ID block retrieval on partition({})-namespace({}) after " +
"graceful shutdown was requested, exec time {}, exec+q time {}",
partition, idNamespace, running.stop(), alive.stop());
throw new TitanException("ID block retrieval aborted by caller");
}
IDBlock idBlock = idAuthority.getIDBlock(partition, idNamespace, renewTimeout);
log.debug("Retrieved ID block from authority on partition({})-namespace({}), " +
"exec time {}, exec+q time {}",
partition, idNamespace, running.stop(), alive.stop());
Preconditions.checkArgument(idBlock!=null && idBlock.numIds()>0);
return idBlock;
} catch (BackendException e) {
throw new TitanException("Could not acquire new ID block from storage", e);
} catch (IDPoolExhaustedException e) {
return ID_POOL_EXHAUSTION;
}
}
}

代码示例来源:origin: MovingBlocks/Terasology

public ChunkMesh generateMesh(ChunkView chunkView, int meshHeight, int verticalOffset) {
PerformanceMonitor.startActivity("GenerateMesh");
ChunkMesh mesh = new ChunkMesh(bufferPool);
final Stopwatch watch = Stopwatch.createStarted();
for (int x = 0; x for (int z = 0; z for (int y = verticalOffset; y Block block = chunkView.getBlock(x, y, z);
if (block != null && block.getMeshGenerator() != null) {
block.getMeshGenerator().generateChunkMesh(chunkView, mesh, x, y, z);
}
}
}
}
watch.stop();
mesh.setTimeToGenerateBlockVertices((int) watch.elapsed(TimeUnit.MILLISECONDS));
watch.reset().start();
generateOptimizedBuffers(chunkView, mesh);
watch.stop();
mesh.setTimeToGenerateOptimizedBuffers((int) watch.elapsed(TimeUnit.MILLISECONDS));
statVertexArrayUpdateCount++;
PerformanceMonitor.endActivity();
return mesh;
}

代码示例来源:origin: kairosdb/kairosdb

@Override
public void run()
{
//System.out.println("DynamicFutureTask.run");
try
{
m_stopwatch.start();
super.run();
m_stopwatch.stop();
m_ingestTimeStats.addValue(m_stopwatch.elapsed(TimeUnit.MICROSECONDS));
}
finally
{
m_semaphore.release();
}
}

代码示例来源:origin: google/guava

public void testStop_alreadyStopped() {
stopwatch.start();
stopwatch.stop();
try {
stopwatch.stop();
fail();
} catch (IllegalStateException expected) {
}
assertFalse(stopwatch.isRunning());
}

代码示例来源:origin: locationtech/geogig

private void benchmarkIteration(Iterator commits) {
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
Stopwatch sw = Stopwatch.createStarted();
sw.reset().start();
int c = 0;
while (commits.hasNext()) {
c++;
commits.next();
}
sw.stop();
System.err.println("Iterated " + numberFormat.format(c) + " commits in " + sw.toString());
}

代码示例来源:origin: apache/kylin

@Override
public void finish(CuboidResult result) {
Stopwatch stopwatch = new Stopwatch().start();
int nRetries = 0;
while (!outputQueue.offer(result)) {
nRetries++;
long sleepTime = stopwatch.elapsedMillis();
if (sleepTime > 3600000L) {
stopwatch.stop();
throw new RuntimeException(
"OutputQueue Full. Cannot offer to the output queue after waiting for one hour!!! Current queue size: "
+ outputQueue.size());
}
logger.warn("OutputQueue Full. Queue size: " + outputQueue.size() + ". Total sleep time : " + sleepTime
+ ", and retry count : " + nRetries);
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
stopwatch.stop();
}
}

代码示例来源:origin: forcedotcom/phoenix

Transaction transaction = null;
List events = Lists.newArrayListWithExpectedSize(this.batchSize);
Stopwatch watch = new Stopwatch().start();
try {
transaction = channel.getTransaction();
logger.error(String.format("Time taken to process [%s] events was [%s] seconds",events.size(),watch.stop().elapsedTime(TimeUnit.SECONDS)));
if( transaction != null ) {
transaction.close();

代码示例来源:origin: Graylog2/graylog2-server

@Override
public void retain(String indexName, IndexSet indexSet) {
final Stopwatch sw = Stopwatch.createStarted();
indices.delete(indexName);
auditEventSender.success(AuditActor.system(nodeId), ES_INDEX_RETENTION_DELETE, ImmutableMap.of(
"index_name", indexName,
"retention_strategy", this.getClass().getCanonicalName()
));
LOG.info("Finished index retention strategy [delete] for index <{}> in {}ms.", indexName,
sw.stop().elapsed(TimeUnit.MILLISECONDS));
}

代码示例来源:origin: twitter/distributedlog

Stopwatch stopwatch = Stopwatch.createStarted();
try {
if (null == lastDLSN) {
reader = FutureUtils.result(dlm.openAsyncLogReader(lastDLSN));
long elapsedMs = stopwatch.elapsed(TimeUnit.MICROSECONDS);
openReaderStats.registerSuccessfulEvent(elapsedMs);
logger.info("It took {} ms to position the reader to transaction id = {}, dlsn = {}",
lastTxId, lastDLSN);
} catch (IOException ioe) {
openReaderStats.registerFailedEvent(stopwatch.elapsed(TimeUnit.MICROSECONDS));
logger.warn("Failed to create reader for stream {} reading from tx id = {}, dlsn = {}.",
new Object[] { streamName, lastTxId, lastDLSN });
while (true) {
try {
stopwatch.start();
records = FutureUtils.result(reader.readBulk(batchSize));
long elapsedMicros = stopwatch.stop().elapsed(TimeUnit.MICROSECONDS);
blockingReadStats.registerSuccessfulEvent(elapsedMicros);
if (!records.isEmpty()) {

代码示例来源:origin: google/guava

public void testElapsed_multipleSegments() {
stopwatch.start();
ticker.advance(9);
stopwatch.stop();
ticker.advance(16);
stopwatch.start();
assertEquals(9, stopwatch.elapsed(NANOSECONDS));
ticker.advance(25);
assertEquals(34, stopwatch.elapsed(NANOSECONDS));
stopwatch.stop();
ticker.advance(36);
assertEquals(34, stopwatch.elapsed(NANOSECONDS));
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public void close() {
stopwatch.stop();
if (stopwatch.elapsed(thresholdUnit) >= threshold) {
log.info("[{}] execution took {} {}", new Object[] {name, stopwatch.elapsed(reportUnit), niceName(reportUnit)});
}
}

代码示例来源:origin: JanusGraph/janusgraph

@Override
public IDBlock call() {
Stopwatch running = Stopwatch.createStarted();
try {
if (stopRequested) {
log.debug("Aborting ID block retrieval on partition({})-namespace({}) after " +
"graceful shutdown was requested, exec time {}, exec+q time {}",
partition, idNamespace, running.stop(), alive.stop());
throw new JanusGraphException("ID block retrieval aborted by caller");
}
IDBlock idBlock = idAuthority.getIDBlock(partition, idNamespace, renewTimeout);
log.debug("Retrieved ID block from authority on partition({})-namespace({}), " +
"exec time {}, exec+q time {}",
partition, idNamespace, running.stop(), alive.stop());
Preconditions.checkArgument(idBlock!=null && idBlock.numIds()>0);
return idBlock;
} catch (BackendException e) {
throw new JanusGraphException("Could not acquire new ID block from storage", e);
} catch (IDPoolExhaustedException e) {
return ID_POOL_EXHAUSTION;
}
}
}

代码示例来源:origin: google/guava

public void testStop() {
stopwatch.start();
assertSame(stopwatch, stopwatch.stop());
assertFalse(stopwatch.isRunning());
}

代码示例来源:origin: apache/kylin

@Test
public void createDirectChildrenCacheStressTest() {
Stopwatch sw = new Stopwatch();
sw.start();
Set cuboidSet = generateMassCuboidSet();
System.out.println("Time elapsed for creating sorted cuboid list: " + sw.elapsedMillis());
sw.reset();
sw.start();
checkDirectChildrenCacheStressTest(CuboidStatsUtil.createDirectChildrenCache(cuboidSet));
System.out.println("Time elapsed for creating direct children cache: " + sw.elapsedMillis());
sw.stop();
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testQueueDeletedRecentlyRetriesWhen60DoesntTry() {
SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class),
createMock(BackoffLimitedRetryHandler.class), ImmutableSet. of(), 60, 100);
HttpCommand command = createHttpCommandForFailureCount(60);
Stopwatch watch = new Stopwatch().start();
assertFalse(retry.shouldRetryRequestOnError(command, response, error));
assertEquals(command.getFailureCount(), 61);
assertTrue(watch.stop().elapsedTime(TimeUnit.MILLISECONDS) <100);
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
protected void shutDown() throws Exception {
for (Periodical periodical : periodicals.getAllStoppedOnGracefulShutdown()) {
LOG.info("Shutting down periodical [{}].", periodical.getClass().getCanonicalName());
Stopwatch s = Stopwatch.createStarted();
// Cancel future executions.
Map futures = periodicals.getFutures();
if (futures.containsKey(periodical)) {
futures.get(periodical).cancel(false);
s.stop();
LOG.info("Shutdown of periodical [{}] complete, took <{}ms>.",
periodical.getClass().getCanonicalName(), s.elapsed(TimeUnit.MILLISECONDS));
} else {
LOG.error("Could not find periodical [{}] in futures list. Not stopping execution.",
periodical.getClass().getCanonicalName());
}
}
}
}

代码示例来源:origin: twitter/distributedlog

Stopwatch stopwatch = Stopwatch.createStarted();
try {
reader = dlm.getInputStream(lastTxId);
long elapsedMs = stopwatch.elapsed(TimeUnit.MICROSECONDS);
openReaderStats.registerSuccessfulEvent(elapsedMs);
logger.info("It took {} ms to position the reader to transaction id {}", lastTxId);
} catch (IOException ioe) {
openReaderStats.registerFailedEvent(stopwatch.elapsed(TimeUnit.MICROSECONDS));
logger.warn("Failed to create reader for stream {} reading from {}.", streamName, lastTxId);
while (true) {
try {
stopwatch.start();
record = reader.readNext(nonBlocking);
if (null != record) {
long elapsedMicros = stopwatch.stop().elapsed(TimeUnit.MICROSECONDS);
if (nonBlocking) {
nonBlockingReadStats.registerSuccessfulEvent(elapsedMicros);

代码示例来源:origin: google/guava

public void testElapsed_notRunning() {
ticker.advance(1);
stopwatch.start();
ticker.advance(4);
stopwatch.stop();
ticker.advance(9);
assertEquals(4, stopwatch.elapsed(NANOSECONDS));
}

推荐阅读
author-avatar
爱他让我心痛_830
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有