Untitled

中間文件類型介紹

? .gcno (gcov note) : 包含重建基本塊圖和相應(yīng)的塊的源碼的行號的信息.
? .gcda (gcov data): 包含弧跳變的次數(shù)和其他的概要信息.
? .gcov :
? .info : 包含一個(gè)或多個(gè)源文件所對應(yīng)的覆蓋率信息,一個(gè)源文件對應(yīng)一條“記錄”

.info record format
: TN: <Test name> 表示測試用例名稱,即通過geninfo中的--test-name選項(xiàng)來命名的測試用例名稱,默認(rèn)為空;
SF: <File name> 表示帶全路徑的源代碼文件名;
FN: <函數(shù)啟始行號>, <函數(shù)名>; <函數(shù)有效行總數(shù)>; <函數(shù)有效行總數(shù)中被執(zhí)行個(gè)數(shù)]]>
FNDA: <函數(shù)被執(zhí)行的次數(shù)>, <函數(shù)名>; <函數(shù)有效行總數(shù)>; <函數(shù)有效行總數(shù)中被執(zhí)行個(gè)數(shù)]]>
FNF: <函數(shù)總數(shù)]]>
FNH: <函數(shù)總數(shù)中被執(zhí)行到的個(gè)數(shù)]]>
BRDA: <分支所在行號>, <對應(yīng)的代碼塊編號>, <分支編號>, <執(zhí)行的次數(shù)]]>
BRF: <分支總數(shù)]]>
BRH: <分支總數(shù)中被執(zhí)行到的個(gè)數(shù)]]>
DA: <代碼行號>, <當(dāng)前行被執(zhí)行到的次數(shù)]]>
LF: < counts> 代碼有效行總數(shù)
LH: <counts> 代碼有效行總數(shù)中被執(zhí)行到的個(gè)數(shù)
end_of_record 一條“記錄”結(jié)束符

Command

gcov
: Option :

: -a --all-blocks : Show information for every basic block(基本快如果沒有-a選項(xiàng),則輸出'main'函數(shù)這個(gè)block的執(zhí)行次數(shù),如上所示。使用該選項(xiàng)可以
> Write individual execution counts for every basic block. Normally gcov outputs execution counts only for the main blocks of a line. With this option you can determine if blocks within a single line are not being executed.
? -b --branch-probabilities : Include branch probabilities(分支概率) in output.
? -c --branch-counts : Given counts of branches(分支計(jì)數(shù)) taken rather than percentages.
? -n --no-output : Do not create an output file(.gcov).
? -l --long-file-names : Use long output file names for included source files.
? -f --function-summaries : Output summaries for each function.
? -o --object-directory DIR|FILE : Search for object files in DIR or called FILE.

lcov

: GCOV圖形化的前端工具
? Linux Test Project維護(hù)的開放源代碼工具,最初被設(shè)計(jì)用來支持Linux內(nèi)核覆蓋率的度量
? 輸出包括概述、覆蓋率百分比、圖表,能快速瀏覽覆蓋率數(shù)據(jù)
? 支持大項(xiàng)目,提供三個(gè)級別的視圖:目錄視圖、文件視圖、源碼視圖

: Operation :
: -c --capture : Capture coverage data

: Options :
: -o --output-file FILENAME : Write data to FILENAME instead of stdout.
? -d --directory DIR : Use .da files in DIR instead of kernel. (.gcno .gcda 所在的文件夾)

Procedure

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

-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 optimisations (-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 base name 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 com- piling) and -lgcov (when linking). See the documentation for those options for more details.
: Compile the source files with -fprofile-arcs plus optimisation and code generation options. For test coverage analysis, use the additional -ftest-coverage option. You do not need to profile every source file in a program.
Link your object files with-lgcovor-fprofile-arcs(thelatterimplies the former).
Run the program on a representative workload to generate the arc profile information. This may be repeated any number of times. You can run concurrent instances of your program, and provided that the file system supports locking, the data files will be correctly updated. Also fork calls are detected and correctly handled (double counting will not happen).
For profile-directed optimisations, compile the source files again with the same optimisation and code generation options plus -fbranch-probabilities.
For test coverage analysis,use gcov to produce human readable information from the .gcno and .gcda files. Refer to the gcov documentation for further information.
: With -fprofile-arcs, for each function of your program GCC creates a program flow graph, then finds a spanning tree for the graph. Only arcs that are not on the spanning tree have to be instrumented: the compiler adds code to count the number of times that these arcs are executed. When an arc is the only exit or only entrance to a block, the instrumentation code can be added to the block; otherwise, a new basic block must be created to hold the instrumentation code.

STEP1: Build & Compile (Generate .gcno)

? Single File :
gcc -fprofile-arcs -ftest-coverage SRC_FILE.c -o SRC_FILE

```
gcc --coverage SRC_FILE.c -o SRC_FILE
```

? Multiple File* :
Compile
gcc -fprofile-arcs -ftest-coverage -c SRC_FILE.c

Link  
```
gcc SRC_FILE.o -o SRC_FILE -lgcov
```

```
gcc SRC_FILE.o –o SRC_FILE -fprofile-arcs
```

```
gcc SRC_FILE.o –o SRC_FILE --coverage
```

STEP2: Run (Generate .gcda)

./SRC_FILE
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容