Пример #1
0
        public static PerformanceAggregate CloneForSwitch(PerformanceAggregate aggregate)
        {
            var result = new PerformanceAggregate(aggregate.Counter, aggregate.Values);

            {
                aggregate.Values = PerformanceItemCollection.CloneAndInitialize(aggregate.Counter.NextValue(), aggregate.Values.LastValue);
            }

            return(result);
        }
Пример #2
0
        private PerformanceResult(ProcedureContext procedureContext, IEnumerable <PerformanceCounter> counters)
        {
            #region Argument exceptions

            if (procedureContext == null)
            {
                throw new ArgumentNullException("procedureContext");
            }

            if (counters == null)
            {
                throw new ArgumentNullException("counters");
            }

            #endregion

            _procedureContext = procedureContext;

            foreach (var item in counters)
            {
                _performances.Add(PerformanceAggregate.Create(item));
            }
        }
Пример #3
0
        public Task FlushBatch(TimeSpan timeout)
        {
            Debug.Assert(_procedureContext.ExecuteForPrepare == false);
            Debug.Assert(_procedureContext.ExecutionMode == ProcedureExecutionMode.Batch);

            lock (_performances)
            {
                foreach (var item in _performances)
                {
                    _performancesBag.Add(PerformanceAggregate.CloneForSwitch(item));
                }
            }

            return(Task.Factory.StartNew(() =>
            {
                if (Monitor.TryEnter(_sync, timeout))
                {
                    try
                    {
                        var aggregateCollection = new List <PerformanceAggregate>();

                        PerformanceAggregate aggregate;
                        while (_performancesBag.TryTake(out aggregate))
                        {
                            aggregateCollection.Add(aggregate);
                        }

                        aggregateCollection.WriteToServer(_procedureContext);
                    }
                    finally
                    {
                        Monitor.Exit(_sync);
                    }
                }
            },
                                         _procedureContext.CancellationToken, TaskCreationOptions.AttachedToParent, TaskScheduler.Default));
        }