private List <MetricAggregate> GetNonpersistentAggregations(DateTimeOffset tactTimestamp, AggregatorCollection aggregators)
        {
            // Complete each non-persistent aggregator:
            // (we snapshotted the entire collection, so Count is stable)

            GrowingCollection <IMetricSeriesAggregator> actualAggregators = aggregators?.Aggregators;

            if (null == actualAggregators || 0 == actualAggregators.Count)
            {
                return(new List <MetricAggregate>(capacity: 0));
            }

            List <MetricAggregate> nonpersistentAggregations = new List <MetricAggregate>(capacity: actualAggregators.Count);

            foreach (IMetricSeriesAggregator aggregator in actualAggregators)
            {
                if (aggregator != null)
                {
                    MetricAggregate aggregate = aggregator.CompleteAggregation(tactTimestamp);

                    if (aggregate != null)
                    {
                        nonpersistentAggregations.Add(aggregate);
                    }
                }
            }

            return(nonpersistentAggregations);
        }
Exemple #2
0
 public StackSnapshotsBufferSegmentCollection()
 {
     _segments            = new GrowingCollection <StackSnapshotsBufferSegment>(SegmentsListAllocationStep);
     _isReadonly          = false;
     _totalByteCount      = 0;
     _totalSnapshotsCount = 0;
     _totalTimeRangeStart = DateTimeOffset.MinValue;
     _totalTimeRangeEnd   = DateTimeOffset.MinValue;
 }
        private List <MetricAggregate> GetPersistentAggregations(DateTimeOffset tactTimestamp, IMetricSeriesFilter previousFilter)
        {
            // Complete each persistent aggregator:
            // The Enumerator of GrowingCollection is a thread-safe lock-free implementation that operates on a "snapshot" of a collection taken at the
            // time when the enumerator is created. We expand the foreach statement (like the compiler normally does) so that we can use the typed
            // enumerator's Count property which is constsent with the data in the snapshot.

            GrowingCollection <IMetricSeriesAggregator> .Enumerator persistentValsAggregators = _aggregatorsForPersistent.Aggregators.GetEnumerator();
            List <MetricAggregate> persistentValsAggregations = new List <MetricAggregate>(capacity: persistentValsAggregators.Count);

            try
            {
                while (persistentValsAggregators.MoveNext())
                {
                    IMetricSeriesAggregator aggregator = persistentValsAggregators.Current;
                    if (aggregator != null)
                    {
                        // Persistent aggregators are always active, regardless of filters for a particular cycle.
                        // But we can apply the cycle's filters to determine whether or not to pull the aggregator
                        // for a aggregate at this time. Of course, only series filters, not value filters, can be considered.
                        IMetricValueFilter unusedValueFilter;
                        bool satisfiesFilter = (previousFilter == null)
                                               ||
                                               (previousFilter.WillConsume(aggregator.DataSeries, out unusedValueFilter));
                        if (satisfiesFilter)
                        {
                            MetricAggregate aggregate = aggregator.CompleteAggregation(tactTimestamp);

                            if (aggregate != null)
                            {
                                persistentValsAggregations.Add(aggregate);
                            }
                        }
                    }
                }
            }
            finally
            {
                persistentValsAggregators.Dispose();
            }

            return(persistentValsAggregations);
        }