2012-06-12 38 views
2

我在使用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應用程序啓動並嘗試讀取從性能監視器計數器運行。

回答

1

什麼是我的樣品確切的問題,我不能完全肯定,但有與Microsoft Windows SDK的微軟例如針對Windows 7和.NET Framework 3.5 SP1:

http://www.microsoft.com/en-us/download/confirmation.aspx?id=3138

istalling MS SDK後樣本位於:

C:\ Program Files文件\微軟的SDK \的Windows \ V7.0 \樣本\勝基\ PerfCounters \基本\ CPP

應當適用於Windows 7的(ctrcpp具有較少的參數,和Per使用fAutoInitialize()和PerfAutoCleanup()代替CounterInitialize()和CounterCleanup())。

它應用程式從perfmon的加法計數器崩潰,請參閱: Perflib 2 crashes when adding a counter (from Perfmon)

0

我知道這個問題已經回答了,但我打的是同樣的問題,它是由我忘記包括生成的.RC文件引起變成可執行當我用stringtable重新編譯包含.RC文件的可執行文件時,unlodctr ed和lodctr編輯了模式文件,它開始工作。

3

爲什麼有註冊您的PerfCounter提供商將失敗的幾個原因:

  • 檢查清單文件的模式是有效的。您可以使用XSD definition file provided by Microsoft來驗證文件。

  • 如果您想檢查,請使用lodctr工具註冊清單。確保以管理員身份運行lodctr工具。如果你的權利不夠充分,它將會失敗。一旦你的清單被註冊,你應該能夠在PerfCounter對話框中看到CounterSet的GUID。 (一個工具,可以列出提供商見Browsing Performance Counters。)

GUID Displayed in the PerfCounter browser dialog

  • 你必須同時生成的頭文件和資源文件(使用ctrpp-rc-o選項)。資源文件必須添加到您的解決方案中。

  • 構建應用程序,然後同時具有清單文件,並在當前目錄您的.exe都重新運行lodctr工具。確保清單文件指向二進制文件中提供的applicationIdentity屬性的文件名:

    <provider symbol="MyProvider" applicationIdentity="PerfCounterTest.exe" providerName="PerfCounterTest"

  • 運行應用程序。當應用程序正在運行,你應該能夠看到在瀏覽器對話框中輸入供應商的名字:

enter image description here

+0

我還必須提到的是64位permon.exe將加載只有64位的定製計數器進程正在運行。我正在調試/運行一個32位,但它沒有加載。我試着用SysWow64 \ perfmon,它工作! – Ajay