> ## 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.

# 附加分析工具

> 將 dotnet trace 或 PIX 等分析工具附加至 PlayFab 多人遊戲伺服器組建，以對圖形和效能進行偵錯，並擷取產生的輸出記錄。

本文說明如何附加分析工具，以及如何取得輸出檔案。分析工具可用來協助對遊戲伺服器的圖形和效能問題進行偵錯。若要使用 dotnet trace 或 PIX 等工具，您需要先上傳您選擇的分析工具。接著將其與組建建立關聯，輸出檔案就會放入您的記錄資料夾中。

不建議將分析工具附加至生產組建，因為這可能會影響效能。
附加分析工具的設定需要在建立組建時完成。我們目前不支援透過 Game Manager 附加分析工具，因此您需要使用我們的 API 建立組建。如需詳細資訊，請參閱[逐步解說：使用 PowerShell/API 部署組建](/zh-TW/services/playfab/multiplayer/servers/deploy-using-powershell-api)。

建立組建時，監視設定下有一個資產參考欄位。請在監視設定中包含資產參考。確定您的資產已在 Game Manager 中上傳。若要深入了解，請參閱[在組建概觀中管理資產](/zh-TW/services/playfab/multiplayer/servers/build-overview)。

對於 Linux 伺服器，以下是分析工具執行指令碼的範例。

```Bash Script theme={null}
sighdl()
{
    #This is the folder the monitoring output should be written to.
    monitoring_folder_path = "${PF_MONITORING_LOG_FOLDER}"

    #Code to end monitoring and copy the output 

    exit 0
}

#set up the trap function to catch the signals and exit gracefully
trap sighdl SIGKILL SIGINT SIGTERM
sleep 3600
```

對於 Windows 伺服器，以下是分析工具執行指令碼的範例。

```PowerShell theme={null}
#Sample function that checks for the sentinel file's existence in order to end.
function Check_Sentinel_File()
{
    $fullPath = $Env:PF_SENTINEL_FILE
    while(!(Test-Path $fullPath)) { Start-Sleep 10}

    #PF_MONITORING_LOG_FOLDER contains the log folder where the monitoring output should be saved
    
    $outputPath = "{0}/{1}" -f $Env:PF_MONITORING_LOG_FOLDER, "output.txt"
    "I've died!" | Out-File $outputPath 
}

Check_Sentinel_File
```

* 請務必將輸出儲存在 **PF\_MONITORING\_LOG\_FOLDER** 環境變數所設定的資料夾內，以確保您的輸出會被儲存。
* 伺服器封存後，您可以下載記錄，並在其中找到名為 **PlayfabProfilingOutput** 的資料夾。其中會包含您在執行指令碼中寫入的內容，以及任何標準輸出和錯誤。


## Related topics

- [直接連線以對遊戲伺服器進行偵錯](/zh-TW/services/playfab/multiplayer/servers/directly-debugging-game-servers.md)
- [XBOX 服務追蹤分析器 (XblTraceAnalyzer.exe)](/zh-TW/tools/tools-services/live-trace-analyzer.md)
- [Godot 與社群引擎總覽](/zh-TW/paths/community-engines/overview.md)
- [Play Anywhere(主機 + PC)總覽](/zh-TW/paths/play-anywhere/overview.md)
- [XBOX Series X|S 總覽](/zh-TW/paths/series-xs/overview.md)
