/// <summary> /// Initializes a new instance of the <see cref="PercentileSnapshot"/> class from the given buckets. /// </summary> /// <param name="buckets">The buckets to initialize the snapshot.</param> public PercentileSnapshot(Bucket[] buckets) { int lengthFromBuckets = 0; // We need to calculate it dynamically as it could have been changed by properties (rare, but possible) // Also this way we capture the actual index size rather than the max, so size the int[] to only what we need foreach (Bucket bd in buckets) { lengthFromBuckets += bd.Data.Length; } this.data = new int[lengthFromBuckets]; int index = 0; int min = int.MaxValue; foreach (Bucket bd in buckets) { PercentileBucketData pbd = bd.Data; int length = pbd.Length; for (int i = 0; i < length && index < this.data.Length; i++) { int v = pbd.List[i]; this.data[index++] = v; Sum += v; if (Max < v) { Max = v; } if (min > v) { min = v; } } } if (min < int.MaxValue) { Min = min; } this.length = index; if (this.length == 0) { this.Mean = 0; } else { this.Mean = (int)Math.Round((double)Sum / (double)this.length); } Array.Sort(this.data, 0, this.length); }
/* package for testing */ public PercentileSnapshot(Bucket[] buckets) { int lengthFromBuckets = 0; // we need to calculate it dynamically as it could have been changed by properties (rare, but possible) // also this way we capture the actual index size rather than the max so size the int[] to only what we need foreach (Bucket bd in buckets) { lengthFromBuckets += bd._data._length; } data = new int[lengthFromBuckets]; int index = 0; int sum = 0; foreach (Bucket bd in buckets) { PercentileBucketData pbd = bd._data; int length = pbd.Length; for (int i = 0; i < length; i++) { int v = pbd._list[i]; this.data[index++] = v; sum += v; } } this.length = index; if (this.length == 0) { this.mean = 0; } else { this.mean = sum / this.length; } Array.Sort(this.data, 0, length); }
public RollingPercentileBucket(long startTime, int bucketDataLength) { windowStart = startTime; data = new PercentileBucketData(bucketDataLength); }
public Bucket(long startTime, int bucketDataLength) { this._windowStart = startTime; this._data = new PercentileBucketData(bucketDataLength); }