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

x33g5p2x  于2022-01-29 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(150)

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

Stopwatch.elapsed介绍

[英]Returns the current elapsed time shown on this stopwatch as a Duration. Unlike #elapsed(TimeUnit), this method does not lose any precision due to rounding.
[中]返回此秒表上显示的当前已用时间作为持续时间。与#已用时间(时间单位)不同,这种方法不会因为舍入而失去任何精度。

代码示例

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

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

代码示例来源:origin: alibaba/nacos

@Override
  public void run() {
    LOGGER.info("[capacityManagement] start correct usage");
    Stopwatch stopwatch = Stopwatch.createStarted();
    correctUsage();
    LOGGER.info("[capacityManagement] end correct usage, cost: {}s", stopwatch.elapsed(TimeUnit.SECONDS));
  }
}, PropertyUtil.getCorrectUsageDelay(), PropertyUtil.getCorrectUsageDelay(), TimeUnit.SECONDS);

代码示例来源: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: apache/geode

@Override
public Void call() throws Exception {
 Stopwatch timeRun = duration != DEFAULT_DURATION ? Stopwatch.createStarted() : null;
 int numRuns = 0;
 do {
  numRuns++;
  callAndValidate();
 } while ((iterations != DEFAULT_ITERATIONS && numRuns < iterations) ||
   (duration != DEFAULT_DURATION
     && timeRun.elapsed(SECONDS) <= duration.getSeconds()));
 return null;
}

代码示例来源: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: 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: twitter/distributedlog

@Override
public byte[] compress(byte[] data, int offset, int length, OpStatsLogger compressionStat) {
  Preconditions.checkNotNull(data);
  Preconditions.checkArgument(offset >= 0 && offset < data.length);
  Preconditions.checkArgument(length >= 0);
  Preconditions.checkNotNull(compressionStat);
  Stopwatch watch = Stopwatch.createStarted();
  byte[] compressed = compressor.compress(data, offset, length);
  compressionStat.registerSuccessfulEvent(watch.elapsed(TimeUnit.MICROSECONDS));
  return compressed;
}

代码示例来源: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<Periodical,ScheduledFuture> 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

void fail(SocketAddress address, Throwable t) {
  stopwatch.stop();
  opStats.failRequest(address,
      stopwatch.elapsed(TimeUnit.MICROSECONDS), tries.get());
}

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

@Override
  public T apply() {
    taskPendingTime.registerSuccessfulEvent(pendingStopwatch.elapsed(TimeUnit.MICROSECONDS));
    Stopwatch executionStopwatch = Stopwatch.createStarted();
    T result = function0.apply();
    taskExecutionTime.registerSuccessfulEvent(executionStopwatch.elapsed(TimeUnit.MICROSECONDS));
    long elapsed = executionStopwatch.elapsed(TimeUnit.MICROSECONDS);
    if (elapsed > traceTaskExecutionWarnTimeUs) {
      LOG.info("{} took too long {} microseconds", function0.toString(), elapsed);
    }
    return result;
  }
}

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

void complete() {
    if (LOG.isTraceEnabled()) {
      LOG.trace("{} : Satisfied promise with {} records", bkLedgerManager.getFullyQualifiedName(), records.size());
    }
    delayUntilPromiseSatisfied.registerSuccessfulEvent(enqueueTime.stop().elapsed(TimeUnit.MICROSECONDS));
    Stopwatch stopwatch = Stopwatch.createStarted();
    promise.setValue(records);
    futureSetLatency.registerSuccessfulEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
  }
}

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

@Override
public void onSuccess(ZKDistributedLock lock) {
  acquireStats.registerSuccessfulEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
}
@Override

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

@Override
  // length parameter is ignored here because of the way the fastDecompressor works.
  public byte[] decompress(byte[] data, int offset, int length, int decompressedSize,
               OpStatsLogger decompressionStat) {
    Preconditions.checkNotNull(data);
    Preconditions.checkArgument(offset >= 0 && offset < data.length);
    Preconditions.checkArgument(length >= 0);
    Preconditions.checkArgument(decompressedSize >= 0);
    Preconditions.checkNotNull(decompressionStat);

    Stopwatch watch = Stopwatch.createStarted();
    byte[] decompressed = fastDecompressor.decompress(data, offset, decompressedSize);
    decompressionStat.registerSuccessfulEvent(watch.elapsed(TimeUnit.MICROSECONDS));
    return decompressed;
  }
}

代码示例来源:origin: apache/incubator-druid

@Override
public void persist(final Committer committer)
{
 final Stopwatch runExecStopwatch = Stopwatch.createStarted();
 appenderator.persistAll(committer);
 final long startDelay = runExecStopwatch.elapsed(TimeUnit.MILLISECONDS);
 metrics.incrementPersistBackPressureMillis(startDelay);
 if (startDelay > WARN_DELAY) {
  log.warn("Ingestion was throttled for [%,d] millis because persists were pending.", startDelay);
 }
 runExecStopwatch.stop();
}

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

void complete(SocketAddress address) {
  stopwatch.stop();
  opStats.completeRequest(address,
      stopwatch.elapsed(TimeUnit.MICROSECONDS), tries.get());
}

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

public void apply(Request request) throws OverCapacityException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
      for (RequestLimiter<Request> limiter : limiters) {
        limiter.apply(request);
      }
    } finally {
      applyTime.registerSuccessfulEvent(stopwatch.elapsed(TimeUnit.MICROSECONDS));
    }
  }
}

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

void setException(Throwable throwable) {
  Stopwatch stopwatch = Stopwatch.createStarted();
  if (promise.updateIfEmpty(new Throw<List<LogRecordWithDLSN>>(throwable))) {
    futureSetLatency.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
    delayUntilPromiseSatisfied.registerFailedEvent(enqueueTime.elapsed(TimeUnit.MICROSECONDS));
  }
}

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

@Override
  public void onFailure(Throwable cause) {
    truncationStat.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
    LOG.error("Failed to truncate stream {} to {} : ",
        new Object[]{streamName, dlsnToTruncate, cause});
  }
});

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

@Override
public byte[] decompress(byte[] data, int offset, int length, OpStatsLogger decompressionStat) {
  Preconditions.checkNotNull(data);
  Preconditions.checkArgument(offset >= 0 && offset < data.length);
  Preconditions.checkArgument(length >= 0);
  Preconditions.checkNotNull(decompressionStat);
  Stopwatch watch = Stopwatch.createStarted();
  // Assume that we have a compression ratio of 1/3.
  int outLength = length * 3;
  while (true) {
    try {
      byte[] decompressed = safeDecompressor.decompress(data, offset, length, outLength);
      decompressionStat.registerSuccessfulEvent(watch.elapsed(TimeUnit.MICROSECONDS));
      return decompressed;
    } catch (LZ4Exception e) {
      outLength *= 2;
    }
  }
}

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

checkNotNull(loader);
checkNotNull(keys);
Stopwatch stopwatch = Stopwatch.createStarted();
Map<K, V> result;
boolean success = false;
} finally {
 if (!success) {
  globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS));
 globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS));
 throw new InvalidCacheLoadException(loader + " returned null map from loadAll");
stopwatch.stop();
 globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS));
 throw new InvalidCacheLoadException(loader + " returned null keys or values from loadAll");
globalStatsCounter.recordLoadSuccess(stopwatch.elapsed(NANOSECONDS));
return result;

相关文章