PerfCounter元素能够让你利用Windows API注册自己的性能计数器。这里有几个部分一起使用来完成注册:
Your performance DLL -
DLL必须输出Open, Collect, 和 Close 方法。更多细节请参考MSDN。
Performance registry values -
注册表必须包含键值指向你的DLL及其Open, Collect, and Close方法。这些键值由Registry元素创建。
Perfmon INI and H text files -
这些文件包含显示于界面的文字描述。更多细节请参考MSDN。
The RegisterPerfmon custom action -
你可以链接sca.wixlib来确保在MSI中包含定制功能。定制功能调用(Un)LoadPerfCounterTextStrings来注册你的计数器。为了调用自定义功能,在Perfmon.INI文件File元素里创建PerfCounter元素。PerfCounter元素包含唯一一个属性:Name,Name属性应该与注册表、WIX源文件 fragment节和PerfCounter.ini文件中的名称匹配。
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="BinDir">
<Component Id="SharedNative" DiskId="1">
<Registry Id="Shared_r1" Root="HKLM" Key="SYSTEM/CurrentControlSet/Services/MyApplication/Performance" Name="Open" Value="OpenPerformanceData" Type="string" />
<Registry Id="Shared_r2" Root="HKLM" Key="SYSTEM/CurrentControlSet/Services/MyApplication/Performance" Name="Collect" Value="CollectPerformanceData" Type="string" />
<Registry Id="Shared_r3" Root="HKLM" Key="SYSTEM/CurrentControlSet/Services/MyApplication/Performance" Name="Close" Value="ClosePerformanceData" Type="string" />
<Registry Id="Shared_r4" Root="HKLM" Key="SYSTEM/CurrentControlSet/Services/MyApplication/Performance" Name="Library" Value="[!PERFDLL.DLL]" Type="string" />
<File Id="PERFDLL.DLL" Name="MyPerfDll.dll" src="x86/debug/0/myperfdll.dll" />
<File Id="PERFCOUNTERS.H" Name="PerfCounters.h" src="x86/debug/0/perfcounters.h" />
<File Id="PERFCOUNTERS.INI" Name="PerfCounters.ini" src="x86/debug/0/perfcounters.ini" >
<PerfCounter Name="MyApplication" />
</File>
</Component>
</DirectoryRef>
</Fragment>
</Wix>
--------------------------------------------------------------------------------
Sample PerfCounters.ini:
[info]
drivername=MyApplication
symbolfile=PerfCounters.h
[languages]
009=English
004=Chinese
[objects]
PERF_OBJECT_1_009_NAME=Performance object name
PERF_OBJECT_1_004_NAME=Performance object name in Chinese
[text]
OBJECT_1_009_NAME=Name of the device
OBJECT_1_009_HELP=Displays performance statistics of the device
OBJECT_1_004_NAME=Name of the device in Chinese
OBJECT_1_004_HELP=Displays performance statistics of the device in Chinese
DEVICE_COUNTER_1_009_NAME=Name of first counter
DEVICE_COUNTER_1_009_HELP=Displays the current value of the first counter
DEVICE_COUNTER_1_004_NAME=Name of the first counter in Chinese
DEVICE_COUNTER_1_004_HELP=Displays the value of the first counter in Chinese
DEVICE_COUNTER_2_009_NAME=Name of the second counter
DEVICE_COUNTER_2_009_HELP=Displays the current rate of the second counter
DEVICE_COUNTER_2_004_NAME=Name of the second counter in Chinese
DEVICE_COUNTER_2_004_HELP=Displays the rate of the second counter in Chinese
PERF_OBJECT_1_009_NAME=Name of the third counter
PERF_OBJECT_1_009_HELP=Displays the current rate of the third counter
PERF_OBJECT_1_004_NAME=Name of the third counter in Chinese
PERF_OBJECT_1_004_HELP=Displays the rate of the third counter in Chinese
Sample PerfCounters.h:
#define OBJECT_1 0
#define DEVICE_COUNTER_1 2
#define DEVICE_COUNTER_2 4
#define PERF_OBJECT_1 8