Пример #1
0
        public override IEnumerable<MetricCollector> Create(RunMode runMode, WarmupData warmup, IBenchmarkSetting setting)
        {

            //if (warmup.ElapsedTicks <= BenchmarkConstants.SamplingPrecisionTicks)
                return new[] {new GcTotalMemoryCollector(MemoryMetricName)};
            //return new[] {new PerformanceCounterTotalMemoryCollector(MemoryMetricName)};
        }
Пример #2
0
        public override MetricCollector Create(RunMode runMode, WarmupData warmup, IBenchmarkSetting setting)
        {
            var timingSetting = setting as TimingBenchmarkSetting;
            Contract.Assert(timingSetting != null);

            return new TimingCollector(timingSetting.TimingMetricName);
        }
        public override MetricCollector Create(RunMode runMode, WarmupData warmup, IBenchmarkSetting setting)
        {
            var timingSetting = setting as TimingBenchmarkSetting;

            Contract.Assert(timingSetting != null);

            return(new TimingCollector(timingSetting.TimingMetricName));
        }
        public override MetricCollector Create(RunMode runMode, WarmupData warmup, IBenchmarkSetting setting)
        {
            Contract.Assert(setting != null);
            Contract.Assert(setting is CreateCounterBenchmarkSetting);
            var createCounter = setting as CreateCounterBenchmarkSetting;

            // ReSharper disable once PossibleNullReferenceException
            // resolved with Code Contracts
            return(new CounterMetricCollector(createCounter.BenchmarkSetting.CounterName, createCounter.Counter));
        }
Пример #5
0
        public override MetricCollector Create(RunMode runMode, WarmupData warmup, IBenchmarkSetting setting)
        {
            Contract.Assert(setting != null);
            Contract.Assert(setting is CreateCounterBenchmarkSetting);
            var createCounter = setting as CreateCounterBenchmarkSetting;

            // ReSharper disable once PossibleNullReferenceException
            // resolved with Code Contracts
            return new CounterMetricCollector(createCounter.BenchmarkSetting.CounterName, createCounter.Counter);
        }
        public override MetricCollector Create(RunMode runMode, WarmupData warmup,
                                               IBenchmarkSetting setting)
        {
            Contract.Assert(setting != null);
            Contract.Assert(setting is GcBenchmarkSetting);
            var gcSetting = setting as GcBenchmarkSetting;

            // ReSharper disable once PossibleNullReferenceException
            // covered by Code Contracts
            if (gcSetting.Generation == GcGeneration.AllGc)
            {
                throw new InvalidOperationException($"{gcSetting.Generation} is not supported by this collector");
            }

            return(CreateInstanceInternal((int)gcSetting.Generation));
        }
Пример #7
0
        public override MetricCollector Create(RunMode runMode, WarmupData warmup,
            IBenchmarkSetting setting)
        {
            Contract.Assert(setting != null);
            Contract.Assert(setting is GcBenchmarkSetting);
            var gcSetting = setting as GcBenchmarkSetting;

            // ReSharper disable once PossibleNullReferenceException
            // covered by Code Contracts
            if (gcSetting.Generation == GcGeneration.AllGc)
            {
                throw new InvalidOperationException($"{gcSetting.Generation} is not supported by this collector");
            }

            return CreateInstanceInternal((int) gcSetting.Generation);
        }
        public override IEnumerable<MetricCollector> Create(RunMode runMode, WarmupData warmup,
            IBenchmarkSetting setting)
        {
            Contract.Assert(setting != null);
            Contract.Assert(setting is GcBenchmarkSetting);
            var gcSetting = setting as GcBenchmarkSetting;

            // ReSharper disable once PossibleNullReferenceException
            // covered by Code Contracts
            if (gcSetting.Generation == GcGeneration.AllGc)
            {
                var collectors = new List<MetricCollector>(SystemInfo.MaxGcGeneration + 1);
                for (var i = 0; i <= SystemInfo.MaxGcGeneration; i++)
                {
                    collectors.Add(CreateInstanceInternal(i));
                }
                return collectors;
            }

            return new[] {CreateInstanceInternal((int) gcSetting.Generation)};
        }
