当前位置: 首页>>代码示例>>C#>>正文


C# CounterCreationDataCollection.AddRange方法代码示例

本文整理汇总了C#中System.Diagnostics.CounterCreationDataCollection.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# CounterCreationDataCollection.AddRange方法的具体用法?C# CounterCreationDataCollection.AddRange怎么用?C# CounterCreationDataCollection.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.CounterCreationDataCollection的用法示例。


在下文中一共展示了CounterCreationDataCollection.AddRange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Install

        /// <summary>
        /// Installs performance counters in the assembly
        /// </summary>
        /// <param name="installerAssembly"></param>
        /// <param name="discoverer">object that can discover aspects inside and assembly</param>
        /// <param name="categoryName">category name for the metrics. If not provided, it will use the assembly name</param>
        public static void Install(Assembly installerAssembly,
            IInstrumentationDiscoverer discoverer,
            string categoryName = null)
        {
            Uninstall(installerAssembly, discoverer, categoryName);

            if (string.IsNullOrEmpty(categoryName))
                categoryName = installerAssembly.GetName().Name;

            var instrumentationInfos = discoverer.Discover(installerAssembly).ToArray();

            if (instrumentationInfos.Length == 0)
            {
                throw new InvalidOperationException("There are no instrumentationInfos found by the discoverer!");
            }

            var counterCreationDataCollection = new CounterCreationDataCollection();
            Trace.TraceInformation("Number of filters: {0}", instrumentationInfos.Length);

            foreach (var group in instrumentationInfos.GroupBy(x => x.CategoryName))
            {
                foreach (var instrumentationInfo in group)
                {

                    Trace.TraceInformation("Setting up filters '{0}'", instrumentationInfo.Description);

                    if (instrumentationInfo.Counters == null || instrumentationInfo.Counters.Length == 0)
                        instrumentationInfo.Counters = CounterTypes.StandardCounters;

                    foreach (var counterType in instrumentationInfo.Counters)
                    {
                        if (!HandlerFactories.ContainsKey(counterType))
                            throw new ArgumentException("Counter type not defined: " + counterType);

                        // if already exists in the set then ignore
                        if (counterCreationDataCollection.Cast<CounterCreationData>().Any(x => x.CounterName == counterType))
                        {
                            Trace.TraceInformation("Counter type '{0}' was duplicate", counterType);
                            continue;
                        }

                        using (var counterHandler = HandlerFactories[counterType](categoryName, instrumentationInfo.InstanceName))
                        {
                            counterCreationDataCollection.AddRange(counterHandler.BuildCreationData());
                            Trace.TraceInformation("Added counter type '{0}'", counterType);
                        }
                    }
                }

                var catName = string.IsNullOrEmpty(group.Key) ? categoryName : group.Key;

                PerformanceCounterCategory.Create(catName, "PerfIt category for " + catName,
                     PerformanceCounterCategoryType.MultiInstance, counterCreationDataCollection);
            }

            Trace.TraceInformation("Built category '{0}' with {1} items", categoryName, counterCreationDataCollection.Count);
        }
开发者ID:284247028,项目名称:PerfIt,代码行数:63,代码来源:PerfItRuntime.cs

示例2: InstallStandardCounters

        /// <summary>
        ///  installs 4 standard counters for the category provided
        /// </summary>
        /// <param name="categoryName"></param>
        public static void InstallStandardCounters(string categoryName)
        {
            if (PerformanceCounterCategory.Exists(categoryName))
                return;

            var creationDatas = new CounterHandlerBase[]
            {
                new AverageTimeHandler(categoryName, string.Empty),
                new LastOperationExecutionTimeHandler(categoryName, string.Empty),
                new TotalCountHandler(categoryName, string.Empty),
                new NumberOfOperationsPerSecondHandler(categoryName, string.Empty) ,
                new CurrentConcurrentCountHandler(categoryName, string.Empty)
            }.SelectMany(x => x.BuildCreationData());

            var counterCreationDataCollection = new CounterCreationDataCollection();
            counterCreationDataCollection.AddRange(creationDatas.ToArray());
            PerformanceCounterCategory.Create(categoryName, "PerfIt category for " + categoryName,
                PerformanceCounterCategoryType.MultiInstance, counterCreationDataCollection);
        }
开发者ID:284247028,项目名称:PerfIt,代码行数:23,代码来源:PerfItRuntime.cs

