'gprof'에 해당되는 글 3건

  1. 2010.01.24 gprof flat view 이해하기
  2. 2010.01.23 gcov, gprof
  3. 2009.04.27 xgprof - gnome based gprof GUI frontend
gprof는 기본적으로 flat view로 출력된다.
index % time    self  children    called     name
                0.00    0.00     100/100         tt [3]
[1]      0.0    0.00    0.00     100         aa [1]
-----------------------------------------------
                0.00    0.00     100/100         tt [3]
[2]      0.0    0.00    0.00     100         bb [2]
-----------------------------------------------
                0.00    0.00     100/100         main [9]
[3]      0.0    0.00    0.00     100         tt [3]
                0.00    0.00     100/100         aa [1]
                0.00    0.00     100/100         bb [2]
-----------------------------------------------
아무튼 아래와 같은 형식의 출력이 보이는데, 참 봐도 무슨 소리인지 모르겠다.

간단하게 생각하자면
[%d] 값은 함수이고, 숫자 나온 것에 대한 구조를 보여준다.
[1] 은 aa() 를 실행한 녀석이 tt() 이라는 의미이고
[2] 는 bb() 를 실행한 녀석이 tt()
[3] 는 tt()를 실행한 녀석이 main() 이라는 이야기이다.

tt()
{
  aa();
  bb();
}

main()
{
   tt();
}

이런 구조를 지니게 된다.

만약, 하나의 함수를 여러개에서 호출한다면
위와 같이 [%d] 위에 하나씩 있는게 아니라 여러개가 나타나게 된다.

아래는 Kprof에서 실행한 결과이다.(main 함수는 어디로 가출한겨 ㄱ-)





'프로그램 사용 > gcov, gprof' 카테고리의 다른 글

gcov와 gcovr  (0) 2023.07.20
gcovr - gocv 를 html로  (0) 2023.07.10
gprof gui  (0) 2023.07.10
gcc -p -pg  (0) 2016.02.25
gcov, gprof  (0) 2010.01.23
Posted by 구차니
gcov - coverage testing tool
[링크 : http://korea.gnu.org/manual/release/gcov/gcov_1.ko.html]
[링크 : http://linux.die.net/man/1/gcov]

gcov 는 사용하지 않는 함수를 찾는데 유용한 유틸리티 이다.
이녀석을 사용하기 위해서는 컴파일시 -fprofile-arcs -ftest-coverage 두개의 옵션을 줘야 하는데
gcc 문서를 보니 아래와 같이 --coverage 하나만 주어도 무방할 것으로 보인다.(2010.01.24 추가 : --coverage만 해도 된다)
위의 옵션을 주고 컴파일을 하면, [파일명.gcno] 라는 파일이 생성되고,
파일을 실행하면 [파일명.gcda] 라는 파일이 생성된다. gcov [소스파일] 을 입력하면 분석을 한다.

-fprofile-arcs
    Add code so that program flow arcs are instrumented. During execution the program records how many times each branch and call is executed and how many times it is taken or returns. When the compiled program exits it saves this data to a file called auxname.gcda for each source file. The data may be used for profile-directed optimizations (-fbranch-probabilities), or for test coverage analysis (-ftest-coverage). Each object file's auxname is generated from the name of the output file, if explicitly specified and it is not the final executable, otherwise it is the basename of the source file. In both cases any suffix is removed (e.g. foo.gcda for input file dir/foo.c, or dir/foo.gcda for output file specified as -o dir/foo.o).

--coverage
    This option is used to compile and link code instrumented for coverage analysis. The option is a synonym for -fprofile-arcs -ftest-coverage (when compiling) and -lgcov (when linking). See the documentation for those options for more details.

-ftest-coverage
    Produce a notes file that the gcov code-coverage utility can use to show program coverage. Each source file's note file is called auxname.gcno. Refer to the -fprofile-arcs option above for a description of auxname and instructions on how to generate test coverage data. Coverage data will match the source files more closely, if you do not optimize.

[링크 : http://linux.die.net/man/1/gcc]



gprof - display call graph profile data
[링크 : http://linux.die.net/man/1/gprof]
[링크 : http://kprof.sourceforge.net/] + [링크 : http://www.graphviz.org/]

프로파일링은 어떤 함수가 몇번이나 불려지고(call), 누가 이 함수를 부르는지(call tree)
그리고 어떤 함수가 실행하는데 오래걸리는지를 분석하는 방법이다.
일반적으로 -pg 옵션을 주고 컴파일 한뒤, 한번 실행하면 프로파일링 파일이 생성된다.(정상종료 되어야 생성됨)

프로그램 실행이후에는 gmon.out 파일이 생성되고, 이 파일을 이용하여 분석한다.

-p
Generate extra code to write profile information suitable for the analysis program prof. You must use this option when compiling the source files you want data about, and you must also use it when linking.

-pg
Generate extra code to write profile information suitable for the analysis program gprof. You must use this option when compiling the source files you want data about, and you must also use it when linking.

[링크 : http://linux.die.net/man/1/gcc]



"리눅스 디버깅과 성능 튜닝 - 오픈소스 도구를 사용한 문제 원인 발견과 해결"
[링크 : http://www.yes24.com/24/goods/1948002?scode=032&srank=1]

'프로그램 사용 > gcov, gprof' 카테고리의 다른 글

gcov와 gcovr  (0) 2023.07.20
gcovr - gocv 를 html로  (0) 2023.07.10
gprof gui  (0) 2023.07.10
gcc -p -pg  (0) 2016.02.25
gprof flat view 이해하기  (0) 2010.01.24
Posted by 구차니
솔찍히 gprof로 나오는 결과를 보는 방법도 모르겠고
간단한 프로그램으로는 결과도 제대로 나오지 않아서 실제로 사용해본적이 없다.
아무튼.. 간단하게 gui로 보여주는게 있길래 일단 링크

Download

Don't remember when, 2007, or maybe 2008.
xgprof-0.9.tar.gz
More improvements in the GUI, provided by Enrico Segre (dig the web to get his contact, he might still be at the Weizmann Institute).



[링크 : http://sed.free.fr/xgprof/]


Posted by 구차니