Simpleperf
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android Studio 提供 Simpleperf 的圖形前端,詳情請參閱使用 CPU 分析器檢查 CPU 活動。
大多數使用者偏好使用這個圖形前端,而非直接使用 Simpleperf。
如果您偏好使用指令列,可以使用 Simpleperf。Simpleperf 是一項通用的指令列 CPU 分析工具,Mac、Linux 和 Windows 的 NDK 中皆有提供這項工具。
如需查看完整的說明文件,請先從 Simpleperf README 開始。
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 和/或其關係企業的商標或註冊商標。
上次更新時間: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"]],["上次更新時間: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**."]]