示例3: SetupCounters

        private static void SetupCounters(IEnumerable<ICounterExample> counterWorkers)
        {
            if (PerformanceCounterCategory.Exists(CounterCategory))
            {
                Console.WriteLine("Deleting Performance Category {0}", CounterCategory);
                PerformanceCounterCategory.Delete(CounterCategory);
            }

            var counterCreationDatas = counterWorkers.SelectMany(counterWorker => counterWorker.GetCounterCreationData()).ToArray();

            var counterDataCollection = new CounterCreationDataCollection();
            counterDataCollection.AddRange(counterCreationDatas);

            Console.WriteLine("Creating Performance Category {0}", CounterCategory);
            PerformanceCounterCategory.Create(
                CounterCategory,
                "Demonstrates usage of various performance counter types.",
                PerformanceCounterCategoryType.SingleInstance,
                counterDataCollection);
        }
开发者ID:ianrkent,项目名称:PerfCounterPoc,代码行数:20,代码来源:PerformanceCounterPOCApp.cs

示例4: Install

        /// <summary>
        /// Installs performance counters in the current assembly using PerfItFilterAttribute.
        /// </summary>
        /// 
        /// <param name="categoryName">category name for the metrics. If not provided, it will use the assembly name</param>
        public static void Install(Assembly installerAssembly, string categoryName = null)
        {
            Uninstall(installerAssembly, categoryName);

            if (string.IsNullOrEmpty(categoryName))
                categoryName = installerAssembly.GetName().Name;

            var perfItFilterAttributes = FindAllFilters(installerAssembly).ToArray();

            var counterCreationDataCollection = new CounterCreationDataCollection();

            Trace.TraceInformation("Number of filters: {0}", perfItFilterAttributes.Length);

            foreach (var filter in perfItFilterAttributes)
            {

                Trace.TraceInformation("Setting up filters '{0}'", filter.Description);

                foreach (var counterType in filter.Counters)
                {
                    if (!HandlerFactories.ContainsKey(counterType))
                        throw new ArgumentException("Counter type not defined: " + counterType);

                    // if already exists in the set then ignore
                    if (counterCreationDataCollection.Cast<CounterCreationData>().Any(x => x.CounterName == counterType))
                    {
                        Trace.TraceInformation("Counter type '{0}' was duplicate", counterType);
                        continue;
                    }

                    using (var counterHandler = HandlerFactories[counterType](categoryName, filter.InstanceName))
                    {
                        counterCreationDataCollection.AddRange(counterHandler.BuildCreationData());
                        Trace.TraceInformation("Added counter type '{0}'", counterType);
                    }
                }
            }

            PerformanceCounterCategory.Create(categoryName, "PerfIt category for " + categoryName,
                PerformanceCounterCategoryType.MultiInstance, counterCreationDataCollection);

            Trace.TraceInformation("Built category '{0}' with {1} items", categoryName, counterCreationDataCollection.Count);
        }
开发者ID:TimButterfield,项目名称:PerfIt,代码行数:48,代码来源:PerfItRuntime.cs

示例5: InstallCounters

        /// <summary>
        /// Register Orleans perf counters with Windows
        /// </summary>
        /// <remarks>Note: Program needs to be running as Administrator to be able to delete Windows perf counters.</remarks>
        public static void InstallCounters()
        {
            var collection = new CounterCreationDataCollection();
            collection.AddRange(GetCounterCreationData());

            PerformanceCounterCategory.Create(
                CATEGORY_NAME,
                CATEGORY_DESCRIPTION,
                PerformanceCounterCategoryType.SingleInstance,
                collection);
        }
开发者ID:MikeHardman,项目名称:orleans,代码行数:15,代码来源:OrleansPerfCounterManager.cs

示例6: CreatePerformanceCounters

        /// <summary>
        /// Registers the performance counters with the operating system.
        /// </summary>
        private void CreatePerformanceCounters()
        {
            CounterCreationDataCollection ccdc = new CounterCreationDataCollection();

            ccdc.AddRange(TaskManagerInstaller.COUNTERS);

            if (!PerformanceCounterCategory.Exists(TaskManagerInstaller.PERFORMANCE_COUNTER_CATEGORY))
            {
                _performanceCounterCategory = PerformanceCounterCategory.Create(TaskManagerInstaller.PERFORMANCE_COUNTER_CATEGORY, TaskManagerInstaller.PERFORMANCE_COUNTER_DESCRIPTION, PerformanceCounterCategoryType.SingleInstance, ccdc);
            }
        }
开发者ID:giacomelli,项目名称:TaskManager,代码行数:14,代码来源:PerformanceCounterStatsStrategy.cs


注:本文中的System.Diagnostics.CounterCreationDataCollection.AddRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。