> ## 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 Multiplayer Servers のビルドにアタッチしてグラフィックスとパフォーマンスをデバッグし、出力ログを取得します。

この記事では、プロファイラーをアタッチする方法と、出力ファイルを取得する方法について説明します。プロファイラーは、ゲーム サーバーのグラフィックスおよびパフォーマンスに関する問題をデバッグするために使用されます。dotnet trace や PIX などのツールを使用するには、まず使用するプロファイラーをアップロードする必要があります。次に、ビルドに関連付けると、出力ファイルがログ フォルダーに保存されます。

プロファイラーはパフォーマンスに影響を与える可能性があるため、運用ビルドへのアタッチは推奨されません。
プロファイラーをアタッチする設定は、ビルド作成時に行う必要があります。現在、Game Manager 経由でのプロファイラーのアタッチはサポートされていないため、API を使用してビルドを作成する必要があります。詳細については、[チュートリアル: PowerShell/API を使用したビルドのデプロイ](/services/playfab/multiplayer/servers/deploy-using-powershell-api) を参照してください。

ビルドを作成する際、監視構成の下にアセット参照のフィールドがあります。監視構成にアセット参照を含めてください。アセットが Game Manager でアップロードされていることを確認してください。詳細については、[ビルド概要のアセット管理](/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

- [ゲーム サーバーをデバッグするための直接接続](/ja-jp/services/playfab/multiplayer/servers/directly-debugging-game-servers.md)
- [Visual Studio でのプロファイルガイド付き最適化](/ja-jp/tools/tools-console/pgo/pgo_full.md)
- [FMA XR-112: 起動時および再開時のユーザーとコントローラー](/ja-jp/publishing/certification/fma/xr-112.md)
- [FMA: XR-047 ユーザープロファイルへのアクセス](/ja-jp/publishing/certification/fma/xr-047.md)
- [Visual Studio を使用した XBOX プロジェクトのデバッグ](/ja-jp/tools/tools-console/visualstudio/debugging-with-visualstudio.md)
