コード例 #1
0
        public void NestedCollectorTest()
        {
            using (PerformanceCollector collector = new PerformanceCollector(TimeSpan.FromMilliseconds(10)))
            {
                using (var aggregator = collector.CreateAggregator())
                {
                    // Sleep until we get a sample
                    Stopwatch sw = Stopwatch.StartNew();
                    while (sw.Elapsed.TotalSeconds < 60 && GetMaxAggregatorCount(aggregator) < 2)
                    {
                        Thread.Sleep(10);
                    }

                    XAssert.IsTrue(GetMaxAggregatorCount(aggregator) > 0, "No samples were collected");

                    using (var aggregator2 = collector.CreateAggregator())
                    {
                        Stopwatch sw2 = Stopwatch.StartNew();
                        while (sw2.Elapsed.TotalSeconds < 1 && GetMaxAggregatorCount(aggregator2) < 2)
                        {
                            Thread.Sleep(10);
                        }

                        XAssert.IsTrue(GetMaxAggregatorCount(aggregator) > GetMaxAggregatorCount(aggregator2), "The nested aggregator should have fewer samples than the earlier created aggregator");
                    }
                }
            }
        }
コード例 #2
0
        public static TimedBlock <TStartObject, TEndObject> Start(
            LoggingContext parentLoggingContext,
            PerformanceCollector collector,
            string phaseFriendlyName,
            Action <LoggingContext, TStartObject> startAction,
            TStartObject startObject,
            Action <LoggingContext, TEndObject> endAction,
            Func <TEndObject> endObjGetter)
        {
            // There's no point is using this structure if the end action and struct aren't set
            Contract.Requires(parentLoggingContext != null);
            Contract.Requires(endAction != null);
            Contract.Requires(endObjGetter != null);
            Contract.Requires(startAction != null);
            Contract.Requires(collector == null || !string.IsNullOrWhiteSpace(phaseFriendlyName));

            startAction(parentLoggingContext, startObject);

            return(new TimedBlock <TStartObject, TEndObject>(
                       parentLoggingContext,
                       collector?.CreateAggregator(),
                       phaseFriendlyName,
                       endAction,
                       endObjGetter));
        }
コード例 #3
0
        public static PerformanceMeasurement Start(
            LoggingContext parentLoggingContext,
            PerformanceCollector collector,
            string phaseFriendlyName,
            Action <LoggingContext> startAction,
            Action <LoggingContext> endAction)
        {
            Contract.Requires(parentLoggingContext != null);
            Contract.Requires(collector == null || !string.IsNullOrWhiteSpace(phaseFriendlyName));
            Contract.Requires(startAction != null);
            Contract.Requires(endAction != null);

            var pm = new PerformanceMeasurement(
                parentLoggingContext,
                collector != null ? collector.CreateAggregator() : null,
                phaseFriendlyName,
                endAction);

            startAction(pm.LoggingContext);

            return(pm);
        }
コード例 #4
0
 public MachinePerformanceCollector()
 {
     _perfStatsAggregator = _collector.CreateAggregator();
 }