> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用時間擷取分析 PIX 事件的關鍵路徑

> 使用時間擷取分析 PIX 事件的關鍵路徑

PIX 會分析[時間擷取](/zh-TW/tools/tools-console/pix/new-timing-captures)期間收集的內容切換資料，以計算所選 PIX 事件的關鍵路徑。關鍵路徑是一系列的 PIX 事件與相依性，若加以縮短，就能減少所選事件的整體持續時間。

下圖顯示名為 *MainLoop 17864* 的 PIX 事件，該事件中間包含大量的停滯時間。

<img src="https://mintcdn.com/microsoft-4404708b/cbgdF-D3rUKJ-fFH/images/gdk/tools/pix_critical_path_stalled_event.png?fit=max&auto=format&n=cbgdF-D3rUKJ-fFH&q=85&s=a878c79ae1382e89e0bbb12e718cf466" alt="具有明顯停滯的 PIX 事件" width="664" height="245" data-path="images/gdk/tools/pix_critical_path_stalled_event.png" />

藉由計算關鍵路徑，PIX 會提供減少事件內停滯時間或完全消除停滯所需的資訊。若要計算關鍵路徑，請以滑鼠右鍵按一下 PIX 事件，然後從操作功能表中選擇 **Calculate Critical Path for Selected PIX Event**，如下圖所示。一次只能計算一個事件的關鍵路徑。

<img src="https://mintcdn.com/microsoft-4404708b/cbgdF-D3rUKJ-fFH/images/gdk/tools/pix_critical_path_context_menu.png?fit=max&auto=format&n=cbgdF-D3rUKJ-fFH&q=85&s=96c294b156eee78e3238401cb7ae3b4f" alt="為 PIX 事件建立關鍵路徑的操作功能表項目" width="823" height="389" data-path="images/gdk/tools/pix_critical_path_context_menu.png" />

PIX 會在名為 *Critical Path:* 後接事件名稱的新通道中顯示事件的關鍵路徑。關鍵路徑通道會在停滯時間中填入該期間執行了哪些 PIX 事件、執行緒與核心的資訊，這些都是造成停滯的因素。同時也會提供造成事件之間相依性的內容切換與就緒事件資訊。如果 PIX 事件組不足以提供足夠的內容，也可以使用 CPU 取樣來判斷當時執行的內容。下列關鍵路徑通道顯示，在 *MainLoop 17864* 停滯期間，執行了一個 *Loader::Process* 事件執行個體以及數個 *TaskWrapper* 事件執行個體。

<img src="https://mintcdn.com/microsoft-4404708b/cbgdF-D3rUKJ-fFH/images/gdk/tools/pix_critical_path_lane_overview.png?fit=max&auto=format&n=cbgdF-D3rUKJ-fFH&q=85&s=c6d5ae6ec8608e9df5715d1902a2e24d" alt="事件 MainLoop 17864 的關鍵路徑通道" width="1151" height="228" data-path="images/gdk/tools/pix_critical_path_lane_overview.png" />

檢視關鍵路徑通道頂端的執行緒與核心資訊，可以輕鬆看出關鍵路徑如何在執行緒以及它們執行所在的核心之間跳躍。

<img src="https://mintcdn.com/microsoft-4404708b/qucDZYz-Wliyj3GK/images/gdk/tools/pix-critical-path-lane-threads-and-cores.png?fit=max&auto=format&n=qucDZYz-Wliyj3GK&q=85&s=ce021bf8e826520ec4d432e7df6e3647" alt="關鍵路徑窗格頂端的執行緒與核心資訊" width="1164" height="291" data-path="images/gdk/tools/pix-critical-path-lane-threads-and-cores.png" />

關鍵路徑通道包含內容切換與就緒事件資料，可用來判斷是什麼造成各種事件執行。這些資訊加上工具提示中顯示的資料，也可用來判斷事件為何以該順序執行。

在下圖中，時間軸已放大以查看是什麼造成 *Loader::Process* 事件開始執行。選取 *MainLoop 17864* 片段結尾的就緒事件，會在 **Element Details** 檢視中填入事件的描述，包括相關的呼叫堆疊。同時也會繪製關聯箭頭。在此案例中，*Loader::Process* 開始執行是因為它被 *Main Loop 17864* 設為就緒。將滑鼠指標停留在關鍵路徑通道頂端的執行緒指示器上，會顯示工具提示，提供 *LoaderProcess* 所在執行緒的其他資訊，包括其名稱與優先順序。

