aboutsummaryrefslogtreecommitdiff
path: root/impl_core/src/main/java/io/opencensus/implcore/stats
diff options
context:
space:
mode:
authorYang Song <songy23@users.noreply.github.com>2018-04-16 12:13:59 -0700
committerGitHub <noreply@github.com>2018-04-16 12:13:59 -0700
commit3e4352b3684b4646a82eef4f2da66038531d821e (patch)
tree167f5835f480364427692f153c8d5a0da9fc2a7a /impl_core/src/main/java/io/opencensus/implcore/stats
parentb964cdfceb9ddcb5323aad99e1d75cbd417b1c5a (diff)
downloadopencensus-java-3e4352b3684b4646a82eef4f2da66038531d821e.tar.gz
Move toMillis(Duration) to Utils so that it can be reused. (#1114)
* Add toMillis() method to TimeUtils. * Reuse toMillis() method in impl and exporters. * Add a note about overflow and precision loss. * Move toMillis() to Duration.
Diffstat (limited to 'impl_core/src/main/java/io/opencensus/implcore/stats')
-rw-r--r--impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java3
-rw-r--r--impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java14
2 files changed, 4 insertions, 13 deletions
diff --git a/impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java b/impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java
index a35948a7..f114bea6 100644
--- a/impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java
+++ b/impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java
@@ -18,7 +18,6 @@ package io.opencensus.implcore.stats;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
-import static io.opencensus.implcore.stats.MutableViewData.toMillis;
import com.google.common.collect.Maps;
import io.opencensus.common.Duration;
@@ -82,7 +81,7 @@ final class IntervalBucket {
checkArgument(
elapsedTime.compareTo(ZERO) >= 0 && elapsedTime.compareTo(duration) < 0,
"This bucket must be current.");
- return ((double) toMillis(elapsedTime)) / toMillis(duration);
+ return ((double) Duration.toMillis(elapsedTime)) / Duration.toMillis(duration);
}
void clearStats() {
diff --git a/impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java b/impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java
index 588b4897..f0938c06 100644
--- a/impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java
+++ b/impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java
@@ -66,9 +66,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
@SuppressWarnings("deprecation")
abstract class MutableViewData {
- private static final long MILLIS_PER_SECOND = 1000L;
- private static final long NANOS_PER_MILLI = 1000 * 1000;
-
@javax.annotation.Nullable @VisibleForTesting static final TagValue UNKNOWN_TAG_VALUE = null;
@VisibleForTesting static final Timestamp ZERO_TIMESTAMP = Timestamp.create(0, 0);
@@ -149,11 +146,6 @@ abstract class MutableViewData {
return tagValues;
}
- // Returns the milliseconds representation of a Duration.
- static long toMillis(Duration duration) {
- return duration.getSeconds() * MILLIS_PER_SECOND + duration.getNanos() / NANOS_PER_MILLI;
- }
-
/**
* Create an empty {@link MutableAggregation} based on the given {@link Aggregation}.
*
@@ -295,7 +287,7 @@ abstract class MutableViewData {
super(view);
Duration totalDuration = ((View.AggregationWindow.Interval) view.getWindow()).getDuration();
this.totalDuration = totalDuration;
- this.bucketDuration = Duration.fromMillis(toMillis(totalDuration) / N);
+ this.bucketDuration = Duration.fromMillis(Duration.toMillis(totalDuration) / N);
// When initializing. add N empty buckets prior to the start timestamp of this
// IntervalMutableViewData, so that the last bucket will be the current one in effect.
@@ -354,8 +346,8 @@ abstract class MutableViewData {
checkArgument(
now.compareTo(startOfLastBucket) >= 0,
"Current time must be within or after the last bucket.");
- long elapsedTimeMillis = toMillis(now.subtractTimestamp(startOfLastBucket));
- long numOfPadBuckets = elapsedTimeMillis / toMillis(bucketDuration);
+ long elapsedTimeMillis = Duration.toMillis(now.subtractTimestamp(startOfLastBucket));
+ long numOfPadBuckets = elapsedTimeMillis / Duration.toMillis(bucketDuration);
shiftBucketList(numOfPadBuckets, now);
}