Simpleperf
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
CPU プロファイラで CPU アクティビティを調べるに記載があるように、Android Studio には Simpleompf のグラフィカル フロントエンドが含まれています。ほとんどのユーザーは Simpleperf を直接使用せずにグラフィカル フロントエンドを使用します。
コマンドラインの方を好むデベロッパーにとっては、Mac、Linux、Windows 向けの NDK に含まれている Simpleperf は多用途に利用できる便利なコマンドライン CPU プロファイリング ツールです。
ドキュメントの全文を読むには、まず Simpleperf の README をお読みください。
Simpleperf のヒントと手法
Simpleperf を使い始めたばかりの時期に特に便利なコマンドをいくつか紹介します。その他のコマンドとオプションについては、Simpleperf コマンドとオプションのリファレンスをご覧ください。
実行時間が最も長い共有ライブラリを調べる
このコマンドを実行すると、(CPU サイクルの数に基づいて)実行時間に占める割合が最も大きいのはどの .so
ファイルかを調べることができます。パフォーマンス解析セッションを開始した際に最初に実行するコマンドとしておすすめします。
$ simpleperf report --sort dso
実行時間が最も長い関数を調べる
実行時間が最も長い共有ライブラリを特定したら、このコマンドを実行して、その .so
ファイルの関数の実行に要した時間の割合を確認できます。
$ simpleperf report --dsos library.so --sort symbol
スレッドの所要時間の割合を調べる
1 つの .so
ファイルの実行時間を複数のスレッドに分割できます。このコマンドを実行すると、各スレッドの所要時間の割合を確認できます。
$ simpleperf report --sort tid,comm
オブジェクト モジュールの所要時間の割合を調べる
実行時間の大部分を占めるスレッドを見つけたら、このコマンドを使用して、そのスレッドの中で実行時間の最も長いオブジェクト モジュールを特定できます。
$ simpleperf report --tids threadID --sort dso
関数呼び出しの関連性を調べる
コールグラフは、プロファイリング セッション中に Simpleperf が記録したスタック トレースを視覚的に表したものです。
report -g
コマンドを使用してコールグラフを出力すると、他の関数によって呼び出されている関数を調べることができます。これは、関数それ自体が遅いのか、それともその関数が呼び出す別の関数が遅いのかを判断するのに便利です。
$ simpleperf report -g
また、Python スクリプト report.py -g
を使用して、関数を表示するインタラクティブ ツールを起動することもできます。各関数をクリックすると、関数の子の所要時間が表示されます。
Unity でビルドしたアプリのプロファイリング
Unity でビルドしたアプリをプロファイリングする場合は、次の手順でデバッグ シンボルを使用してアプリをビルドします。
- Unity エディタで Android プロジェクトを開きます。
- Android プラットフォームの [Build Settings] ウィンドウで、[Development Build] オプションがオンになっていることを確認します。
- [Player Settings] をクリックして、[Stripping Level] プロパティを [Disabled] に設定します。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2024-08-22 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2024-08-22 UTC。"],[],[],null,["# Simpleperf\n\nAndroid Studio includes a graphical front end to Simpleperf, documented in\n[Inspect CPU activity with CPU Profiler](https://developer.android.com/studio/profile/cpu-profiler).\nMost users will prefer to use that instead of using Simpleperf directly.\n\nIf you prefer to use the command line, Simpleperf is a versatile command-line\nCPU profiling tool included in the NDK for Mac, Linux, and Windows.\n\nFor full documentation, start with the Simpleperf [README](https://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/README.md).\n\nSimpleperf tips and recipes\n---------------------------\n\nIf you are just starting out with Simpleperf, here are some commands that you may find\nparticularly useful. For more commands and options, see\n[Simpleperf command and options reference](/ndk/guides/simpleperf-commands).\n\n### Find which shared libraries take the longest to execute\n\nYou can run this command to see which `.so` files take up the largest percentage of execution\ntime (based on the number of CPU cycles). This is a good first command to run when starting\nyour performance analysis session. \n\n```\n$ simpleperf report --sort dso\n```\n\n### Find which functions take the longest to execute\n\nOnce you have identified which shared library takes most of the execution time, you can run this\ncommand to see the percentage of time spent executing the functions of that `.so` file. \n\n```\n$ simpleperf report --dsos library.so --sort symbol\n```\n\n### Find percentage of time spent in threads\n\nExecution time in a `.so` file can be split across multiple threads. You can run this command to\nsee the percentage of time spent in each thread. \n\n```\n$ simpleperf report --sort tid,comm\n```\n\n### Find the percentage of time spent in object modules\n\nAfter finding the threads where most of the execution time is spent, you can use this command to\nisolate the object modules taking the longest execution time on those threads. \n\n```\n$ simpleperf report --tids threadID --sort dso\n```\n\n### See how function calls are related\n\nA *call graph* provides a visual representation of a stack trace that Simpleperf records during the\nprofiling session.\n\nYou can use the `report -g` command to print a call graph to see what\nfunctions are called by other functions. This is useful to determine if a function is slow by\nitself, or if it's because one or more of the functions it calls are slow. \n\n```\n$ simpleperf report -g\n```\n\nYou can also use the Python script `report.py -g` to start an interactive tool that displays\nfunctions. You can click on each function to see how much time is spent in its children.\n\n### Profiling apps built with Unity\n\nIf you are profiling an app built with Unity, make sure to build the app with\ndebug symbols by following these steps:\n\n1. Open your Android project in the Unity Editor.\n2. In the **Build Settings** window for the Android platform, make sure the **Development Build** option is checked.\n3. Click on **Player Settings** and set the **Stripping Level** property to **Disabled**."]]