Simpleperf
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android Studio 包含 Simpleperf 的图形前端,记录在使用 CPU 性能分析器检查 CPU 活动中。大多数用户更喜欢使用该图形前端,而不是直接使用 Simpleperf。
如果您更喜欢使用命令行,可以直接使用 Simpleperf。Simpleperf 是一个通用的命令行 CPU 性能剖析工具,包含在面向 Mac、Linux 和 Windows 的 NDK 中。
如需查看完整的文档,请先阅读 Simpleperf 自述文件。
Simpleperf 提示与诀窍
如果您刚开始使用 Simpleperf,不妨试试以下一些特别实用的命令。如需了解更多命令和选项,请参阅 Simpleperf 命令和选项参考。
查找执行时间最长的共享库
您可以运行此命令来查看哪些 .so
文件占用了最大的执行时间百分比(基于 CPU 周期数)。启动性能分析会话时,首先运行此命令是个不错的选择。
$ simpleperf report --sort dso
查找执行时间最长的函数
当您确定占用最多执行时间的共享库后,就可以运行此命令来查看执行该 .so
文件的函数所用时间的百分比。
$ simpleperf report --dsos library.so --sort symbol
查找线程中所用时间的百分比
.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 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-22。
[[["易于理解","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"]],["最后更新时间 (UTC):2024-08-22。"],[],[],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**."]]