进程计数器的奇怪行为
我们有一个 Web 应用程序,其中使用了一些性能计数器。对于同时运行多个应用程序的情况,我们有用于确定当前实例名称的代码:
int processId = GetProcessID();
PerformanceCounterCategory processCategory = new PerformanceCounterCategory("Process");
string[] runnedInstances = processCategory.GetInstanceNames();
foreach (string runnedInstance in runnedInstances){
using (System.Diagnostics.PerformanceCounter performanceCounter =
new System.Diagnostics.PerformanceCounter("Process", "ID Process", runnedInstance, true)){
if ((int)performanceCounter.RawValue == processId){
return runnedInstance;
}
}
}
此代码工作正常,但不久前我们添加了对 .Net CLR 类别中的两个计数器的支持。我们发现它们在进程 ID 和实例名称之间有不同的匹配:alt text http:// /img26.imageshack.us/img26/9876/perfmon.png
因此,.Net Clr 内存和进程类别的一个实例名称的进程 ID 是不同的。
是.Net的bug吗?
我应该使用什么计数器(来自.Net Clr内存的进程ID或来自进程类别的ID进程)来获取正确的实例名称?
什么
We have web application in which we are using some performance counters. For cases when there are more then one application run simultaneously we have code for determining current instance name:
int processId = GetProcessID();
PerformanceCounterCategory processCategory = new PerformanceCounterCategory("Process");
string[] runnedInstances = processCategory.GetInstanceNames();
foreach (string runnedInstance in runnedInstances){
using (System.Diagnostics.PerformanceCounter performanceCounter =
new System.Diagnostics.PerformanceCounter("Process", "ID Process", runnedInstance, true)){
if ((int)performanceCounter.RawValue == processId){
return runnedInstance;
}
}
}
This code works fine but some time ago we added in our support of two counters from .Net CLR category. And as we discovered they have different match between process id and instance name:alt text http://img26.imageshack.us/img26/9876/perfmon.png
So Process Id's are differs for one instance name for .Net Clr Memory and Process category.
Is it bug of .Net?
What counter(Process ID from .Net Clr Memory or ID Process from Process category) should I use to get right Instance name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论