定義篩選器

提供者可以定義會話用來根據事件資料篩選事件的篩選。 使用層級和關鍵字時,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>