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


C# PerformanceCounterCategory.GetCounters方法代码示例

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


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

示例1: GetCountersForCategory

 public static List<string> GetCountersForCategory(string category, string instance)
 {
     var cat = new PerformanceCounterCategory(category);
     var counters = string.IsNullOrEmpty(instance)
         ? cat.GetCounters()
         : cat.GetCounters(instance);
     var ret = new List<string>();
     foreach(var counter in counters) {
         ret.Add(counter.CounterName);
     }
     return ret;
 }
开发者ID:AndyCross,项目名称:CloudMonitR,代码行数:12,代码来源:PerformanceCounterFactory.cs

示例2: GetCounterNames

 public IEnumerable<string> GetCounterNames(string category)
 {
     var cat = new PerformanceCounterCategory(category);
     var instances = cat.CategoryType == PerformanceCounterCategoryType.SingleInstance ? new string[] { null } : cat.GetInstanceNames();
     foreach (var instance in instances)
     {
         var coutners = string.IsNullOrEmpty(instance) ? cat.GetCounters().Select(x => x.CounterName) : cat.GetCounters(instance).Select(x => x.CounterName);
         foreach (var counter in coutners)
         {
             yield return counter;
         }
     }
 }
开发者ID:zeugfr,项目名称:Influx-Capacitor,代码行数:13,代码来源:CounterBusiness.cs

示例3: PerfCounterMBean

 public PerfCounterMBean(string perfObjectName, string perfInstanceName, IEnumerable<string> perfCounterNames, bool useProcessInstanceName, bool useAllCounters)
 {
     _perfObjectName = perfObjectName;
      if (useProcessInstanceName)
      {
     Process p = Process.GetCurrentProcess();
     _perfInstanceName = p.ProcessName;
      }
      else
      {
     _perfInstanceName = perfInstanceName ?? "";
      }
      _category = new PerformanceCounterCategory(_perfObjectName);
      if (useAllCounters)
      {
     foreach (PerformanceCounter counter in _category.GetCounters(_perfInstanceName))
     {
        _counters[counter.CounterName] = counter;
     }
      }
      else if (perfCounterNames != null)
      {
     foreach (string counterName in perfCounterNames)
     {
        PerformanceCounter counter;
        counter = new PerformanceCounter(_perfObjectName, counterName, _perfInstanceName, true);
        _counters.Add(counterName, counter);
     }
      }
 }
开发者ID:SzymonPobiega,项目名称:NetMX,代码行数:30,代码来源:PerfCounterMBean.cs

示例4: GetOrCreateCounterCategory

        /// <summary>
        /// Gets the or create counter category.
        /// </summary>
        /// <param name="categoryInfo">The category information.</param>
        /// <param name="counters">The counters.</param>
        /// <returns>PerformanceCounterCategory.</returns>
        private static PerformanceCounterCategory GetOrCreateCounterCategory(
            PerformanceCounterCategoryInfo categoryInfo, CounterCreationData[] counters)
        {
            var creationPending = true;
            var categoryExists = false;
            var categoryName = categoryInfo.CategoryName;
            var counterNames = new HashSet<string>(counters.Select(info => info.CounterName));
            PerformanceCounterCategory category = null;

            if (PerformanceCounterCategory.Exists(categoryName))
            {
                categoryExists = true;
                category = new PerformanceCounterCategory(categoryName);
                var counterList = category.GetCounters();
                if (category.CategoryType == categoryInfo.CategoryType && counterList.Length == counterNames.Count)
                {
                    creationPending = counterList.Any(x => !counterNames.Contains(x.CounterName));
                }
            }

            if (!creationPending) return category;

            if (categoryExists)
                PerformanceCounterCategory.Delete(categoryName);

            var counterCollection = new CounterCreationDataCollection(counters);

            category = PerformanceCounterCategory.Create(
                categoryInfo.CategoryName,
                categoryInfo.CategoryHelp,
                categoryInfo.CategoryType,
                counterCollection);

            return category;
        }
