2017-03-06 113 views
14

我正在運行Ubuntu 16.10並嘗試使用gprof來分析程序。我編譯的標誌是-pg,程序是單線程的。實際的編譯命令是:gprof產生空輸出

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

聽起來像[這個bug](https://bugs.launchpad.net/ubuntu/+source/gcc-6/+bug/1678510) –

+0

我有同樣的問題。 – thb

+0

@thb:查看上面的評論 – Malin

回答

10

正如上面的Tony Beta Lambda在評論中指出的那樣,這是一個bug in gcc。有兩種可能的解決方法:降級到gcc-4.9,或使用標記--no-pie進行編譯。

+0

它適用於GCC 6.3。同時使用--no-pie和-pg。 –

+3

對我來說,'-no-pie'(注意單個破折號)起作用,而'--no-pie'沒有。 – 7anner

+0

正確的標誌確實是'-no-pie'。 – Olivier