gpt4 book ai didi

c++ - 让 gprof 从 Qt 调试应用程序读取 gmon.out 输出的问题

转载 作者:可可西里 更新时间:2023-11-01 10:49:46 28 4
gpt4 key购买 nike

我正在尝试分析我正在开发的 Qt 窗口应用程序,并且已经阅读了使用 gprof 进行分析的方法。我已经成功地将项目配置为编译并与 -pg 标志链接以启用分析,并且每次执行应用程序时都会输出 gmon.out。但是,当我尝试运行 gprof 将 gmon.out 文件转换为可读的 txt 文件时,我遇到了“gmon.out 太短而不能成为 gmon 文件”的错误消息。我试着用谷歌搜索这个问题的答案,但无济于事。这里也有人问过同样的问题,但没有给出答案。

我在 Windows 7 上为此项目使用 Qt 4.7.4 和 Qt Creator 2.3.0 以及 mingw 编译器。

我在 .pro 文件中设置的标志是:

# Profiler flags
CONFIG += DEBUG
QMAKE_CXXFLAGS_DEBUG += -pg
QMAKE_CXXFLAGS_MT_DBG += -pg
QMAKE_LFLAGS_DEBUG += -pg

这就是我在命令提示符下调用 gprof 的方式:

C:\QtSDK\mingw\bin>gprof "C:\Qt exe\debug\QtGUI.exe"> profile.txt

错误信息:gmon.out: 文件太短,不能成为 gmon 文件

我还检查了 gmon.out 的文件大小;每次运行调试应用程序时大约有 520 kb。这真的太短了,不能成为 gmon 文件吗?

最佳答案

在运行 gprof 时,如果您省略输出文件的名称,gprof 将采用默认名称“gmon.out”。此文件应位于运行 gprof 的同一文件夹中。

因此,在运行程序时,检查输出文件 gmon.out 是否在您运行的文件夹中正确生成。还要注意目录,你可以在这里阅读

The gmon.out' file is written in the program's current working directory at the time it exits. This means that if your program calls chdir, thegmon.out' file will be left in the last directory your program chdir'd to. If you don't have permission to write in this directory, the file is not written.

(来自:http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html)

在这种情况下,您可以将输出文件路径指定为:

C:\QtSDK\mingw\bin>gprof QtGUI.exe path_to_outfile\gmon.out > profile.txt

希望这对您有所帮助。

再见!

关于c++ - 让 gprof 从 Qt 调试应用程序读取 gmon.out 输出的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9187379/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com