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


C# PerformanceCounterCategory.InstanceExists方法代码示例

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


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

示例1: GetCounter

        PerformanceCounter GetCounter(string category, string counter,
             PerformanceCounterType type = PerformanceCounterType.AverageCount64,
             string machine = ".", string instance = "_Total")
        {
            if (!PerformanceCounterCategory.Exists(category))
            {
                // create category
                var counterInfos = new CounterCreationDataCollection();
                var counterInfo = new CounterCreationData()
                    {
                        CounterType = type,
                        CounterName = counter,
                    };
                counterInfos.Add(counterInfo);
                PerformanceCounterCategory
                    .Create(category, category, counterInfos);

                // check creation
                var counters
                    = new PerformanceCounterCategory(category, machine);
                if (!counters.CounterExists(counter))
                    Debug.Fail("Counter was not created");
                if (!counters.InstanceExists(instance))
                    Debug.Fail("Instance not found");
            }

            // get counter

            var perfCounter = new PerformanceCounter
            {
                CategoryName = category,
                CounterName = counter,
                MachineName = machine,
                ReadOnly = false,
            };
            perfCounter.IncrementBy(10);

            return perfCounter;
        }
开发者ID:noriike,项目名称:xaml-106136,代码行数:39,代码来源:Program.cs

示例2: UniquifyInstanceName

        private void UniquifyInstanceName(ref string instanceName)
        {
            // Through experimentation it has been learned that performance counter instances
            // with names greater than 64 characters use a shared counter.  We have not
            // investigated how to use a shared counter, so limit to 64 characters for now
            //
            // We trim to 60 in order to allow space to uniquify the name _NNN 
            // (up to 1000 instances of the same name)
            if (instanceName.Length > 60)
            {
//                string msg = string.Format("Trying to create performance counter instance " +
//                    "greater than 60 characters - {0}, length: {1}.  Instance will be " +
//                    "trimmed to function correctly.", instanceName, instanceName.Length);
//
//                EventLog.WriteEntry("Rtp", msg, EventLogEntryType.Warning, (int)RtpEL.ID.PerformanceCounterTooLong);

                instanceName = instanceName.Substring(0, 60);
            }

            // Check to see if the instanceName already exists and choose a different one
            PerformanceCounterCategory pcc = new PerformanceCounterCategory(categoryName);

            if(pcc.InstanceExists(instanceName))
            {
                int i = 0;
                while(pcc.InstanceExists(instanceName + "_" + (++i)));

                instanceName += "_" + i;
            }        
        }
开发者ID:tdhieu,项目名称:openvss,代码行数:30,代码来源:PerfmonWrapper.cs

示例3: InstanceExists

        /// <devdoc>
        ///     Returns true if the instance already exists for this category and machine specified.
        /// </devdoc>
        public static bool InstanceExists(string instanceName, string categoryName, string machineName) {
            if (instanceName == null)
                throw new ArgumentNullException("instanceName");

            if (categoryName == null)
                throw new ArgumentNullException("categoryName");

            if (categoryName.Length == 0)
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "categoryName", categoryName));

            if (!SyntaxCheck.CheckMachineName(machineName))
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "machineName", machineName));

            PerformanceCounterCategory category = new PerformanceCounterCategory(categoryName, machineName);
            return category.InstanceExists(instanceName);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:19,代码来源:PerformanceCounterCategory.cs

示例4: EnumeratePerformanceCounters

        public DataTable EnumeratePerformanceCounters()
        {
            DataTable dt = new DataTable();
            DataRow dr = null;

            // define the table's schema
            dt.Columns.Add(new DataColumn("PerfCategoryName", typeof(string)));
            dt.Columns.Add(new DataColumn("PerfCounterName", typeof(string)));
            dt.Columns.Add(new DataColumn("PerfInstanceName", typeof(string)));
            dt.Columns.Add(new DataColumn("PerfCategoryDesc", typeof(string)));

            PerformanceCounterCategory[] perfCounterCats = PerformanceCounterCategory.GetCategories();
            PerformanceCounterCategory perfCounterCat = null;
            PerformanceCounter[] perfCounters = null;

            // PerformanceCounterCategoryType - MultiInstance, SingleInstance, Unknown
            string catName = string.Empty;
            string catDesc = string.Empty;
            string counterName = string.Empty;
            string[] instanceNames = null;

            for (int count = 0; count < perfCounterCats.Length; count++)
            {
                catName = perfCounterCats[count].CategoryName;
                catDesc = perfCounterCats[count].CategoryHelp;

                perfCounterCat = new PerformanceCounterCategory(catName);

                instanceNames = perfCounterCat.GetInstanceNames();

                if (instanceNames.Length > 0)
                {
                    foreach (string instanceName in instanceNames)
                    {
                        try
                        {
                            if (perfCounterCat.InstanceExists(instanceName))
                            {
                                perfCounters = perfCounterCat.GetCounters(instanceName);

                                foreach (PerformanceCounter perfCounter in perfCounters)
                                {
                                    counterName = perfCounter.CounterName;

                                    dr = dt.NewRow();
                                    dr[0] = catName;
                                    dr[1] = counterName;
                                    dr[2] = instanceName;
                                    dr[3] = catDesc;
                                    dt.Rows.Add(dr);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Trace.Write(ex.Message + ex.StackTrace, TRACE_CATEGORY);
                        }
                    }
                }
                else
                {
                    foreach (PerformanceCounter perfCounter in perfCounterCat.GetCounters())
                    {
                        counterName = perfCounter.CounterName;

                        dr = dt.NewRow();
                        dr[0] = catName;
                        dr[1] = counterName;
                        dr[2] = BCCUIHelper.Constants.SC303_INSTANCE_NOT_FOUND;
                        dr[3] = catDesc;
                        dt.Rows.Add(dr);
                    }
                }
            }

            return dt;
        }
开发者ID:navkar,项目名称:BizTalkControlCenter,代码行数:77,代码来源:BCCPerformanceCounters.cs


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