diff options
Diffstat (limited to 'kamon-core/src/main')
-rw-r--r-- | kamon-core/src/main/resources/reference.conf | 3 | ||||
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/Sampler.scala | 15 |
2 files changed, 16 insertions, 2 deletions
diff --git a/kamon-core/src/main/resources/reference.conf b/kamon-core/src/main/resources/reference.conf index 7c4b4ecb..d7276b53 100644 --- a/kamon-core/src/main/resources/reference.conf +++ b/kamon-core/src/main/resources/reference.conf @@ -147,7 +147,8 @@ kamon { # Use a AtomicLong to ensure that every .sample-interval number of requests tracing information will be gathered and # reported. ordered-sampler { - sample-interval = 10 + # must be power of two + sample-interval = 8 } # Gather tracing information for all traces but only report those whose elapsed-time is equal or greated to the diff --git a/kamon-core/src/main/scala/kamon/trace/Sampler.scala b/kamon-core/src/main/scala/kamon/trace/Sampler.scala index be6ace69..9c6e5e63 100644 --- a/kamon-core/src/main/scala/kamon/trace/Sampler.scala +++ b/kamon-core/src/main/scala/kamon/trace/Sampler.scala @@ -44,14 +44,27 @@ class RandomSampler(chance: Int) extends Sampler { } class OrderedSampler(interval: Int) extends Sampler { + import OrderedSampler._ + require(interval > 0, "kamon.trace.ordered-sampler.interval cannot be <= 0") + assume(interval isPowerOfTwo, "kamon.trace.ordered-sampler.interval must be power of two") private val sequencer = Sequencer() - def shouldTrace: Boolean = sequencer.next() % interval == 0 + def shouldTrace: Boolean = (sequencer.next() fastMod interval) == 0 def shouldReport(traceElapsedTime: NanoInterval): Boolean = true } +object OrderedSampler { + implicit class EnhancedInt(i: Int) { + def isPowerOfTwo = !((i & (i - 1)) == 0) + } + + implicit class EnhancedLong(dividend: Long) { + def fastMod(divisor: Int) = dividend & (divisor - 1) + } +} + class ThresholdSampler(thresholdInNanoseconds: Long) extends Sampler { require(thresholdInNanoseconds > 0, "kamon.trace.threshold-sampler.minimum-elapsed-time cannot be <= 0") |