Perflib 2 crashes when adding a counter (from Perfmon)

杀马特。学长 韩版系。学妹 提交于 2019-12-11 13:42:06

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/4431372/perflib-2-crashes-when-adding-a-counter-from-perfmon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!