本文整理汇总了C#中System.Diagnostics.PerformanceCounterCategory.ReadCategory方法的典型用法代码示例。如果您正苦于以下问题:C# PerformanceCounterCategory.ReadCategory方法的具体用法?C# PerformanceCounterCategory.ReadCategory怎么用?C# PerformanceCounterCategory.ReadCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.PerformanceCounterCategory
的用法示例。
在下文中一共展示了PerformanceCounterCategory.ReadCategory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProcessCounterName
/// <summary>
/// Find the process counter name
/// </summary>
/// <returns></returns>
public static string GetProcessCounterName()
{
Process process = Process.GetCurrentProcess();
int id = process.Id;
PerformanceCounterCategory perfCounterCat = new PerformanceCounterCategory("Process");
foreach(DictionaryEntry entry in perfCounterCat.ReadCategory()["id process"])
{
string processCounterName = (string)entry.Key;
if (((InstanceData)entry.Value).RawValue == id)
return processCounterName;
}
return "";
}
示例2: HarvestPerformanceCategory
/// <summary>
/// Harvest a performance category.
/// </summary>
/// <param name="category">The name of the performance category.</param>
/// <returns>A harvested file.</returns>
public Util.PerformanceCategory HarvestPerformanceCategory(string category)
{
if (null == category)
{
throw new ArgumentNullException("category");
}
if (PerformanceCounterCategory.Exists(category))
{
Util.PerformanceCategory perfCategory = new Util.PerformanceCategory();
// Get the performance counter category and set the appropriate WiX attributes
PerformanceCounterCategory pcc = new PerformanceCounterCategory(category);
perfCategory.Id = CompilerCore.GetIdentifierFromName(pcc.CategoryName);
perfCategory.Name = pcc.CategoryName;
perfCategory.Help = pcc.CategoryHelp;
if (PerformanceCounterCategoryType.MultiInstance == pcc.CategoryType)
{
perfCategory.MultiInstance = Util.YesNoType.yes;
}
foreach (InstanceDataCollection counter in pcc.ReadCategory().Values)
{
Util.PerformanceCounter perfCounter = new Util.PerformanceCounter();
// Get the performance counter and set the appropriate WiX attributes
PerformanceCounter pc = new PerformanceCounter(pcc.CategoryName, counter.CounterName);
perfCounter.Name = pc.CounterName;
perfCounter.Type = CounterTypeToWix(pc.CounterType);
perfCounter.Help = pc.CounterHelp;
perfCategory.AddChild(perfCounter);
}
return perfCategory;
}
else
{
throw new WixException(UtilErrors.PerformanceCategoryNotFound(category));
}
}
示例3: tvCategories_AfterSelect
private void tvCategories_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
// Clear the listview to prep it for new data
this.lvCounters.Items.Clear();
// If a category was selected, that has multiple instances skip everything
if(e.Node.Parent == null && e.Node.GetNodeCount(false) > 0)
return;
// If there are no instances just get the category name, otherwise get category and instance name
String strCategory;
String strInstance = null;
if(e.Node.Parent == null)
{
strCategory = e.Node.Text;
}
else
{
strCategory = e.Node.Parent.Text;
strInstance = e.Node.Text;
}
// Suspend drawing until we're done
this.lvCounters.BeginUpdate();
// Get the selected category
PerformanceCounterCategory perfcat = new PerformanceCounterCategory(strCategory, this.comboBox.Text);
try
{
InstanceDataCollectionCollection datacollcoll = perfcat.ReadCategory();
foreach(InstanceDataCollection datacoll in datacollcoll.Values)
{
foreach(InstanceData data in datacoll.Values)
{
if(strInstance == null || data.InstanceName == strInstance)
{
ListViewItem item = new ListViewItem(datacoll.CounterName);
item.SubItems.Add(data.RawValue.ToString());
this.lvCounters.Items.Add(item);
break;
}
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
// Result drawing
this.lvCounters.EndUpdate();
}
示例4: PerfCounterRepopulate
public void PerfCounterRepopulate(PfcMonitor pfc)
{
alreadyPopulated = true;
perfCounterCategories = pfc.Server == "" ? PerformanceCounterCategory.GetCategories() : PerformanceCounterCategory.GetCategories(pfc.Server);
for (int x = 0; x < perfCounterCategories.Length; x++)
{
perfCounterPCTypeDdl.Items.Add(perfCounterCategories[x].CategoryName);
}
PerformanceCounterCategory pcc = new PerformanceCounterCategory(pfc.Category, pfc.Server);
InstanceDataCollectionCollection idcc = pcc.ReadCategory();
perfCounterNames = new List<String>(idcc.Count);
foreach (DictionaryEntry idc in idcc)
{
perfCounterNames.Add(((InstanceDataCollection)idc.Value).CounterName);
}
perfCounterInstances = new List<String>(pcc.GetInstanceNames());
if (perfCounterNames.Count > 0)
perfCounterCounterNameDdl.Items.AddRange(perfCounterNames.ToArray());
else
{
perfCounterCounterNameDdl.Items.Add("None");
perfCounterCounterNameDdl.SelectedItem = "None";
}
if (perfCounterInstances.Count > 0)
perfCounterInstanceNameDdl.Items.AddRange(perfCounterInstances.ToArray());
else
{
perfCounterInstanceNameDdl.Items.Add("None");
perfCounterInstanceNameDdl.SelectedItem = "None";
}
try
{
perfCounterPCTypeDdl.SelectedIndexChanged -= PerfCounterPcTypeDdlSelectedIndexChanged;
perfCounterPCTypeDdl.SelectedItem = pfc.Category;
perfCounterPCTypeDdl.SelectedIndexChanged += PerfCounterPcTypeDdlSelectedIndexChanged;
perfCounterCounterNameDdl.SelectedItem = pfc.Counter;
perfCounterInstanceNameDdl.SelectedItem = pfc.Instance;
perfCounterTestDataThresholdBreachTextBox.Text = pfc.ThresholdBreachCount.ToString();
perfCounterTestDataThresholdLessThanCheckBox.Checked = pfc.ThresholdLessThan;
perfCounterTestDataThresholdPanicTextBox.Text = pfc.ThresholdPanic;
perfCounterTestDataThresholdWarningTextBox.Text = pfc.ThresholdWarning;
perfCounterTestDataUpdateFreqTextBox.Text = pfc.UpdateFrequency.ToString();
}
catch(Exception ex)
{
Logger.Instance.LogException(this.GetType(), ex);
}
perfCounterCategoryWaitLabel.Visible = false;
perfCounterPCTypeDdl.Visible = true;
perfCounterCounterNameWaitLabel.Visible = false;
perfCounterCounterNameDdl.Visible = true;
perfCounterInstanceNameWaitLabel.Visible = false;
perfCounterInstanceNameDdl.Visible = true;
}
示例5: GetCounterNamesAndInstances
private void GetCounterNamesAndInstances(object selectedItemText)
{
PerformanceCounterCategory pcc = new PerformanceCounterCategory((String)selectedItemText, IpOrHostName);
try
{
InstanceDataCollectionCollection idcc = pcc.ReadCategory();
perfCounterNames = new List<String>(idcc.Count);
foreach (DictionaryEntry idc in idcc)
{
perfCounterNames.Add(((InstanceDataCollection) idc.Value).CounterName);
}
}
catch (Exception ex)
{
Logger.Instance.LogException(this.GetType(), ex);
ToLog = "Error: " + ex.Message;
}
try
{
perfCounterInstances = new List<String>(pcc.GetInstanceNames());
}
catch (Exception ex)
{
Logger.Instance.LogException(this.GetType(), ex);
ToLog = "Error: " + ex.Message;
}
Invoke(new PopulateCounterNamesDelegate(PopulatePerfCounterNamesAndInstancesDdl));
}