Version: 2019.2
プロファイラー概要
アプリケーションのプロファイリング

Getting started with the Profiler window

Unity Profiler (プロファイラー) にアクセスするには、Window > Analysis > Profiler に移動するか、キーボードショートカット Ctrl+7 (macOS では Command+7 ) を使用します。

プロファイラーは、アプリケーションパフォーマンスの複数の領域を記録し、その情報を表示します。この情報を使用して、アプリケーションで何を最適化する必要があるかについて十分な情報に基づいた決定を行い、最適化によって期待する結果が得られることを確認できます。

The Profiler records and keeps the last 300 frames of your game, and shows you detailed information about every frame. You can inspect script code, and how your application uses certain Assets and resources that might be slowing it down. You can also compare how your application performs on different devices.

The Profiler has several different Profiler modules that you can add to your profiling session to get more information on areas such as rendering, memory, and audio.

このページでは、以下のトピックについて説明します。

Profiler window layout

Profiler ウィンドウは以下のようにレイアウトされています。

  • A: Profiler controls. Use these controls to set which device to profile from and what kind of profiling Unity should perform, navigate between frames, and start recording data.
  • B: Context menu. Use this to select Color Blind mode.
  • C: Profiler modules. This is a list of all the modules you can profile in your application. Use the drop-down menu at the top of this area to add modules to the window.
  • D: Frame charts. This area contains charts of each module the Profiler profiles. This area is blank when you open the Profiler for the first time, and fills with information when you start profiling your application.
  • E: Module details panel. The information in this area of the window changes based on the module you have selected. For instance, when you select the CPU Usage Profiler module, it contains a detailed timeline and the option to switch to a Hierarchy view. When you select the Rendering Profiler module, this area displays a list of debugging information. This area is blank when you open the Profiler for the first time, and fills with information when you start profiling your application.

Profiler controls

プロファイラーのコントロールは、Profiler ウィンドウ上部のツールバーにあります。これらを使用して、 プロファイラーデータのレコーディングを開始または停止し、プロファイリングされたフレームをナビゲートします。

コントロール 機能
レコーディング これをクリックすると、アプリケーションの実行時にアクティブなモジュールのプロファイリング情報が記録されます。このボタンを有効にしないと、アプリケーションを実行してもプロファイラーはデータを収集しません。
Deep Profile すべての C# メソッドをプロファイリングするには、この設定を有効にします。この設定を有効にすると、Unity はすべての mono 呼び出しにインストルメンテーションを加えます。これにより、スクリプトのより詳細な調査が可能になります。詳細は ディーププロファイリング を参照してください。
Profile Editor Enable this setting to profile the Unity Editor. This displays the resources that the Editor is currently using. Click the button again to stop profiling the Editor.
プロファイリングターゲット Select which target to profile your application on. By default, this is set to Editor, which refers to the Unity Editor. Unity also automatically detects any devices that are running on your network or connected via USB, and displays them in the drop-down. Click Enter IP in the drop-down to manually enter the IP address of the device you want to profile your application on. For more information, see Profiling your application.
Allocation Callstacks To record call stacks for scripting memory allocations, click this drop-down and select Managed Allocations. Frames that the Profiler records when you enable this option have information in the GC.Alloc samples on the full call stack that lead to a managed scripting allocation, even when Deep Profile is not active. For more information, see the Allocation Callstacks section of the CPU Usage Profiler module page.
Clear on Play これを有効にすると、次に Player ウィンドウで再生ボタンをクリックしたとき、または新しいターゲット デバイスに接続したときに、Profiler ウィンドウからすべてのデータが消去されます。
Clear Profiler ウィンドウからすべてのデータを消去します。
ロード 保存したプロファイラーデータを Profiler ウィンドウにロードします。プレイヤーが Profiler.logFile API を通してファイルに書き出したバイナリプロファイルデータをロードすることもできます。