Пример #9
0
        public override IEnumerable <MetricCollector> Create(RunMode runMode, WarmupData warmup,
                                                             IBenchmarkSetting setting)
        {
            Contract.Assert(setting != null);
            Contract.Assert(setting is GcBenchmarkSetting);
            var gcSetting = setting as GcBenchmarkSetting;

            // ReSharper disable once PossibleNullReferenceException
            // covered by Code Contracts
            if (gcSetting.Generation == GcGeneration.AllGc)
            {
                var collectors = new List <MetricCollector>(SystemInfo.MaxGcGeneration + 1);
                for (var i = 0; i <= SystemInfo.MaxGcGeneration; i++)
                {
                    collectors.Add(CreateInstanceInternal(i));
                }
                return(collectors);
            }

            return(new[] { CreateInstanceInternal((int)gcSetting.Generation) });
        }
 public bool Equals(IBenchmarkSetting other)
 {
     return((other is PerformanceCounterBenchmarkSetting) &&
            Equals((PerformanceCounterBenchmarkSetting)other));
 }
Пример #11
0
 public bool Equals(IBenchmarkSetting other)
 {
     return(other is GcBenchmarkSetting &&
            Equals((GcBenchmarkSetting)other));
 }
Пример #12
0
 public bool Equals(IBenchmarkSetting other)
 {
     return (other is TimingBenchmarkSetting)
         && Equals((TimingBenchmarkSetting) other);
 }
 /// <summary>
 ///     Creates an instance for all applicable <see cref="MetricCollector" />s for this metric type.
 /// </summary>
 /// <param name="runMode">
 ///     The <see cref="RunMode" /> for this benchmark. Influences the type of
 ///     <see cref="MetricCollector" /> used in some instances.
 /// </param>
 /// <param name="warmup">Warmup data. Influences the type of <see cref="MetricCollector" /> used in some instances.</param>
 /// <param name="setting">An implementation-specific <see cref="IBenchmarkSetting" /></param>
 /// <returns>At least 1 new <see cref="MetricCollector"/> instance. Each instance will be uniquely named.</returns>
 public abstract IEnumerable<MetricCollector> Create(RunMode runMode, WarmupData warmup,
     IBenchmarkSetting setting);