开发者ID:bradsjm,项目名称:DotEmwin,代码行数:41,代码来源:PerformanceCounterManager.cs

示例5: EnumerateCountersFor

        private static void EnumerateCountersFor(string category)
        {
            var sb = new StringBuilder();
            var counterCategory = new PerformanceCounterCategory(category);

            if(counterCategory.CategoryType == PerformanceCounterCategoryType.SingleInstance)
            {
                foreach (var counter in counterCategory.GetCounters())
                {
                    sb.AppendLine(string.Format("{0}:{1}", category, counter.CounterName));
                }
            }
            else
            {
                foreach (var counterInstance in counterCategory.GetInstanceNames())
                {
                    foreach (var counter in counterCategory.GetCounters(counterInstance))
                    {
                        sb.AppendLine(string.Format("{0}:{1}:{2}", counterInstance, category, counter.CounterName));
                    }
                }
            }

            Console.WriteLine(sb.ToString());
        }
开发者ID:VS1URL,项目名称:metrics-net,代码行数:25,代码来源:CLRProfilerTests.cs

示例6: GetPerfCounters

 public ICollection GetPerfCounters(string category)
 {
     var r = new ArrayList();
     var cat = new PerformanceCounterCategory(category);
     foreach (var counter in cat.GetCounters()) {
         r.Add(new DictionaryEntry(counter.CounterName, counter.NextValue()));
     }
     return r;
 }
开发者ID:ruanzx,项目名称:mausch,代码行数:9,代码来源:IndexController.cs

示例7: DotNetClrDataCategory

 public void DotNetClrDataCategory() {
     var category = new PerformanceCounterCategory(".NET CLR Data");
     Assert.IsNotNull(category);
     var counters = category.GetCounters();
     Assert.IsNotNull(counters);
     Assert.IsTrue(counters.Any());
     foreach(var counter in counters) {
         Console.WriteLine("Counter={0}, InstanceName={1}", counter.CounterName, counter.InstanceName);
     }
 }
开发者ID:debop,项目名称:NFramework,代码行数:10,代码来源:PerformanceCounterFixture.cs

示例8: MemoryPlugin

        public MemoryPlugin(ApplicationConfiguration config)
        {
            using (Profiler.Step("Memory Init"))
            {
                _config = _config;
                var category = new PerformanceCounterCategory("Memory");

                _counters = category.GetCounters();
            }
        }
开发者ID:GregBrant,项目名称:CollectN,代码行数:10,代码来源:MemoryPlugin.cs

示例9: DoCheck

        public object DoCheck()
        {
            PerformanceCounterCategory category = new PerformanceCounterCategory("ASP.NET");
            IDictionary<string, object> values = new Dictionary<string, object>();

            foreach (PerformanceCounter counter in category.GetCounters())
            {
                values.Add(counter.CounterName, counter.NextValue());
            }
            return values;
        }
开发者ID:surgicalcoder,项目名称:Tether,代码行数:11,代码来源:ASPNet.cs

