ターゲットのリリースプラットフォームでアプリケーションのプロファイリングを行うには、ターゲットデバイスをネットワークに接続するか、ケーブルで直接コンピューターに接続します。また、Unity エディターでアプリケーションを直接プロファイリングして、 アプリケーション開発中のおおよそのプロファイリング結果を確認することもできます。
アプリケーションは開発ビルドとしてのみプロファイルできます。これを設定するには、Build Settings (File > Build Settings) に移動し、アプリケーションのターゲットプラットフォームを選択します。Development Build 設定を有効にします。この設定を有効にすると、プロファイラーに関連する 2 つの設定 Autoconnect to Profiler と Deep Profiling Support が使用可能になります。
Autoconnect Profiler 設定を有効にすると、Unity エディターはビルド処理中にビルドプレイヤーに IP アドレスをベイクします。プレイヤーを起動すると、ベイクした IP アドレスのエディターのプロファイラーに接続を試みます。
さらに、Deep Profiling Support 設定を有効にすると、ビルドされたプレイヤーの起動時に Unity が ディーププロファイリング を実行します。これは、アプリケーションの起動時間を詳細にプロファイルするのに便利です。これは、ビルドにわずかなオーバーヘッドを加えます。
アプリケーションをビルドして実行すると、Profiler ウィンドウの Playmode ドロップダウンにプレイヤーが表示されます。Playmode ドロップダウンには、ローカルネットワーク上で実行されているすべての Unity プレイヤーが表示されます。これらのプレイヤーは、プレイヤーのタイプとプレイヤーを実行しているホスト名 (例えば、iPhonePlayer (Toms iPhone) など) で識別できます。
プレイヤーを選択し、 Record をクリックして、アプリケーションのプロファイリング情報の収集を開始します。Build Settings で Autoconnect to Profiler を有効にすると、アプリケーションの起動時に Unity が自動的にデータの収集を開始します。
アプリケーションの実行中に継続的にデータを収集するには、Player Settings の Run In Background 設定を有効にします (Edit > Project Settings > Player > Resolution and Presentation)。この設定を有効にすると、バックグラウンドでアプリケーションを実行し続ける場合でもプロファイラーはデータを収集します。これを無効にすると、プロファイラーは、 アプリケーションがアクティブなウィンドウで実行されている場合にのみデータを収集します。
Profiler ウィンドウを使用してエディターでアプリケーションの実行とプロファイリングを行う場合、結果は、ターゲットプラットフォームで実行したときのアプリケーションの動作の近似にすぎません。再生モードはエディターと同じプロセスで実行されるため、アプリケーションの CPU、GPU、メモリ使用を Unity から完全に分離することはできません。これにより、結果のプロファイリングデータがさらに歪められます。
より適切なプロファイリング結果を得るには、常にターゲットデバイスでアプリケーションをプロファイルする必要があります。すでにデバイス上で特定された問題を素早く繰り返す目的にのみ、エディターでのプロファイリングを行ってください。
WebGL でも Unity プロファイラーを使用できますが、エディターを使用して WebGL を実行しているプレイヤーにアタッチすることはできません。これは、WebGL は WebSockets を通信に使用しているため、ブラウザー側の受信を許可しないためです。実行中のプレイヤーにアタッチするには、Build Settings の Autoconnect Profiler チェックボックスを有効にする必要があります (File > Build Settings)。Unity は WebGL のドローコールをプロファイルできません。
iOS デバイスと Android デバイスはどちらも、ネットワークを通じてリモートプロファイリングをサポートしています。ファイアウォールを使用している場合は、ファイアウォールの設定でポート番号 54998 から 55511 が開放されていることを確認します。これらは、Unity がリモートプロファイリングに使用するポートです。
ノート: リモートプロファイリングを設定すると、Unity エディターがデバイスに自動接続しない場合があります。これが発生した場合は、手動でプロファイラーの接続を開始できます。これを行うには、Profiler ウィンドウの Playmode ドロップダウンで適切なデバイスを選択します。
ターゲットデバイスを直接コンピューターに接続して、ネットワークや接続の問題を回避することもできます。
iOS デバイスでリモートプロファイリングを有効にするには、以下の手順を実行します。
Android デバイスは、Wi-Fi と Android Debug Bridge (adb) の 2 種類のリモートプロファイリング方法をサポートしています。
Wi-Fi プロファイリングは、以下の手順で行います。
ノート: デバイスの検出が正常に機能するためには、Android デバイスとホストコンピューター (Unity エディターを実行中) は、両方とも同じサブネット上になければなりません。
Android Debug Bridge (adb) プロファイリングは、以下の手順で行います。
Build & Run を選択すると、Unity エディターはアプリケーションのために自動的に adb トンネルを作成します。別のアプリケーションをプロファイルしたい場合や adb サーバーを再起動した場合は、このトンネルを手動で設定できます。これを行うためには、ターミナル/コマンドウィンドウを開き、次のコマンドを入力します。
adb forward tcp:34999 localabstract:Unity-{insert bundle identifier here}
Android ビルドでディーププロファイリングを使用するには、Android Player Settings (Edit > Project Settings > Player > Android > Other Settings) で Mono Scripting Backend 設定を有効にし、以下を入力して adb コマンドでゲームを開始します。
~$ adb shell am start -n {insert bundle identifier here}/com.unity3d.player.UnityPlayerActivity -e 'unity' '-deepprofiling'
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.