我在使用PerflibV2預覽自定義性能計數器時遇到問題。從非託管代碼更新性能計數器
性能監視器通過GUID顯示我的自定義性能計數器組,並且當我想展開它時顯示「無法加載計數器」。
我試圖將自己添加到「Performance Monitor Users」和「Performance Log Users」組中,但沒有成功。
我使用了它,並閱讀了很多MSDN文章,但沒有成功。
有人熟悉這個問題嗎?
以下是我如何創建並添加自定義性能計數器的詳細過程:
我需要創建從我unamanged應用更新的性能計數器。
有,我發現兩種方法:
包裝管理性能計數器API,這是不是一種選擇,因爲它會影響性能;
使用PerflibV2提供所需的功能;
作爲一個測試應用程序,我創建了下面的schema.xml模式描述自定義性能計數器:
<!-- <?xml version="1.0" encoding="UTF-16"?> -->
<instrumentationManifest
xmlns="http://schemas.microsoft.com/win/2004/08/events"
xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<instrumentation>
<counters xmlns="http://schemas.microsoft.com/win/2005/12/counters">
<provider callback = "custom"
applicationIdentity = "PerfCounters.exe"
providerType = "userMode"
providerGuid = "{ab8e1320-965a-4cf9-9c07-fe25378c2a23}">
<counterSet
guid = "{ad36a036-c923-4794-b696-70577630b5cf}"
uri = "Microsoft.Windows.System.PerfCounters.MyCounterSet1"
name = "My LogicalDisk"
description = "This is a sample counter set with multiple instances."
instances = "multiple">
<counter id = "1"
uri = "Microsoft.Windows.System.PerfCounters.MyCounterSet1.MyCounter1"
name = "My Free Megabytes"
description = "First sample counter."
type = "perf_counter_rawcount"
detailLevel = "standard"
defaultScale = "1"/>
</counterSet>
</provider>
</counters>
</instrumentation>
</instrumentationManifest>
並執行:
ctrpp schema.xml
我加入創建的文件到我的測試應用程序,並在我的測試應用程序,大致:
PerfAutoInitialize();
ULONG instanceId = 0;
wchar_t instanceName[] = {'t', 'e', 's', 't', 0};
PPERF_COUNTERSET_INSTANCE b = PerfCreateInstance(hDataSource_schema_1, &CtrSetGuid_schema_1_1, instanceName, instanceId);
我裝櫃配用性能:
lodctr /m:schema.xml
我PerfCounters應用程序啓動並嘗試讀取從性能監視器計數器運行。
我還必須提到的是64位permon.exe將加載只有64位的定製計數器進程正在運行。我正在調試/運行一個32位,但它沒有加載。我試着用SysWow64 \ perfmon,它工作! – Ajay