定義篩選
提供者可以定義會話用來根據事件資料篩選事件的過濾器。 使用層級和關鍵詞時,ETW 會判斷事件是否寫入記錄檔。 不過,使用篩選條件,提供者會使用控制會話傳遞給它的篩選數據準則(請參閱 EnableCallback 函式)來判斷它是否將事件寫入該會話。 篩選器僅在 ETW 追蹤會話啟用您的提供者時適用。
一般來說,提供者主要是記錄事件,而工作階段會透過層級和關鍵字來識別其想要的事件類型。 如果提供者為事件類型定義數據篩選,會話就可以用它來根據事件數據篩選掉該事件類型的事件(提供者會定義篩選條件的語意)。 例如,如果您的提供者產生進程事件,您可以定義根據進程標識元篩選進程事件的數據篩選。 然後,工作階段可以將進程標識碼當做篩選數據傳遞至提供者,並只接收該進程標識碼的進程事件。
下列範例示範如何使用 篩選 元素來定義篩選。 您必須指定篩選器的屬性,名稱 和 值;其他屬性是選填的。 如果篩選條件要求會話通過篩選數據,則需要 tid 屬性。
<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>
<events>
<provider name="Microsoft-Windows-SampleProvider"
guid="{1db28f2e-8f80-4027-8c5a-a11f7f10f62d}"
symbol="PROVIDER_GUID"
resourceFileName="<path to the exe or dll that contains the metadata resources>"
messageFileName="<path to the exe or dll that contains the string resources>"
message="$(string.Provider.Name)">
. . .
<filters>
<filter name="Pid"
value="1"
tid="t1"
symbol="FILTER_PID"/>
</filters>
<templates>
<template tid="t1">
<data name="Pid" inType="win:UInt32"/>
</template>
</templates>
. . .
</provider>
</events>
</instrumentation>
<localization>
<resources culture="en-US">
<stringTable>
<string id="Provider.Name" value="Sample Provider"/>
</stringTable>
</resources>
</localization>
</instrumentationManifest>