我有一个 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>