Last active
January 21, 2019 05:08
-
-
Save hqf00342/ad94a916ef1b9a3f493e to your computer and use it in GitHub Desktop.
パフォーマンスカウンターの全カテゴリーを取得
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// パフォーマンスカウンターのカテゴリーリストを表示 | |
/// 値も表示 | |
/// Excelで処理しやすいように1行に全部表示 | |
/// </summary> | |
static void EnumPCCategory2() | |
{ | |
//参考 | |
//http://uchukamen.com/Programming2/PerfMeter2/ | |
//カテゴリー一覧を取得 | |
var cats = System.Diagnostics.PerformanceCounterCategory.GetCategories(); | |
foreach (var cat in cats) | |
{ | |
//Console.WriteLine(cat.CategoryName); | |
//インスタンス一覧 | |
var categoryInstance = new PerformanceCounterCategory(cat.CategoryName); | |
var instanceNameList = categoryInstance.GetInstanceNames(); | |
foreach (var instanceName in instanceNameList) | |
{ | |
//Console.WriteLine(" " + instanceName); | |
//カウンター一覧。見つからずに例外があるのでtry{} | |
try | |
{ | |
var counterList = categoryInstance.GetCounters(instanceName); | |
foreach (var counter in counterList) | |
{ | |
//Console.WriteLine(" " + counter.CounterName); | |
Console.WriteLine("{0}\t{1}\t{2}\t{3}", | |
cat.CategoryName, | |
instanceName, | |
counter.CounterName, | |
counter.NextValue()); | |
} | |
} | |
catch { } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment