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


C# CounterCreationDataCollection.Cast方法代码示例

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


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

示例1: 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

示例2: 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

示例3: IsCounterAlreadyIncluded

 private static bool IsCounterAlreadyIncluded(ref CounterCreationDataCollection colCounterCreationData, string counterName)
 {
     return colCounterCreationData.Cast<CounterCreationData>().Any(objCreateCounter => objCreateCounter.CounterName == counterName);
 }
开发者ID:simondmorias,项目名称:MSBuildExtensionPack,代码行数:4,代码来源:PerformanceCounters.cs


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