Shift ボタンを押しながら Load ボタンをクリックすると、ファイルのコンテンツを現在のプロファイルフレームに追加できます。
保存 プロファイラーデータを Project フォルダーの .data ファイルに保存します。
Transport controls Use these controls to navigate around the Profiler charts. If you are profiling in Play mode and you click on any of these transport controls while your application is running, your application pauses.
Frame number 現在プロファイラーで表示しているフレームの番号を示します。
Back arrow 1 フレーム前に戻ります。
Forward arrow 1 フレーム先に進みます。
Current Jump to the last recorded frame and make the Profiler display data collected in real time.

オーバーヘッドを低く維持するために、Unity はエディター UI の 5 フレームごとに再描画します。これにより、少しぎこちない更新になります。

詳細プロファイリング

通常、プロファイラーは、ProfilerMarkers に明示的に包まれているコード部分をプロファイリングします。これには、エンジンのネイティブ コードからスクリプトコードへの呼び出し (例えば、MonoBehaviourStartUpdate、または類似のメソッドなど) の最初のコールスタックの深さが含まれます。

独自のコードにさらに明示的な ProfilerMarker インストルメンテーションを加えなくても、スクリプトコードの子サンプルとして表示できる他のサンプルは、その API がインストルメント化されている場合に、Unity の API にコールバックできるサンプルのみです。パフォーマンスのオーバーヘッドを伴うほとんどの API 呼び出しはインストルメント化されています。例えば、Camera.main API を通してメインカメラにアクセスすると、FindMainCamera サンプルとして記録されます。

Deep Profile 設定を有効にすると、プロファイラーはスクリプトコードのすべての部分をプロファイリングし、少なくとも最初のコールスタックの深さを含むすべての関数呼び出しを Unity API に記録します。これは、コードがアプリケーションのパフォーマンスに影響を与える箇所を改善するのに役立つ情報ですが、オーバーヘッドが増加します。

When you deep profile your application, Unity injects profiler instrumentation into all of your script methods to record all function calls. This is useful to understand where your application code spends the most time. Because you need to reload the assembly to use Deep Profiling, you need to start the Players with the -deepprofiling command line argument.

ディーププロファイリングはリソースを大量に消費し、多くのメモリを使用します。結果として、プロファイリング中はアプリケーションの実行が著しく遅くなります。ディーププロファイリングは、簡単なスクリプトで動く小さなゲームに適しています。複雑なスクリプトコードを使用している場合、アプリケーションでディーププロファイリングをまったく使用できない場合があります。また、大きなアプリケーションの多くでは、ディーププロファイリングによって Unity のメモリが不足する場合があります。

プロファイラーにサンプルを流すためのリングバッファに保存するには、サンプルが多すぎるという問題が発生した場合、Unity はエラーメッセージを表示します。リングバッファのサイズを増やすには、プロファイリングするプレイヤーの Profiler.maxUsedMemory プロパティーを調整します。

ディーププロファイリングによってアプリケーションのフレームレートが大幅に低下し、実行が不可能にな場合は、スクリプトコードのブロックを手動でプロファイリングできます。これにより、ディーププロファイリングよりオーバーヘッドが小さくなります。ProfilerMarkers を使用して、スクリプトブロックをマークアップするために必要なインストルメンテーションを手動で加えます。これらは CPU Usage プロファイラーモジュール に表示されます。

If you want to find out which call stacks lead to a GC.Alloc sample without Deep Profiling, you can turn on the collection of Allocation Callstacks. When you enable the Managed Allocations setting, you can select the GC.Alloc samples in the Timeline view, or use the Show Related Objects panel in the Hierarchy view to find the call stacks for these samples. For more information, see the documentation on Allocation Callstacks in the CPU Profiler Module page.

Color blind mode

Enable Color Blind Mode to make the Profiler use higher contrast colors in its graphs. This enhances visibility for users with red-green color blindness (such as deuteranopia, protanopia, or tritanopia). To enable it, go to the context menu in the upper-right corner of the Profiler window, and select Color Blind Mode.

Profiler modules

Profiler ウィンドウの上部は、ゲームの特定の領域をプロファイリングする Profiler Modules (プロファイラーモジュール) に分かれています。アプリケーションをプロファイリングすると、Unity は各モジュールに関連するデータを対応するチャートに表示します。

