gprof生成空输出

27

我正在运行Ubuntu 16.10,并尝试使用gprof对一个程序进行性能分析。我使用-pg标志进行编译,该程序是单线程的。实际的编译命令如下:

g++ -I. -std=c++11 -Wall -Wextra -O3 -pg -fPIC -Wno-unused-parameter -c -o build/obj/performance/stencil_application.o test/performance/stencil_application.cpp
g++ -I. -std=c++11 -Wall -Wextra -O3 -pg -Wno-unused-parameter build/obj/performance/stencil_application.o -o build/test/performance/stencil_application

当我运行该程序时,它需要几秒钟才能完成,并生成一个名为gmon.out的文件。但是,当我运行 gprof ./build/test/performance/stencil_application 时,输出结果中不包含任何数字。我只得到表头和各个字段的解释,如下:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
           else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
           function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
           the function in the gprof listing. If the index is
           in parenthesis it shows where it would appear in
           the gprof listing if it were to be printed.

Copyright (C) 2012-2016 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

                     Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) no time propagated

index % time    self  children    called     name

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

等等就是这样。

我也尝试过不带-O3和带-g进行编译,但结果相同。有人知道是什么问题吗?


6
听起来像是这个错误 - Tony Beta Lambda
我有同样的问题。 - thb
@thb:请参考上面的评论。 - Malin
1个回答

21

正如 Tony Beta Lambda 在上面的评论中指出的那样,这是一个 gcc 的错误。有两种可能的解决方法:降级到 gcc-4.9,或使用标志 -no-pie 进行编译。


6
对我来说,使用单破折号-no-pie有效,而双破折号--no-pie无效。 - 7anner
1
gcc版本为4.8.4(Ubuntu 4.8.4-2ubuntu1~14.04.4)。选项--no-pie有效,而-no-pie无效,但不幸的是,两者都没有解决问题。 - PunyCode
2
我必须指定 -fno-pie。这里是 i386 上的 gcc 4.4.5。 - scai
谢谢。2023年在Windows上仍然存在这个问题(使用x86_64-13.2.0-posix-seh-msvcrt-rt_v11-rev0)。gcc -pg -no-pie -O2 对我也有效。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接