示例10: GetStandardValues

		/// <summary>
		/// Returns a collection of standard values for the data type this type converter is designed for when provided with a
		/// format context.
		/// </summary>
		/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be <see langword="null"/> .</param>
		/// <returns>
		/// A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"/> that holds a standard set
		/// of valid values, or <see langword="null"/> if the data type does not support a
		/// standard set of values.
		/// </returns>
		public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
		{
			INuGenCounter counter = (context == null) ? null : (context.Instance as INuGenCounter);

			string machineName = ".";
			string categoryName = string.Empty;

			if (counter != null) 
			{
				machineName = counter.MachineName;
				categoryName = counter.CategoryName;
			}

			try 
			{
				PerformanceCounterCategory category = new PerformanceCounterCategory(categoryName, machineName);
				
				string[] instances = category.GetInstanceNames();
				PerformanceCounter[] counters = null;

				if (instances.Length == 0) counters = category.GetCounters();
				else counters = category.GetCounters(instances[0]);

				string[] names = new string[counters.Length];

				for (int nameIndex = 0; nameIndex < counters.Length; nameIndex++) 
				{
					names[nameIndex] = counters[nameIndex].CounterName;
				}

				Array.Sort(names, Comparer.Default);

				return new TypeConverter.StandardValuesCollection(names);
			}
			catch
			{
			}

			return null;
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:50,代码来源:NuGenCounterNameConverter.cs

示例11: CpuPlugin

        public CpuPlugin(ApplicationConfiguration config)
        {
            using (Profiler.Step("CPU Init"))
            {
                _config = config;
                var category = new PerformanceCounterCategory("Processor");

                _counters = (from name in category.GetInstanceNames()
                             select category.GetCounters(name))
                            .SelectMany(x => x)
                            .ToArray();
            }
        }
开发者ID:GregBrant,项目名称:CollectN,代码行数:13,代码来源:CPUPlugin.cs

示例12: InterfacePlugin

        public InterfacePlugin()
        {
            using (Profiler.Step("Interface Init"))
            {
                var category = new PerformanceCounterCategory("Network Interface");

                // TODO: This is too slow. Need to define a default list of counters
                //       which can be overridden in the config file.
                _counters = (from name in category.GetInstanceNames()
                             select category.GetCounters(name))
                            .SelectMany(x => x)
                            .ToArray();
            }
        }
开发者ID:GregBrant,项目名称:CollectN,代码行数:14,代码来源:InterfacePlugin.cs

示例13: GetStandardValues

 public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     PerformanceCounter counter = (context == null) ? null : (context.Instance as PerformanceCounter);
     string machineName = ".";
     string categoryName = string.Empty;
     if (counter != null)
     {
         machineName = counter.MachineName;
         categoryName = counter.CategoryName;
     }
     try
     {
         PerformanceCounterCategory category = new PerformanceCounterCategory(categoryName, machineName);
         string[] instanceNames = category.GetInstanceNames();
         PerformanceCounter[] counters = null;
         if (instanceNames.Length == 0)
         {
             counters = category.GetCounters();
         }
         else
         {
             counters = category.GetCounters(instanceNames[0]);
         }
         string[] array = new string[counters.Length];
         for (int i = 0; i < counters.Length; i++)
         {
             array[i] = counters[i].CounterName;
         }
         Array.Sort(array, Comparer.Default);
         return new TypeConverter.StandardValuesCollection(array);
     }
     catch (Exception)
     {
     }
     return null;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:36,代码来源:CounterNameConverter.cs

示例14: getDiskCounterHandler_

 private PerformanceCounterCategory getDiskCounterHandler_()
 {
     if (diskCounterHandler_ == null)
     {
         diskCounterHandler_ = new PerformanceCounterCategory("logicaldisk", Environment.MachineName);
         Console.WriteLine("Created new disk counter handler");
         String[] instanceNames = diskCounterHandler_.GetInstanceNames();
         for (int i = 0; i < instanceNames.Length; i++)
             if (instanceNames[i].Contains(':'))
             {
                 diskCounters_ = diskCounterHandler_.GetCounters(instanceNames[i]);
                 Console.WriteLine("Selected logical disk: "+instanceNames[i]+", total counter count: "+diskCounters_.Length);
                 break;
             }
     }
     return diskCounterHandler_;
 }
开发者ID:gerardtse,项目名称:vperf,代码行数:17,代码来源:IOStatManager.cs

示例15: ListInstances

        private void ListInstances(PerformanceCounterCategory category, string instanceName)
        {
            richTextBox1.Text += string.Format("    {0}", instanceName);
            PerformanceCounter[] counters = category.GetCounters(instanceName);

            foreach (PerformanceCounter counter in counters)
            {
                richTextBox1.Text += string.Format("        {0}", counter.CounterName);
            }
            richTextBox1.Text += string.Format("\n\nWorkingSet: {0}", (Environment.WorkingSet / (1024*10)));
        }
开发者ID:JesseFinch,项目名称:testFormsProject,代码行数:11,代码来源:Form2.cs


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