分析 CPU 使用率
利用 Perf,可以分析 Linux 桌面和嵌入式设备上应用程序的 CPU 和内存使用情况。性能分析器使用 Linux 内核捆绑的 Perf 工具,定期拍摄应用程序调用链的快照,并以时间线视图或火焰图的形式将其可视化。
通常,性能分析器需要剖析二进制文件的调试符号。配置文件生成的优化二进制文件带有单独的调试符号,因此可用于剖析。
收集数据
通过以下方式启动 Performance Analyzer 以收集数据:
- 转到Analyze >Performance Analyzer ,对当前应用程序进行剖析。
- 选择
(Start) 从Performance Analyzer 启动应用程序。
注意: 如果数据收集没有自动启动,请选择 (Collect profile data)。
开始分析应用程序时,应用程序会启动,性能分析器会立即开始收集数据。Recorded 中的运行时间表示了这一点。但是,由于数据是通过 Perf 工具和Qt Creator 中捆绑的额外辅助程序传递的,并且两者都会对数据进行缓冲和处理,因此数据可能会在生成几秒后才到达Qt Creator 。Processing delay 显示了延迟的估计值。
数据将一直收集到您选择 (Stop collecting profile data) 或关闭应用程序为止。
选择Stop collecting profile data 可关闭启动应用程序时自动开始的数据收集。配置文件数据仍会生成,但Qt Creator 会将其丢弃,直到您再次选择该按钮。
剖析设备上的内存使用情况
创建跟踪点以剖析目标设备上的内存使用情况:
- 访问Analyze >Performance Analyzer Options >Create Memory Trace Points 。
- 在Performance Analyzer 工具栏上选择
。
在Create Memory Trace Points 对话框中,修改要运行的脚本。
如果需要 root 权限才能以根用户身份运行脚本,请在Elevate privileges using 中选择要使用的权限。
选择OK 运行脚本。
要为跟踪点添加事件,请参阅选择事件类型。
记录内存跟踪以查看时间线样本行中的使用情况图,并查看火焰图中的内存分配、峰值和释放情况。
为 qmake 项目生成单独的调试信息
要手动设置编译配置,使为发布而编译的应用程序也能生成调试符号,请编辑 qmake 项目的编译设置:
- 转到Projects >Build Settings 。
- 在Separate debug info 中,选择Enable 。
- 选择Yes 以重新编译项目。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.