定義工作和 Opcode

提供者會使用工作和作業碼,以邏輯方式將事件分組。 群組事件可協助取用者只查詢包含特定工作和 opcode 組合的事件。 一般而言,您會使用工作來識別提供者的主要元件,例如網路或資料庫元件。 然後,您可以使用 opcode 來識別元件執行的作業,例如網路元件的傳送和接收作業。 如果您只有一個元件,您可以使用工作來反映元件中的主要作業,例如連線或中斷連線,並使用 opcode 來反映作業內的活動,例如讀取登錄。 您也可以使用 opcode 而不指定工作。 如何使用工作和 opcode 來為取用者分組事件,完全由您決定。

若要定義工作,請使用 工作 元素。 若要定義 opcode,請使用 opcode 元素。 您可以指定最多 228 個 opcode。 工作 必須大於 0。 Opcode 的範圍必須介於 10 到 239。 Winmeta.xml檔案會定義您可以使用的一般作業,而不是自行定義。

下列範例示範如何定義數個工作和作業碼。

<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)">

                . . .

                <tasks>
                    <task name="Disconnect" 
                          symbol="TASK_DISCONNECT"
                          value="1"
                          message="$(string.Task.Disconnect)"/>
 
                    <task name="Connect" 
                          symbol="TASK_CONNECT"
                          value="2"
                          message="$(string.Task.Connect)">
                    </task>

                    <task name="Validate" 
                          symbol="TASK_VALIDATE"
                          value="3"
                          message="$(string.Task.Validate)">
                    </task>
                </tasks>

                <opcodes>
                    <opcode name="Initialize" 
                            symbol="OPCODE_INITIALIZE" 
                            value="12"
                            message="$(string.Opcode.Initialize)"/>

                    <opcode name="Cleanup" 
                            symbol="OPCODE_CLEANUP" 
                            value="13"
                            message="$(string.Opcode.Cleanup)"/>
                 </opcodes>

                . . .

            </provider>
        </events>
    </instrumentation>

    <localization>
        <resources culture="en-US">
            <stringTable>
                <string id="Provider.Name" value="Sample Provider"/>
                <string id="Task.Disconnect" value="Disconnect"/>
                <string id="Task.Connect" value="Connect"/>
                <string id="Task.Connect.ReadRegistry" value="ReadRegistry"/>
                <string id="Task.Validate" value="Connect"/>
                <string id="Task.Validate.GetRules" value="GetRules"/>
                <string id="Opcode.Initialize" value="Initialize"/>
                <string id="Opcode.Cleanup" value="Cleanup"/>
            </stringTable>
        </resources>
    </localization>

</instrumentationManifest>