CPU Usage モジュールは、 アプリケーションが各フレームに費やす時間に関する最適な概要を提供します。他のモジュールはより具体的なデータを収集し、より具体的な領域を調べたり、メモリ消費、レンダリング、 オーディオ統計など、 アプリケーションの重要な要素を監視するのに役立ちます。

各モジュールには独自のチャートがあります。任意のモジュールを選択すると、モジュール詳細パネルがウィンドウの下方に表示されます。これを使ってモジュールが収集した詳細なデータを検査できます。

Profiler Modules 機能
CPU Usage 物理演算、スクリプト、アニメーション、ガベージコレクションなど、アプリケーションが最も時間を費やすエリアの概要を表示します。このモジュールには、アプリケーションに関する幅広いプロファイリング情報が含まれています。このモジュールを使用して、 アプリケーションのより具体的な問題を調査するために使用するモジュールを決定できます。このモジュールは、たとえ閉じても常にアクティブです。CPU Usage プロファイラーモジュール を参照してください。
GPU Usage グラフィックス処理に関する情報を表示します。オーバーヘッドが高いため、デフォルトではこのモジュールはアクティブではありません。GPU Usage プロファイラーモジュール を参照してください。
Rendering Unity がアプリケーションでグラフィックスをどのようにレンダリングするかに関する情報を表示します。静的および動的バッチ処理、SetPass と Draw の呼び出し、三角形、頂点などの情報が含まれます。Rendering プロファイラーモジュール を参照してください。
Memory Unity がアプリケーションでメモリをどのように割り当てるかに関する情報を表示します。これは、スクリプティングアロケーション (GC.Alloc) がどのようにガベージコレクションにつながるのか、またはアプリケーションのアセットメモリ使用量の経時的変化を確認するのに特に役立ちます。Memory プロファイラーモジュール を参照してください。
Audio Displays information related to the audio in your application, such as when and how many audio sources play, how much CPU usage the Audio system requires, and how much memory Unity allocates to it. See Audio profiler module.
Video Displays information related to video in your application.
Physics 物理演算エンジンが処理したアプリケーションの物理演算に関する情報を表示します。Physics プロファイラーモジュール を参照してください。
Physics (2D) Physics プロファイラーに似ていて、このモジュールは、物理演算エンジンが処理したアプリケーションの 2D 物理演算に関する情報を表示します。
Network Messages(deprecated) マルチプレイヤー高レベル API によって送受信される低レベルのパケットとメッセージに関する情報を表示します。
ノート: マルチプレイヤー高レベル API は非推奨です。
Network Operations (deprecated) マルチプレイヤー高レベル API によって送受信される低レベルのパケット (SyncVar やコマンドの送信数など) とメッセージに関する情報を表示します。
ノート: マルチプレイヤー高レベル API は非推奨です。
UI Unity がアプリケーションの UI バッチをどのように処理するか (Unity がアイテムをバッチする理由や方法などを含む) に関する情報を表示します。UI プロファイラーモジュール を参照してください。
UI Details UI モジュールと似ており、このモジュールのチャートにはバッチと頂点の数に関するデータと、UI の変更をトリガーするユーザー入力イベントに関する情報を含むマーカーが含まれます。
Global Illumination Unity がアプリケーションのグローバルイルミネーション (GI) ライティングサブシステムに費やす CPU リソースに関する情報を表示します。Global Illumination Profiler ウィンドウ を参照してください。

Profiler module overhead

Some Profiler modules have a large data collection overhead, such as the GPU, UI, and Audio Profiler module. To prevent these modules from affecting your application’s performance, you can click the close button (x) in the top right hand corner of the module to deactivate it. This removes the module from the window, stops the Profiler from collecting that module’s data, and lowers the Profiler’s overhead.

アクティブでないときでも常にデータを収集する CPU Usage モジュールには適用されません。なぜなら、他のモジュールが依存しているためです。

