本文整理汇总了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;
}
示例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;
}
}
}
示例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);
}
}
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
}
示例8: MemoryPlugin
public MemoryPlugin(ApplicationConfiguration config)
{
using (Profiler.Step("Memory Init"))
{
_config = _config;
var category = new PerformanceCounterCategory("Memory");
_counters = category.GetCounters();
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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_;
}
示例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)));
}