io.opencensus.common.Timestamp.subtractTimestamp()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(113)

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

Timestamp.subtractTimestamp介绍

[英]Returns a Duration calculated as: this - timestamp.
[中]返回计算为:this-timestamp的持续时间。

代码示例

代码示例来源:origin: census-instrumentation/opencensus-java

private static long toMillis(Timestamp start, Timestamp end) {
 Duration duration = end.subtractTimestamp(start);
 return SECONDS.toMillis(duration.getSeconds()) + NANOSECONDS.toMillis(duration.getNanos());
}

代码示例来源:origin: io.opencensus/opencensus-impl-core

double getFraction(Timestamp now) {
 Duration elapsedTime = now.subtractTimestamp(start);
 checkArgument(
   elapsedTime.compareTo(ZERO) >= 0 && elapsedTime.compareTo(duration) < 0,
   "This bucket must be current.");
 return ((double) elapsedTime.toMillis()) / duration.toMillis();
}

代码示例来源:origin: census-instrumentation/opencensus-java

double getFraction(Timestamp now) {
 Duration elapsedTime = now.subtractTimestamp(start);
 checkArgument(
   elapsedTime.compareTo(ZERO) >= 0 && elapsedTime.compareTo(duration) < 0,
   "This bucket must be current.");
 return ((double) elapsedTime.toMillis()) / duration.toMillis();
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static double getDurationInSecs(
  ViewData.AggregationWindowData.CumulativeData cumulativeData) {
 return toDoubleSeconds(cumulativeData.getEnd().subtractTimestamp(cumulativeData.getStart()));
}

代码示例来源:origin: census-instrumentation/opencensus-java

private void refreshBucketList(Timestamp now) {
 if (buckets.size() != N + 1) {
  throw new AssertionError("Bucket list must have exactly " + (N + 1) + " buckets.");
 }
 Timestamp startOfLastBucket =
   CheckerFrameworkUtils.castNonNull(buckets.peekLast()).getStart();
 // TODO(songya): decide what to do when time goes backwards
 checkArgument(
   now.compareTo(startOfLastBucket) >= 0,
   "Current time must be within or after the last bucket.");
 long elapsedTimeMillis = now.subtractTimestamp(startOfLastBucket).toMillis();
 long numOfPadBuckets = elapsedTimeMillis / bucketDuration.toMillis();
 shiftBucketList(numOfPadBuckets, now);
}

代码示例来源:origin: io.opencensus/opencensus-impl-core

private void refreshBucketList(Timestamp now) {
 if (buckets.size() != N + 1) {
  throw new AssertionError("Bucket list must have exactly " + (N + 1) + " buckets.");
 }
 Timestamp startOfLastBucket =
   CheckerFrameworkUtils.castNonNull(buckets.peekLast()).getStart();
 // TODO(songya): decide what to do when time goes backwards
 checkArgument(
   now.compareTo(startOfLastBucket) >= 0,
   "Current time must be within or after the last bucket.");
 long elapsedTimeMillis = now.subtractTimestamp(startOfLastBucket).toMillis();
 long numOfPadBuckets = elapsedTimeMillis / bucketDuration.toMillis();
 shiftBucketList(numOfPadBuckets, now);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void timestampSubtractTimestamp_NegativeResult() {
 Timestamp timestamp = Timestamp.create(1234, 223);
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1235, 223)))
   .isEqualTo(Duration.create(-1, 0));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1234, 224)))
   .isEqualTo(Duration.create(0, -1));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1235, 224)))
   .isEqualTo(Duration.create(-1, -1));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1236, 123)))
   .isEqualTo(Duration.create(-1, -999999900));
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void timestampSubtractTimestamp() {
 Timestamp timestamp = Timestamp.create(1234, 223);
 assertThat(timestamp.subtractTimestamp(Timestamp.create(0, 0)))
   .isEqualTo(Duration.create(1234, 223));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1233, 223)))
   .isEqualTo(Duration.create(1, 0));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1233, 222)))
   .isEqualTo(Duration.create(1, 1));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1232, 999999900)))
   .isEqualTo(Duration.create(1, 323));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1200, 224)))
   .isEqualTo(Duration.create(33, 999999999));
}

代码示例来源:origin: census-instrumentation/opencensus-java

? String.format(
     "%13.6f",
     durationToNanos(span.getEndTimestamp().subtractTimestamp(span.getStartTimestamp()))
       * 1.0e-9)
   : String.format("%13s", " ");
    durationToNanos(event.getTimestamp().subtractTimestamp(lastTimestampNanos)));
String deltaString;
if (deltaMicros >= 1000000) {

相关文章