diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2018-06-17 22:50:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-17 22:50:19 +0200 |
commit | 145a601e01f2c90965e88165fc402eb1edd864df (patch) | |
tree | be609e82e410eba0714f4867e11a3c2fff18220c /kamon-core | |
parent | b03c554e4a9f0368bd20d24003cd5f1302a5813a (diff) | |
parent | eeed5e1614eb0435163506a8a740142b71cbe1f5 (diff) | |
download | Kamon-145a601e01f2c90965e88165fc402eb1edd864df.tar.gz Kamon-145a601e01f2c90965e88165fc402eb1edd864df.tar.bz2 Kamon-145a601e01f2c90965e88165fc402eb1edd864df.zip |
Merge pull request #538 from ivantopo/ensure-snapshot-immutability
Ensure that histograms snapshots are immutable
Diffstat (limited to 'kamon-core')
-rw-r--r-- | kamon-core/src/main/scala/kamon/metric/Histogram.scala | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/Histogram.scala b/kamon-core/src/main/scala/kamon/metric/Histogram.scala index 592dae7d..f06e58c4 100644 --- a/kamon-core/src/main/scala/kamon/metric/Histogram.scala +++ b/kamon-core/src/main/scala/kamon/metric/Histogram.scala @@ -117,7 +117,7 @@ private[kamon] trait SnapshotCreation { val zigZagCounts = Array.ofDim[Byte](buffer.limit()) buffer.get(zigZagCounts) - val distribution = new ZigZagCountsDistribution(totalCount, minIndex, maxIndex, ByteBuffer.wrap(zigZagCounts), + val distribution = new ZigZagCountsDistribution(totalCount, minIndex, maxIndex, ByteBuffer.wrap(zigZagCounts).asReadOnlyBuffer(), protectedUnitMagnitude(), protectedSubBucketHalfCount(), protectedSubBucketHalfCountMagnitude()) MetricDistribution(name, tags, unit, dynamicRange, distribution) @@ -130,7 +130,7 @@ private[kamon] object SnapshotCreation { override def initialValue(): ByteBuffer = ByteBuffer.allocate(33792) } - class ZigZagCountsDistribution(val count: Long, minIndex: Int, maxIndex: Int, val zigZagCounts: ByteBuffer, + class ZigZagCountsDistribution(val count: Long, minIndex: Int, maxIndex: Int, zigZagCounts: ByteBuffer, unitMagnitude: Int, subBucketHalfCount: Int, subBucketHalfCountMagnitude: Int) extends Distribution { val min: Long = if(count == 0) 0 else bucketValueAtIndex(minIndex) @@ -211,6 +211,10 @@ private[kamon] object SnapshotCreation { builder.result() } + def countsArray(): ByteBuffer = { + zigZagCounts.duplicate() + } + @inline private def bucketValueAtIndex(index: Int): Long = { var bucketIndex: Int = (index >> subBucketHalfCountMagnitude) - 1 var subBucketIndex: Int = (index & (subBucketHalfCount - 1)) + subBucketHalfCount |