Пример #14
0
        public override MetricCollector Create(RunMode runMode, WarmupData warmup, IBenchmarkSetting setting)
        {
            Contract.Assert(setting != null);
            Contract.Assert(setting is PerformanceCounterBenchmarkSetting);
            var counterBenchmarkSetting = setting as PerformanceCounterBenchmarkSetting;
            var name = counterBenchmarkSetting.PerformanceCounterMetric;

            // re-use the PerformanceCounter objects in our pool if possible
            if (_cache.Exists(name))
            {
                return(new PerformanceCounterValueCollector(name, name.UnitName ?? MetricNames.DefaultUnitName, _cache.Get(name), true));
            }

            // otherwise, warm up new ones
            var maxRetries     = 3;
            var currentRetries = 0;

            if (!PerformanceCounterCategory.CounterExists(name.CounterName, name.CategoryName))
            {
                throw new NBenchException($"Performance counter {name.ToHumanFriendlyString()} is not registered on this machine. Please create it first.");
            }

            // check to see that the instance we're interested in is registered
            if (!string.IsNullOrEmpty(name.InstanceName))
            {
                var categories = PerformanceCounterCategory.GetCategories().Where(x => x.CategoryType == PerformanceCounterCategoryType.MultiInstance).ToList();
#if DEBUG
                Console.WriteLine("---- DEBUG -----");
                Console.WriteLine("{0} multi-instance categories detected", categories.Count);
#endif
                var category  = categories.Single(x => x.CategoryName == name.CategoryName);
                var instances = category.GetInstanceNames();

                if (!instances.Contains(name.InstanceName))
                {
#if DEBUG
                    Console.WriteLine("---- DEBUG -----");
                    Console.WriteLine("Multi-instance? {0}", category.CategoryType);
                    foreach (var instance in instances)
                    {
                        Console.WriteLine(instance);
                    }
#endif
                    throw new NBenchException($"Performance counter {name.CategoryName}:{name.CounterName} exists, but we could not find an instance {name.InstanceName}.");
                }
            }

            var proxy = new PerformanceCounterProxy(() =>
            {
                var counter = new PerformanceCounter(name.CategoryName, name.CounterName,
                                                     name.InstanceName ?? string.Empty, true);

                return(counter);
            });
            while (!CanFindPerformanceCounter(name) && currentRetries <= maxRetries)
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(1000 + 100 * (currentRetries ^ 2))); // little bit of exponential backoff
                if (proxy.CanWarmup)
                {
                    break;
                }
                currentRetries++;
            }

            if (!proxy.CanWarmup)
            {
                throw new NBenchException($"Performance counter {name.ToHumanFriendlyString()} is not registered on this machine. Please create it first.");
            }

            // cache this performance counter and pool it for re-use
            _cache.Put(name, proxy);
            return(new PerformanceCounterValueCollector(name, name.UnitName ?? MetricNames.DefaultUnitName, _cache.Get(name), true));
        }
 public bool Equals(IBenchmarkSetting other)
 {
     return other is CreateCounterBenchmarkSetting &&
            ((CreateCounterBenchmarkSetting) other).BenchmarkSetting.Equals(BenchmarkSetting);
 }
        public override MetricCollector Create(RunMode runMode, WarmupData warmup, IBenchmarkSetting setting)
        {
            Contract.Assert(setting != null);
            Contract.Assert(setting is PerformanceCounterBenchmarkSetting);
            var counterBenchmarkSetting = setting as PerformanceCounterBenchmarkSetting;
            var name = counterBenchmarkSetting.PerformanceCounterMetric;

            // re-use the PerformanceCounter objects in our pool if possible
            if (_cache.Exists(name))
                return new PerformanceCounterValueCollector(name, name.UnitName ?? MetricNames.DefaultUnitName, _cache.Get(name), true);

            // otherwise, warm up new ones
            var maxRetries = 3;
            var currentRetries = 0;

            if (!PerformanceCounterCategory.CounterExists(name.CounterName, name.CategoryName))
                throw new NBenchException($"Performance counter {name.ToHumanFriendlyString()} is not registered on this machine. Please create it first.");

            // check to see that the instance we're interested in is registered
            if (!string.IsNullOrEmpty(name.InstanceName))
            {
                var categories = PerformanceCounterCategory.GetCategories().Where(x => x.CategoryType == PerformanceCounterCategoryType.MultiInstance).ToList();
            #if DEBUG
                Console.WriteLine("---- DEBUG -----");
                Console.WriteLine("{0} multi-instance categories detected", categories.Count);
            #endif
                var category = categories.Single(x => x.CategoryName == name.CategoryName);
                var instances = category.GetInstanceNames();

                if (!instances.Contains(name.InstanceName))
                {
            #if DEBUG
                    Console.WriteLine("---- DEBUG -----");
                    Console.WriteLine("Multi-instance? {0}", category.CategoryType);
                    foreach (var instance in instances)
                        Console.WriteLine(instance);
            #endif
                    throw new NBenchException($"Performance counter {name.CategoryName}:{name.CounterName} exists, but we could not find an instance {name.InstanceName}.");
                }

            }

            var proxy = new PerformanceCounterProxy(() =>
            {
                var counter = new PerformanceCounter(name.CategoryName, name.CounterName,
                    name.InstanceName ?? string.Empty, true);

                return counter;
            });
            while (!CanFindPerformanceCounter(name) && currentRetries <= maxRetries)
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(1000 + 100 * (currentRetries ^ 2))); // little bit of exponential backoff
                if (proxy.CanWarmup)
                    break;
                currentRetries++;
            }

            if (!proxy.CanWarmup)
                throw new NBenchException($"Performance counter {name.ToHumanFriendlyString()} is not registered on this machine. Please create it first.");

            // cache this performance counter and pool it for re-use
            _cache.Put(name, proxy);
            return new PerformanceCounterValueCollector(name, name.UnitName ?? MetricNames.DefaultUnitName, _cache.Get(name), true);
        }
 public bool Equals(IBenchmarkSetting other)
 {
     return(other is MemoryBenchmarkSetting &&
            Equals((MemoryBenchmarkSetting)other));
 }
