我想用PerformanceCounter来检索Windows上的一些性能细节。我使用了PerformanceCounterCategory.GetCategories方法,并从链接中运行示例代码,该链接提供了运行的计算机上可用的所有类别名称。找出有关PerformanceCounter的信息
我从BlackWasp.co.uk运行代码,演示了如何在示例代码中使用PerformanceCounter。
我缺少的是constructor需要至少两个字符串作为参数counterCategory和counterName。我可以从PerformanceCounterCategory.GetCategories中获得计数器类别,但是如何设置名称?
我明白了,我应该使用PerformanceCounterCategory.Create(...)来设置名称,但是如何将它与我想要监视的指定行为(如磁盘读取等)联系起来呢?
的示例代码:
Console.WriteLine("Creating Inventory custom counter");
if (!PerformanceCounterCategory.Exists("Inventory"))
PerformanceCounterCategory.Create("Inventory",
"Truck inventory",
PerformanceCounterCategoryType.SingleInstance,
"Trucks", "Number of trucks on hand");
这种让我在黑暗中,我不知道在哪里“卡车库存”或“卡车”从何而来。
任何人都可以指向正确的方向吗?有没有更好的方法来进行性能监控?
那么如何创建一个性能计数器并将其与有意义的硬件性能联系起来呢?
http://social.msdn.microsoft.com/Forums/en-US/37b8b63a-da32-4497-b570-3811a2255dee/how-to-得到-磁盘IO-countersdisk写时间磁盘读出时间 - 使用 - CNET?论坛= csharplanguage – Andreas
性能计数器必须先注册。并且需要有*某种类型的应用程序来设定它们的价值。只有这样你才能期望能够阅读这样的计数器。你的问题并没有暗示你照顾到了这些初步步骤。 –