分析 CPU 使用情况
借助 Perf,您可以在 Linux 桌面和嵌入式设备上分析应用程序的 CPU 和内存使用情况。性能分析器利用 Linux 内核自带的 Perf 工具,定期对应用程序的调用链进行快照,并将其以时间轴视图或火焰图的形式可视化呈现。
通常,性能分析器需要被分析二进制文件的调试符号。性能分析构建会生成带有独立调试符号的优化二进制文件,因此请使用这些文件进行性能分析。
收集数据
请通过以下方式启动性能分析器以收集数据:
- 转至Analyze >Performance Analyzer 以对当前应用程序进行性能分析。
- 选择“
”(Start )以从“Performance Analyzer ”启动应用程序。
注意:如果 数据收集未自动开始,请选择“
”(Collect profile data )。
当您开始分析应用程序时,该应用程序将被启动,Performance Analyzer 会立即开始收集数据。 这可以通过“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 ”以运行脚本。
要为跟踪点添加事件,请参阅“选择事件类型”。
记录内存跟踪,以便在时间轴的“samples”行中查看使用情况图表,并在火焰图中查看内存分配、峰值和释放情况。
为 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.