/// <summary> /// Implements HistogramController interface /// </summary> public override void AddSample(Histogram histogram, StackSourceSample sample) { double bucketDuration = BucketDuration; double startSampleInBucket = sample.TimeRelativeMSec; int bucketIndex = (int)((sample.TimeRelativeMSec - Start) / bucketDuration); Debug.Assert(0 <= bucketIndex && bucketIndex <= BucketCount); if (Tree.ScalingPolicy == ScalingPolicyKind.TimeMetric) { // place the metric in each of the buckets it overlaps with. var nextBucketStart = GetStartTimeForBucket((HistogramCharacterIndex)(bucketIndex + 1)); // The Math.Abs is a bit of a hack. The problem is that that sample does not // represent time for a DIFF (because we negated it) but I rely on the fact // that we only negate it so I can undo it double endSample = sample.TimeRelativeMSec + Math.Abs(sample.Metric); var metricSign = sample.Metric > 0 ? 1 : -1; for (; ;) { if (BucketCount <= bucketIndex) { break; } var metricInBucket = Math.Min(nextBucketStart, endSample) - startSampleInBucket; histogram.AddMetric((float)metricInBucket * metricSign, bucketIndex); bucketIndex++; startSampleInBucket = nextBucketStart; nextBucketStart += bucketDuration; if (startSampleInBucket > endSample) { break; } } } else { // Put the sample in the right bucket. Note that because we allow inclusive times on the end // point we could get bucketIndex == Length, so put that sample in the last bucket. if (bucketIndex >= BucketCount) { bucketIndex = BucketCount - 1; } histogram.AddMetric(sample.Metric, bucketIndex); } }
/// <summary> /// Add a sample to a histogram controlled by this HistogramController. /// </summary> /// <param name="histogram">The histogram to add the sample to.</param> /// <param name="sample">The sample to add.</param> public override void AddSample(Histogram histogram, StackSourceSample sample) { histogram.AddMetric(sample.Metric, sample.Scenario); }