Backend/C

gprof

petitCoding 2011. 5. 26. 11:46




gprof : 프로그램 수행시간동안 각 함수의 호출 횟수와 함수 호출시 진입에서 종료할때 까지 시간을 기록해 두고, 이 정보에 대한 통계를 제공하는 방식의 디버거이다.

 

사용법은 매우..간편하다 -_ -

심플한 사용법은 다음과 같다.

! 프로그램은 Makefile을 사용해 컴파일하지 않고 단순히 gcc를 사용해 컴파일하였다.

Makefile 사용 시에도 아래와 같이 -pg옵션을 넣어주면 된다.

 

1. -pg 옵션을 넣어서 컴파일한다.

[whitelka]$ gcc -o main main.c -pg

 

2. 생성된 파일을 실행한다.

 main  main.c  main.h  main_profile  sample.c  url.txt
[whitelka]$ ./main

3. 파일이 실행되면 gmon.out 이라는 파일이 생성된다.

gmon.out  main  main.c  main.h  main_profile  sample.c  url.txt

 

4. gprof 명령어를 수행한다.

[whitelka]$ gprof ./main

 

5. 다음과 같은 정보를 얻을 수 있다.


Each sample counts as 0.01 seconds. //수행시간..너무 짧아서..-_ -
 no time accumulated
/* 각 함수별 성능 정보를 알 수 있다. */

  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
  0.00      0.00     0.00       13     0.00     0.00  check
  0.00      0.00     0.00       13     0.00     0.00  hashing
  0.00      0.00     0.00       13     0.00     0.00  make_ip
  0.00      0.00     0.00       13     0.00     0.00  update

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


                     Call graph (explanation follows)


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

index % time    self  children    called     name
                0.00    0.00      13/13          main [11]
[1]      0.0    0.00    0.00      13         check [1]
-----------------------------------------------
                0.00    0.00      13/13          main [11]
[2]      0.0    0.00    0.00      13         hashing [2]
-----------------------------------------------
                0.00    0.00      13/13          main [11]
[3]      0.0    0.00    0.00      13         make_ip [3]
-----------------------------------------------
                0.00    0.00      13/13          main [11]
[4]      0.0    0.00    0.00      13         update [4]
-----------------------------------------------

 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.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index      A unique number given to each element of the table.
                Index numbers are sorted numerically.
                The index number is printed next to every function name so
                it is easier to look up where the function in the table.

     % time     This is the percentage of the `total' time that was spent
                in this function and its children.  Note that due to
                different viewpoints, functions excluded by options, etc,
                these numbers will NOT add up to 100%.

     self       This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
                function by its children.

     called     This is the number of times the function was called.
                If the function called itself recursively, the number
                only includes non-recursive calls, and is followed by
                a `+' and the number of recursive calls.

     name       The name of the current function.  The index number is
                printed after it.  If the function is a member of a
                cycle, the cycle number is printed between the
                function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self       This is the amount of time that was propagated directly
                from the function into this parent.

     children   This is the amount of time that was propagated from
                the function's children into this parent.

     called     This is the number of times this parent called the
                function `/' the total number of times the function
                was called.  Recursive calls to the function are not
                included in the number after the `/'.

     name       This is the name of the parent.  The parent's index
                number is printed after it.  If the parent is a
                member of a cycle, the cycle number is printed between
                the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self       This is the amount of time that was propagated directly

 

Index by function name //함수별 이름

   [1] check                   [3] make_ip
   [2] hashing                 [4] update



반응형

'Backend > C' 카테고리의 다른 글

Memmove  (0) 2012.04.12
valgrind  (0) 2011.05.26
GDB  (0) 2011.05.26
memset()을 이용하여 메모리를 채워보자  (0) 2011.05.20
memcpy()를 이용한 메모리 카피!  (0) 2011.05.20