gcc 에서 빌드시에 아래의 플래그를 설정하고

-fprofile-arcs -ftest-coverage

 

빌드시에 생성되는 *.gnco 파일을 바이너리와 동일 경로에 두고 프로그램을 실행하면 *.gcda 파일이 생성된다.

그리고 gcovr을 아래 옵션을 주고 실행하면 html로 결과가 나온다.

소스 디렉토리 내에 bin/ 이 하위 디렉토리로 있어서

bin 에서 covr을 실행하였기에 상위 디렉토리(소스 디렉토리)를 지정해야 해서 "-r .." 을 사용해야 한다.

$ gcovr -r.. --html-details -o gcov.html

 

다만 크로스컴파일 환경에서 실행경로가 다르면 이래저래 번거로우니

profile-dir 플래그로 실행환경에 맞추어서 넣어주어야 편리할 듯 하다.

gcov uses two files for profiling. The names of these files are derived from the original object file by substituting the file suffix with either .gcno, or .gcda. The files contain coverage and profile data stored in a platform-independent format. The .gcno files are placed in the same directory as the object file. By default, the .gcda files are also stored in the same directory as the object file, but the GCC -fprofile-dir option may be used to store the .gcda files in a separate directory.

[링크 : https://gcc.gnu.org/onlinedocs/gcc/Gcov-Data-Files.html]

 

 

+

gcovr로 html 리포트를 생성하면 아래와 같이 나오는데

파일을 클릭하면 파일내에 branch 와 coverage가 나온다.

 

단일 파일 내에서는 Exec가 실행횟수 x는 실행이 한번도 되지 않은 영역이고

 

1/2 라고 나와서 눌러보면 머라고 나오는데 좀 이해가 안되네

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

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
gcov, gprof  (0) 2010.01.23
Posted by 구차니