进程计数器的奇怪行为

发布于 2024-08-08 22:27:31 字数 1001 浏览 2 评论 0原文

我们有一个 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 是不同的。

  1. 是.Net的bug吗?

  2. 我应该使用什么计数器(来自.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.

  1. Is it bug of .Net?

  2. What counter(Process ID from .Net Clr Memory or ID Process from Process category) should I use to get right Instance name?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文