繼承

Windows Performance Recorder (WPR) 錄製設定檔會儲存在副檔名為 .wprp 的 XML 檔案中。 WPR 支援在 WPR 設定檔 XML 架構中使用 Base=「」 屬性繼承其物件。 繼承可讓您保留、重複使用及建置在常見的設定檔定義上,以記錄特殊案例。 例如,您可以將提供者新增至現有的設定檔,藉此變更緩衝區大小,而不改變實際設定檔中的定義。

重要 當您撰寫 WPRP 設定檔時,應該從 WPR 的內建基底設定檔繼承設定檔資料,或重複使用相同的會話名稱,以避免多次啟用相同的提供者。

基底設定檔

您可以使用 XML 標記來變更設定檔的內容。 您必須使用 Operation 屬性。 Operation屬性的可能值為SetAdd。 在下列範例中,DerivedProfile會將ReadyThread系統關鍵字新增至BaseProfile所定義的CpuConfigCSwitchSampledProfile關鍵字。

<SystemCollector
  Id="BaseSystemCollector" ... />

<SystemProvider
  Id="MainSystemProvider">
  <Keywords>
    <Keyword
      Value="CpuConfig"/>
    <Keyword
      Value="CSwitch"/>
    <Keyword
      Value="SampledProfile"/>
  </Keywords>
</SystemProvider>

<SystemProvider
  Id="AnotherSystemProvider">
  <Keywords> 
    <Keyword
      Value="ReadyThread"/>
  </Keywords>
</SystemProvider>

<Profile
  Id="BaseProfile"...>
  ... 
  <Collectors>
    <SystemCollectorId
      Value="BaseSystemCollector">
      <SystemProviderId
        Value="MainSystemProvider"/>
    </SystemCollectorId>
  </Collectors>
</Profile>

<Profile
  Id="DerivedProfile"
  Base="BaseProfile"...>
... 
  <Collectors Operation="Add"> <!--Use "Add" operation to add new provider to an existing one. -->
    <SystemCollectorId
      Value="BaseSystemCollector">
      <SystemProviderId
        Value="AnotherSystemProvider"/> <!--Specify provider to add. --> 
    </SystemCollectorId> 
  </Collectors>
</Profile>

注意 如果您未指定 Operation 屬性,但使用繼承,WPR 會使用預設值 Set

範例

下列範例會定義檔案記錄模式的設定檔。 記憶體版本繼承自檔案版本,並只會覆寫記錄模式。

<Profile
   Id="SampleProfile.Verbose.File"
   LoggingMode = "File"
   DetailLevel = "Verbose"
   Name = "SampleProfile"
   Description = "A sample profile">
   …

</Profile>

<Profile
   Id="SampleProfile.Verbose.Memory"
   Base="SampleProfile.Verbose.File”
   LoggingMode = "Memory"
   DetailLevel = "Verbose"
   Name = "SampleProfile"
   Description = "A sample profile"/>

繼承最佳做法

架構不佳的繼承可能會產生非預期的結果。 我們建議您只從收集器衍生收集器,或從設定檔衍生設定檔。 您絕對不應該將衍生結合到多個物件類型。

下列三個範例描述使用繼承的兩個好方法;第三個範例描述繼承的使用不佳。

範例 1:良好使用繼承

您想要使用事件收集器 A 的規格,並進行一些修改。 若要這樣做:

  1. 定義從 Collector-A 繼承其規格的第二個收集器 (Collector-B) 。

  2. 修改收集器-B。

  3. 將設定檔設定為參考 Collector-B。

這是很好的作法,因為只有收集器物件會從另一個收集器物件繼承屬性,然後由設定檔直接參考。

範例 2:良好的繼承使用

  1. Profile-A 參考收集器 A。

  2. Profile-B 會從 Profile-A 繼承屬性。

  3. 您可以在 Profile-B 中修改特定屬性。

這是很好的作法,因為只有設定檔物件衍生自另一個設定檔物件。

範例 3:繼承的使用不佳

  1. Profile-A 參考收集器 A。

  2. Collector-B 繼承自 Collector-A。

  3. Profile-B 繼承自 Profile-A,也參考 Collector-B。

在此情況下,Profile-B 會參考 Collector-B 兩次:一次透過 Profile-A 繼承,一次直接參考 Collector-B。 在此情況下,不清楚應該如何評估 Collector-B 的定義;也就是說,衍生應該優先于哪一個。 此範例會因為排序未定義而造成不良做法,因此可能會根據作業順序而產生衝突的結果。 應避免這種繼承。

撰寫錄製設定檔

WPRControlProfiles 結構描述