To add a module, select the Add Profiler dropdown and choose the Profiler you want to activate. When you choose a Profiler module from the drop-down, it starts collecting data, but shows no data for the period in which it was not active.

GPU プロファイラーモジュールのオーバーヘッドを避けるために、デフォルトではアクティブではありません。GPU プロファイラーモジュールは、グラフィックスドライバーにフックするために、アプリケーションの開始時にアクティブでなければなりません。後で追加すると、ほとんどのプラットフォームでは効果がなく、プロファイラーに “GPU profiling is not supported by the graphics card driver (or it was disabled because of driver bugs)” (GPU プロファイリングはグラフィックスカードドライバーでサポートされていません。または、ドライバーのバグのため無効でした) というメッセージが表示されます。

Profiler ウィンドウを使わずに Profiler.logFile API を使用してデータを収集しディスクに送信するようにプロファイラーに指示する場合は、 Profiler.SetAreaEnabled() を使用してプロファイラーモジュールをオフにすることができます 。

外部 IDE を通してスクリプトをデバッグする設定の中には、オーバーヘッドが発生するものもあります。このオーバーヘッドを避け、より正確な測定値を得るには、Editor Attaching 設定を無効にします (Preferences > External Tools)。同様に、ビルドプレイヤーをプロファイリングするときは、 Build Settings を開き、 Script Debugging を無効にしてオーバーヘッドを回避します。

Profiler frame charts

The upper part of the Profiler window displays performance data over time on a frame-by-frame basis. When you run your application, the Profiler records data for each frame. The Profiler window displays the history of the last 300 frames it profiles. When you click in the Profiler frame chart area of the Profiler window, a white line appears, which highlights one frame of your application. To navigate between frames, use the transport controls in the toolbar of the Profiler window.

Unity はチャートの垂直方向のスケールを自動的に管理し、チャートはウィンドウの垂直方向のスペースを埋めようとします。チャートの詳細を表示するには、他のプロファイラーモジュールを削除するか、チャートと詳細統計エリアの間の境界線をドラッグして、チャートの画面領域を増やします。

チャートで指標の表示と非表示を切り替えるには、モジュールのラベルの横にある色付きの正方形をクリックします。これは、スパイクの原因を特定するのに役立ちます。CPU Usage プロファイラーのチャートなどの積み上げチャートでは、指標ラベルを並べ替えて、積み上げ順序を変更できます。これにより、ノイズの多い指標をより見やすくすることで、チャートをより明白にすることができます。

各プロファイラーモジュールは、異なるパフォーマンスデータの指標を収集し、別々のチャートに表示します。フレームをクリックすると、Unity は Profiler ウィンドウの下半分のモジュール詳細パネルにフレームの詳細を表示します。このウィンドウの詳細のタイプは、選択するプロファイラーモジュールによって異なります。各モジュールがこのエリアに表示する特定の詳細については、プロファイラーモジュール の個々のドキュメントを参照してください。

Command line arguments

ビルドしたプレイヤーや Unity エディターをコマンドライン (Windows のコマンドプロンプト、macOS のターミナル、Linux シェル、Android の adb など) から起動する場合は、コマンドライン引数を渡してプロファイラーの設定を行うことができます。

コマンドライン引数 説明
-deepprofiling Enable Deep Profiling in a built Player. This only works with Players built against the Mono Scripting Backend.
-profileStartup プレイヤーやエディターの起動をプロファイリングします。プレイヤーでこの引数を使用すると、Build Settings で Autoconnect Profiler オプションを有効にしてプレイヤーをビルドするのと同じ効果があります。

エディターでこの引数を使用すると、エディターの起動時に Profiler ウィンドウでプロファイラー情報の収集と表示を開始します。
-profiler-maxusedmemory デフォルトでは、maxUsedMemory はプレイヤー用に 16MB、エディター用に 256MB です。この引数を使用して、起動時に maxUsedMemory パラメーターをカスタムサイズに設定できます (例えば、-profiler-maxusedmemory 16777216)。サイズはバイト単位で設定します。
プロファイラー概要
アプリケーションのプロファイリング
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961