iOS と Android にはビルトインのプロファイラーが備えられています。ビルトインのプロファイラーは、デバイス上で実行されているゲームからのコンソールメッセージを出力します。これらのメッセージは 30 秒ごとに出力され、ゲームの実行状況の詳細を示します。これらのメッセージの意味を理解することは必ずしも簡単ではありませんが、少なくとも CPU バインドか GPU バインドかを判断し、CPU バインドの場合は、スクリプトコードであるのか、速度を低下させる Mono ガベージコレクションであるかを素早く判断する必要があります。このページの後半に、ビルトインプロファイラーを設定する方法を説明します。
以下は、ビルトインプロファイラーの出力例です。
iPhone/iPad Unity internal profiler stats:
cpu-player> min: 9.8 max: 24.0 avg: 16.3
cpu-ogles-drv> min: 1.8 max: 8.2 avg: 4.3
cpu-waits-gpu> min: 0.8 max: 1.2 avg: 0.9
cpu-present> min: 1.2 max: 3.9 avg: 1.6
frametime> min: 31.9 max: 37.8 avg: 34.1
draw-call #> min: 4 max: 9 avg: 6 | batched: 10
tris #> min: 3590 max: 4561 avg: 3871 | batched: 3572
verts #> min: 1940 max: 2487 avg: 2104 | batched: 1900
player-detail> physx: 1.2 animation: 1.2 culling: 0.5 skinning: 0.0 batching: 0.2 render: 12.0 fixed-update-count: 1 .. 2
mono-scripts> update: 0.5 fixedUpdate: 0.0 coroutines: 0.0
mono-memory> used heap: 233472 allocated heap: 548864 max number of collections: 1 collection total duration: 5.7
すべての時間はミリ秒毎フレームで測定されます。直近 30 フレームの最短時間、最長時間、平均時間を確認できます。
プロパティ | 機能 |
---|---|
cpu-player | ゲームが Unity エンジンの中でコードを実行したり、CPU でスクリプトを実行する時間を表示します。 |
cpu-ogles-drv | OpenGL ES ドライバーのコード実行が CPU 上で消費する時間を表示します。ドローコール、内部レンダリングのステート変更、レンダリングパイプラインセットアップおよび処理する頂点数がドライバーの統計に影響します。 |
cpu-waits-gpu | GPU によるレンダリング完了を待機している CPU のアイドル時間を表示します。もしこの数が 2–3 ミリ秒を超える場合、アプリケーションはフィルレートまたは GPU 処理能力がボトルネックの可能性が高いです。もし値が小さすぎる場合、プロファイルは値の表示をスキップします |
msaa-resolve | アンチエイリアシング処理に要した時間を表示します。 |
cpu-present | OpenGL ES の presentRenderbuffer コマンド実行に要した時間を表示します。 |
frametime | ゲームフレームの総時間を表します。iOS ハードウェアは常に 60Hz のリフレッシュレートにロックされているため、~16.7ms の倍数の時間が得られます。(1000ms/60Hz = 16.7ms) |
プロパティ | 機能 |
---|---|
tris # | レンダリングに送信される三角形の総数を表示します。 |
verts # | レンダリングに送信される頂点の総数を表示します。静的な物体では 10000 以内に抑えればよいですが、たくさんのスキニングされた物体がある場合はもっと低く抑えるべきです。 |
batched | エンジンによりバッチされたドローコール、三角形、および頂点の数を表示します。この数をドローコールと三角形の総数と比較することでシーンがバッチするのに適しているか判断する材料となります。バッチを改善するためにはできる限りマテリアルを共有するべきです。 |
player-detail セクションには、エンジン内部で起こっていることの詳細な内訳が表示されます。
プロパティ | 機能 |
---|---|
physx | 物理エンジンの計算に要した時間を表示します。 |
animation | ボーンアニメーションに要した時間を表示します。 |
culling | カメラの Frustum 外のオブジェクトカリングに要した時間を表示します。 |
skinning | スキンメッシュへのアニメーション適用に要した時間を表示します。 |
batching | 物体のバッチに要した時間を表示します。動的な物体のバッチは静的な物体のバッチより著しく高価です。 |
render | 表示されるオブジェクトのレンダリングに要した時間を表示します。 |
fixed-update-count | このフレームで実行された最小と最大の FixedUpdate の数を表示します。FixedUpdate の数が大きすぎるとパフォーマンスが著しく劣化します。fixed time delta についてよい値を設定するためにいくつかシンプルなガイドラインが ここに あります。 |
mono-scripts セクションにより、Mono ランタイムのコード実行に要した時間について詳細な内訳が表示されます。
プロパティ | 機能 |
---|---|
update | スクリプトのすべての Update() 実行に要した総時間を表示します。 |
fixedUpdate | スクリプトのすべての FixedUpdate() 実行に要した総時間を表示します。 |
coroutines | スクリプトのコルーチン内で要した時間を表示します。 |
mono-memory セクションにより、Mono ガベージコレクターによりメモリ管理がどのように管理されているかの情報がみられます。
プロパティ | 機能 |
---|---|
allocated heap | メモリ使用可能な量を表示します。メモリ割り当ての際に十分なメモリがヒープに残っていない場合、ガベージコレクションが起動されます。もしコレクションの後もまだ十分な空きメモリがない場合、割り当てヒープサイズが大きくなります。 |
used heap | allocated heap のうち、オブジェクトによって使用されている量を表示します。新しいクラスインスタンスを作成するたびに(構造体ではなく)、この数は次のガベージコレクションまで増え続けます。 |
max number of collections | 直近 30 フレームでのガベージコレクションが行われた回数を表示します。 |
collection total duration | 直近 30 フレームでのガベージコレクションの総時間(ミリ秒単位)を表示します。 |
iOS ではデフォルトで無効となっているため、有効化するためには Unity により生成された XCode プロジェクトを開いて、 InternalProfiler.h
ファイルを選択し
#define ENABLE_INTERNAL_PROFILER 0
の行を次のように変更します。
#define ENABLE_INTERNAL_PROFILER 1
XCode メニューで View > Debug Area > Activate Console を選択して、出力コンソール (GDB) を表示して、次にプロジェクトを実行します。Unity は統計情報を 30 フレームごとにコンソールウィンドウに表示します。
Android でこれを有効にするには、Player ウィンドウ (Edit > Project Settings の順に移動し、Player カテゴリを選択) の Enable Internal Profiler (Deprecated) チェックボックスをクリックします。ビルド時に Build Settings の Development Build にチェックが入っていることと、デバイスで実行されている場合は統計が logcat に表示されていることを確認してください。 logcat を表示するには adb か Android Debug Bridge が必要です。いったんそれを取得したら、単にシェルコマンド adb logcat を実行します。
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.