添加计数器时 Perflib 2 崩溃(来自 Perfmon)

发布于 2024-10-07 12:55:50 字数 1885 浏览 9 评论 0原文

我有一个 C++ 应用程序(在 Win32 下),我需要为其提供性能计数器信息。我正在使用 Perflib v2,因此创建了一个由 CTRPP 处理的清单。

然后,我的提供程序调用 PerfAutoInitialize 和 PerfCreateInstance,没有任何错误。

当我在 Perfmon 中添加计数器时,我的应用程序崩溃了。通过反汇编进行跟踪显示了 perflib 工作线程中调用内部函数 (pcwum.dll) PerfpAddOrRemoveCounter 的代码。这会调用 PerfpValidateCounter,它返回 edi 中的地址;该地址无效,当调用者取消引用它时,应用程序崩溃。

如果我重新启动我的提供程序,计数器在 Perfmon 中仍然可见并正确递增。

清单如下

<instrumentationManifest xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd"
     xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:trace="http://schemas.microsoft.com/win/2004/08/events/trace">
  <instrumentation>
    <counters xmlns="http://schemas.microsoft.com/win/2005/12/counters">
      <provider callback = "custom"
        applicationIdentity = "TPerfStatsCollector.exe"
            providerName = "TPerfstatscollector"
        providerType = "userMode"
        providerGuid = "{33d68436-4cf9-4f58-9976-44b048b072f3}"
        symbol = "symbolGUID">
        <counterSet guid = "{381300a5-3be6-46d8-8615-12d8b259aae4}"
          uri = "A.AxPServer.Counters.Basic"
          name = "Basic counters"
          description = "These are the sample counters"
          instances = "Single"
          symbol = "setGUID">
          <counter id = "1"
            uri = "A.AxPServer.Counters.Basic.Session"
            name = "Sessions"
            description = "Number of sessions"
            type = "perf_counter_rawcount"
            detailLevel = "standard"
            defaultScale = "1">            
          </counter>
        </counterSet>
      </provider>
   </counters>
  </instrumentation>
</instrumentationManifest>

I have a C++ application (under Win32) for which I need to provide performance counter information. I'm using Perflib v2, so have created a manifest which is processed by CTRPP.

My provider then calls PerfAutoInitialize and PerfCreateInstance with no errors.

When I go to add the counter in Perfmon, my application crashes. Tracing through the disassembly shows the code in the perflib worker thread calling the internal function (pcwum.dll) PerfpAddOrRemoveCounter. This calls on to PerfpValidateCounter which returns an address in edi; this address is invalid and when caller dereferences it, the application crashes.

If I restart my provider, the counter is still visible in Perfmon and increments correctly.

Manifest follows

<instrumentationManifest xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd"
     xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:trace="http://schemas.microsoft.com/win/2004/08/events/trace">
  <instrumentation>
    <counters xmlns="http://schemas.microsoft.com/win/2005/12/counters">
      <provider callback = "custom"
        applicationIdentity = "TPerfStatsCollector.exe"
            providerName = "TPerfstatscollector"
        providerType = "userMode"
        providerGuid = "{33d68436-4cf9-4f58-9976-44b048b072f3}"
        symbol = "symbolGUID">
        <counterSet guid = "{381300a5-3be6-46d8-8615-12d8b259aae4}"
          uri = "A.AxPServer.Counters.Basic"
          name = "Basic counters"
          description = "These are the sample counters"
          instances = "Single"
          symbol = "setGUID">
          <counter id = "1"
            uri = "A.AxPServer.Counters.Basic.Session"
            name = "Sessions"
            description = "Number of sessions"
            type = "perf_counter_rawcount"
            detailLevel = "standard"
            defaultScale = "1">            
          </counter>
        </counterSet>
      </provider>
   </counters>
  </instrumentation>
</instrumentationManifest>

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡渣熟男 2024-10-14 12:55:50

我的不好。这是一个 64/32 位问题,我意识到我正在构建一个在 64 位操作系统上运行的 32 位提供程序。当这个问题得到解决后,一切都很好。

My bad. This was a 64/32 bit issue and I realised that I was building a 32 bit provider to run on a 64 bit OS. All works fine when this was straightened out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文