LoginSignup
11
14

More than 5 years have passed since last update.

[Unity] 実機によるプロファイル

Posted at

Unityのドキュメントビルトインプロファイラーでのパフォーマンス測定のメモです。

まず、(当然ですが)iOS向けにビルドを行います。
するとiOSではデフォルトではプロファイラの出力がオフになっているため、以下のフラグを有効化します。

#define ENABLE_INTERNAL_PROFILER 0

これを

#define ENABLE_INTERNAL_PROFILER 1

に変更します。
すると、Xcodeのコンソールに以下の項目が出力されます。

項目 説明
cpu-player ゲームが Unity エンジンの中でコード実行およびスクリプト実行が CPU 上で消費する時間を表示
cpu-ogles-drv OpenGL ES ドライバのコード実行が CPU 上で消費する時間を表示。ドローコール、内部レンダリングのステート変更、レンダリングパイプラインセットアップおよび処理する頂点数がドライバの統計に影響しますI
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 エンジンによりバッチされたドローコール、三角形、および頂点の数。この数をドローコールおよび三角形の総数と比較することでシーンがバッチするのに適しているか判断する材料となります。バッチを改善するためにはできる限りマテリアルを共有するべきです。
physx 物理エンジンの計算に要した時間
animation ボーンアニメーションに要した時間
culling カメラの Frustum 外のオブジェクトカリングに要した時間
skinning スキンメッシュへのアニメーション適用に要した時間
batching 物体のバッチに要した時間。動的な物体のバッチは静的な物体のバッチより顕著に高価です。
render 表示されるオブジェクトのレンダリングに要した時間
fixed-update-count このフレームで実行された最小および最大の FixedUpdate の数。FixedUpdate の数が大きすぎるとパフォーマンスが著しく劣化します。fixed time delta について良い値を設定するためにいくつかシンプルなガイドラインが ここに あります。

実際の出力例

以下は、自分が今開発中のゲームのシーン0と1での出力の違いです。

ちなみにまだしっかりとした見方は分かっていませんが、シーン0に比べてシーン1のbatchingの数がだいぶ少ないですね。
これはおそらく、バッチ処理がうまく働かず、効率的なドローコールが出せていないのが原因ではないかと思います。

事実、シーン0では 60FPS 出ているのに対し、シーン1では 40FPS くらいしか出ていません。
目下の目標は、シーン1で 60FPS を出すことです。

シーン0

scene0
iPhone Unity internal profiler stats
cpu-player>    min: 13.7   max: 28.1   avg: 17.1
cpu-ogles-drv> min:  0.0   max:  0.0   avg:  0.0
cpu-present>   min:  0.0   max:  0.1   avg:  0.0
frametime>     min: 14.1   max: 29.0   avg: 17.3
batches>       min: 240    max: 240    avg: 240
draw calls>    min: 290    max: 292    avg: 290
tris>          min: 55470  max: 55478  avg: 55470
verts>         min: 61846  max: 61862  avg: 61847
dynamic batching> batched draw calls:  26 batches:   9 tris:  1840 verts:  2140
static batching>  batched draw calls:  26 batches:   9 tris:  1840 verts:  2140
player-detail> physx:  0.4 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.1 render: 15.2 fixed-update-count: 0 .. 1
scripting-scripts>  update:  0.4   fixedUpdate:  0.0 coroutines:  0.0 
scripting-memory>   used heap: 0 allocated heap: 0  max number of collections: 0 collection total duration:  0.0

シーン1

scene1
iPhone Unity internal profiler stats
cpu-player>    min: 12.2   max: 37.5   avg: 22.9
cpu-ogles-drv> min:  0.0   max:  0.0   avg:  0.0
cpu-present>   min:  0.0   max:  0.0   avg:  0.0
frametime>     min: 12.6   max: 37.8   avg: 23.4
batches>       min:  76    max:  79    avg:  77
draw calls>    min: 145    max: 150    avg: 146
tris>          min: 14580  max: 15086  avg: 14934
verts>         min: 17910  max: 18473  avg: 18217
dynamic batching> batched draw calls:   8 batches:   2 tris:    16 verts:    32
static batching>  batched draw calls:   8 batches:   2 tris:    16 verts:    32
player-detail> physx:  0.9 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.0 render: 19.8 fixed-update-count: 0 .. 2
scripting-scripts>  update:  0.6   fixedUpdate:  0.0 coroutines:  0.1 
scripting-memory>   used heap: 0 allocated heap: 0  max number of collections: 0 collection total duration:  0.0
11
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
14