Пример #18
0
 /// <summary>
 ///     Creates an instance for all applicable <see cref="MetricCollector" />s for this metric type.
 /// </summary>
 /// <param name="runMode">
 ///     The <see cref="RunMode" /> for this benchmark. Influences the type of
 ///     <see cref="MetricCollector" /> used in some instances.
 /// </param>
 /// <param name="setting">An implementation-specific <see cref="IBenchmarkSetting" /></param>
 /// <returns>A new <see cref="MetricCollector" /> instance. </returns>
 public MetricCollector Create(RunMode runMode, IBenchmarkSetting setting)
 {
     return Create(runMode, WarmupData.PreWarmup, setting);
 }
 /// <summary>
 ///     Creates an instance for all applicable <see cref="MetricCollector" />s for this metric type.
 /// </summary>
 /// <param name="runMode">
 ///     The <see cref="RunMode" /> for this benchmark. Influences the type of
 ///     <see cref="MetricCollector" /> used in some instances.
 /// </param>
 /// <param name="warmup">Warmup data. Influences the type of <see cref="MetricCollector" /> used in some instances.</param>
 /// <param name="setting">An implementation-specific <see cref="IBenchmarkSetting" /></param>
 /// <returns>A new <see cref="MetricCollector" /> instance.</returns>
 public abstract MetricCollector Create(RunMode runMode, WarmupData warmup,
                                        IBenchmarkSetting setting);
 public bool Equals(IBenchmarkSetting other)
 {
     return(other is CreateCounterBenchmarkSetting &&
            ((CreateCounterBenchmarkSetting)other).BenchmarkSetting.Equals(BenchmarkSetting));
 }
Пример #21
0
 /// <summary>
 ///     Creates an instance for all applicable <see cref="MetricCollector" />s for this metric type.
 /// </summary>
 /// <param name="runMode">
 ///     The <see cref="RunMode" /> for this benchmark. Influences the type of
 ///     <see cref="MetricCollector" /> used in some instances.
 /// </param>
 /// <param name="warmup">Warmup data. Influences the type of <see cref="MetricCollector" /> used in some instances.</param>
 /// <param name="setting">An implementation-specific <see cref="IBenchmarkSetting" /></param>
 /// <returns>A new <see cref="MetricCollector" /> instance.</returns>
 public abstract MetricCollector Create(RunMode runMode, WarmupData warmup,
     IBenchmarkSetting setting);
Пример #22
0
 public bool Equals(IBenchmarkSetting other)
 {
     return((other is TimingBenchmarkSetting) &&
            Equals((TimingBenchmarkSetting)other));
 }
 /// <summary>
 ///     Creates an instance for all applicable <see cref="MetricCollector" />s for this metric type.
 /// </summary>
 /// <param name="runMode">
 ///     The <see cref="RunMode" /> for this benchmark. Influences the type of
 ///     <see cref="MetricCollector" /> used in some instances.
 /// </param>
 /// <param name="setting">An implementation-specific <see cref="IBenchmarkSetting" /></param>
 /// <returns>A new <see cref="MetricCollector" /> instance. </returns>
 public MetricCollector Create(RunMode runMode, IBenchmarkSetting setting)
 {
     return(Create(runMode, WarmupData.PreWarmup, setting));
 }
Пример #24
0
 public override IEnumerable <MetricCollector> Create(RunMode runMode, WarmupData warmup, IBenchmarkSetting setting)
 {
     //if (warmup.ElapsedTicks <= BenchmarkConstants.SamplingPrecisionTicks)
     return(new[] { new GcTotalMemoryCollector(MemoryMetricName) });
     //return new[] {new PerformanceCounterTotalMemoryCollector(MemoryMetricName)};
 }
 public bool Equals(IBenchmarkSetting other)
 {
     return(other is CounterBenchmarkSetting &&
            Equals((CounterBenchmarkSetting)other));
 }
Пример #26
0
 /// <summary>
 ///     Creates an instance for all applicable <see cref="MetricCollector" />s for this metric type.
 /// </summary>
 /// <param name="runMode">
 ///     The <see cref="RunMode" /> for this benchmark. Influences the type of
 ///     <see cref="MetricCollector" /> used in some instances.
 /// </param>
 /// <param name="warmup">Warmup data. Influences the type of <see cref="MetricCollector" /> used in some instances.</param>
 /// <param name="setting">An implementation-specific <see cref="IBenchmarkSetting" /></param>
 /// <returns>At least 1 new <see cref="MetricCollector"/> instance. Each instance will be uniquely named.</returns>
 public abstract IEnumerable <MetricCollector> Create(RunMode runMode, WarmupData warmup,
                                                      IBenchmarkSetting setting);