<img src="https://mintcdn.com/microsoft-4404708b/cbgdF-D3rUKJ-fFH/images/gdk/tools/pix_critical_path_lane_example1.png?fit=max&auto=format&n=cbgdF-D3rUKJ-fFH&q=85&s=383aa443a805cf0149cd583901beae1b" alt="在關鍵路徑通道中分析就緒事件" width="1269" height="710" data-path="images/gdk/tools/pix_critical_path_lane_example1.png" />

再舉一個例子，請考慮 *MainLoop 17864* 接近結尾的順序：*Loader::Process* 的執行結束，接著是一系列 *TaskWrapper* 事件與一個 *DoneWorking* 事件，然後 *MainLoop 17864* 才完成。

選取造成 *TaskWrapper* 系列事件與 *DoneWorking* 事件執行的內容切換，會顯示這些事件執行所在的兩個執行緒都是由 *Loader* 執行緒設為就緒，如下圖所示。

<img src="https://mintcdn.com/microsoft-4404708b/cbgdF-D3rUKJ-fFH/images/gdk/tools/pix_critical_path_lane_example2_context_switch1.png?fit=max&auto=format&n=cbgdF-D3rUKJ-fFH&q=85&s=5c91655cabff1965d2104bc4e3001eba" alt="造成第一個背景工作執行緒執行的內容切換" width="742" height="522" data-path="images/gdk/tools/pix_critical_path_lane_example2_context_switch1.png" />

<img src="https://mintcdn.com/microsoft-4404708b/cbgdF-D3rUKJ-fFH/images/gdk/tools/pix_critical_path_lane_example2_context_switch2.png?fit=max&auto=format&n=cbgdF-D3rUKJ-fFH&q=85&s=d695de9b00d3e603801df84b7d05f358" alt="造成第二個背景工作執行緒執行的內容切換" width="1414" height="501" data-path="images/gdk/tools/pix_critical_path_lane_example2_context_switch2.png" />

即使 *TaskWrapper* 系列事件與 *DoneWorking* 事件在不同的執行緒上執行，關鍵路徑通道仍顯示它們是依序執行，而不是平行執行。將滑鼠指標停留在執行緒指示器上時所顯示的工具提示，說明了兩個執行緒為何無法同時執行。在此案例中，原因是核心爭用。兩個執行緒都在核心 4 上執行，且具有相同的優先順序 (8)。因此，核心爭用是這些事件被序列化的原因。調整核心指派或執行緒優先順序都可以縮短此關鍵路徑。

<img src="https://mintcdn.com/microsoft-4404708b/cbgdF-D3rUKJ-fFH/images/gdk/tools/pix_critical_path_lane_example2_core_contention.png?fit=max&auto=format&n=cbgdF-D3rUKJ-fFH&q=85&s=fcd92ee99feffe9d9ddff007ad90d4bf" alt="核心爭用導致事件依序執行而不是平行執行" width="1512" height="135" data-path="images/gdk/tools/pix_critical_path_lane_example2_core_contention.png" />

只會建立一個關鍵路徑通道。如果關鍵路徑通道已存在，而您選擇分析另一個事件的關鍵路徑，現有關鍵路徑通道的內容會被新事件的關鍵路徑資料取代。

關鍵路徑通道在首次建立時，通常會出現在 **Timeline** 檢視的底部。您可以使用[通道設定](/zh-TW/tools/tools-console/pix/new-timing-captures#lane_config)面板將通道往上移、將其釘選在頂端等。

## 另請參閱

[時間擷取](/zh-TW/tools/tools-console/pix/new-timing-captures)

[PIX](/zh-TW/tools/tools-console/pix/pix)


## Related topics

- [適用於 GDK 遊戲的 XBOX 與 Windows 版 PIX](/zh-TW/tools/tools-console/pix/index.md)
- [NDA 主題目錄 - Microsoft Learn 線上連結](/zh-TW/nda/nda-topic-directory.md)
- [PIX 影片](/zh-TW/tools/tools-console/pix/pix-videos.md)
- [使用 PIX 進行永續性分析](/zh-TW/build/game-principles/sustainability/sustainability-pix-guide.md)
- [PIX GPU 擷取與效能分析](/zh-TW/tools/tools-console/pix/gpu/index.md)
