2012-07-15 46 views
2

可能重複:
gprof reports no time accumulated剖析C:空報告

我試圖來分析一個小的C程序。

我編譯它:

% gcc -std=c99 main.c -Wall -c -pg main.c 
% gcc -Wall -pg main.o 
% ./a.out 

然後我嘗試讀取配置文件報告,但它是空的

% gprof a.out                                         130 ↵ 



call graph profile: 
      The sum of self and descendents is the major sort 
      for this listing. 

      function entries: 

index  the index of the function in the call graph 
      listing, as an aid to locating it (see below). 

%time  the percentage of the total time of the program 
      accounted for by this function and its 
      descendents. 

self  the number of seconds spent in this function 
      itself. 

descendents 
      the number of seconds spent in the descendents of 
      this function on behalf of this function. 

called the number of times this function is called (other 
      than recursive calls). 

self  the number of times this function calls itself 
      recursively. 

name  the name of the function, with an indication of 
      its membership in a cycle, if any. 

index  the index of the function in the call graph 
      listing, as an aid to locating it. 



      parent listings: 

self*  the number of seconds of this function's self time 
      which is due to calls from this parent. 

descendents* 
      the number of seconds of this function's 
      descendent time which is due to calls from this 
      parent. 

called** the number of times this function is called by 
      this parent. This is the numerator of the 
      fraction which divides up the function's time to 
      its parents. 

total* the number of times this function was called by 
      all of its parents. This is the denominator of 
      the propagation fraction. 

parents the name of this parent, with an indication of the 
      parent's membership in a cycle, if any. 

index  the index of this parent in the call graph 
      listing, as an aid in locating it. 



      children listings: 

self*  the number of seconds of this child's self time 
      which is due to being called by this function. 

descendent* 
      the number of seconds of this child's descendent's 
      time which is due to being called by this 
      function. 

called** the number of times this child is called by this 
      function. This is the numerator of the 
      propagation fraction for this child. 

total* the number of times this child is called by all 
      functions. This is the denominator of the 
      propagation fraction. 

children the name of this child, and an indication of its 
      membership in a cycle, if any. 

index  the index of this child in the call graph listing, 
      as an aid to locating it. 



      * these fields are omitted for parents (or 
      children) in the same cycle as the function. If 
      the function (or child) is a member of a cycle, 
      the propagated times and propagation denominator 
      represent the self time and descendent time of the 
      cycle as a whole. 

      ** static-only parents and children are indicated 
      by a call count of 0. 



      cycle listings: 
      the cycle as a whole is listed with the same 
      fields as a function entry. Below it are listed 
      the members of the cycle, and their contributions 
      to the time and call counts of the cycle. 



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

            called/total  parents 
index %time self descendents called+self name  index 
            called/total  children 






flat profile: 

%   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. 



granularity: each sample hit covers 4 byte(s) no time accumulated 

    % cumulative self    self  total   
time seconds seconds calls ms/call ms/call name  


Index by function name 

我在做什麼錯?

它的Mac OS X.

% gcc -v                                           
Using built-in specs. 
Target: i686-apple-darwin11 
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1 
Thread model: posix 
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00) 
+0

正在閱讀$ gprof gmon.out? – Aftnix 2012-07-15 20:09:34

回答

0

有沒有可能是你的小C程序主要是做I/O?

這兩分鐘的執行時間可能是99.99%的I/O。

在這個網站上看到有人在內部循環中寫入一個printf的小程序,然後在其上運行gprof,然後發佈類似這樣的問題。

gprof和其他「CPU分析器」對I/O是盲目的,所以這可能是您看不到任何東西的原因。

Check this discussion.