Untitled

中間文件類型介紹

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

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

Command

gcov
: Option :

: -a --all-blocks : Show information for every basic block(基本快如果沒有-a選項,則輸出'main'函數(shù)這個block的執(zhí)行次數(shù),如上所示。使用該選項可以
> 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(分支計數(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è)計用來支持Linux內(nèi)核覆蓋率的度量
? 輸出包括概述、覆蓋率百分比毁涉、圖表沉帮,能快速瀏覽覆蓋率數(shù)據(jù)
? 支持大項目,提供三個級別的視圖:目錄視圖贫堰、文件視圖穆壕、源碼視圖

: 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)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市其屏,隨后出現(xiàn)的幾起案子喇勋,更是在濱河造成了極大的恐慌,老刑警劉巖偎行,帶你破解...
    沈念sama閱讀 211,194評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件川背,死亡現(xiàn)場離奇詭異,居然都是意外死亡蛤袒,警方通過查閱死者的電腦和手機(jī)熄云,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,058評論 2 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來妙真,“玉大人缴允,你說我怎么就攤上這事≌涞拢” “怎么了健蕊?”我有些...
    開封第一講書人閱讀 156,780評論 0 346
  • 文/不壞的土叔 我叫張陵,是天一觀的道長踢俄。 經(jīng)常有香客問我,道長晴及,這世上最難降的妖魔是什么都办? 我笑而不...
    開封第一講書人閱讀 56,388評論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮虑稼,結(jié)果婚禮上琳钉,老公的妹妹穿的比我還像新娘。我一直安慰自己蛛倦,他們只是感情好歌懒,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,430評論 5 384
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著溯壶,像睡著了一般及皂。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上且改,一...
    開封第一講書人閱讀 49,764評論 1 290
  • 那天验烧,我揣著相機(jī)與錄音,去河邊找鬼又跛。 笑死碍拆,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的慨蓝。 我是一名探鬼主播感混,決...
    沈念sama閱讀 38,907評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼礼烈!你這毒婦竟也來了弧满?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,679評論 0 266
  • 序言:老撾萬榮一對情侶失蹤此熬,失蹤者是張志新(化名)和其女友劉穎谱秽,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體摹迷,經(jīng)...
    沈念sama閱讀 44,122評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡疟赊,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,459評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了峡碉。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片近哟。...
    茶點(diǎn)故事閱讀 38,605評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖鲫寄,靈堂內(nèi)的尸體忽然破棺而出吉执,到底是詐尸還是另有隱情疯淫,我是刑警寧澤,帶...
    沈念sama閱讀 34,270評論 4 329
  • 正文 年R本政府宣布戳玫,位于F島的核電站熙掺,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏咕宿。R本人自食惡果不足惜币绩,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,867評論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望府阀。 院中可真熱鬧缆镣,春花似錦、人聲如沸试浙。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,734評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽田巴。三九已至钠糊,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間壹哺,已是汗流浹背眠蚂。 一陣腳步聲響...
    開封第一講書人閱讀 31,961評論 1 265
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留斗躏,地道東北人逝慧。 一個月前我還...
    沈念sama閱讀 46,297評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像啄糙,于是被迫代替她去往敵國和親笛臣。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,472評論 2 348

推薦閱讀更多精彩內(nèi)容