Untitled

作者: Yu0in | 来源:发表于2014-05-06 09:55 被阅读0次

    中间文件类型介绍

    .gcno (gcov note) : 包含重建基本块图和相应的块的源码的行号的信息.
    .gcda (gcov data): 包含弧跳变的次数和其他的概要信息.
    .gcov :
    .info : 包含一个或多个源文件所对应的覆盖率信息,一个源文件对应一条“记录”

    .info record format
    : TN: <Test name> 表示测试用例名称,即通过geninfo中的--test-name选项来命名的测试用例名称,默认为空;
    SF: <File name> 表示带全路径的源代码文件名;
    FN: <函数启始行号>, <函数名>; <函数有效行总数>; <函数有效行总数中被执行个数]]>
    FNDA: <函数被执行的次数>, <函数名>; <函数有效行总数>; <函数有效行总数中被执行个数]]>
    FNF: <函数总数]]>
    FNH: <函数总数中被执行到的个数]]>
    BRDA: <分支所在行号>, <对应的代码块编号>, <分支编号>, <执行的次数]]>
    BRF: <分支总数]]>
    BRH: <分支总数中被执行到的个数]]>
    DA: <代码行号>, <当前行被执行到的次数]]>
    LF: < counts> 代码有效行总数
    LH: <counts> 代码有效行总数中被执行到的个数
    end_of_record 一条“记录”结束符

    Command

    gcov
    : Option :

    : -a --all-blocks : Show information for every basic block(基本快如果没有-a选项,则输出'main'函数这个block的执行次数,如上所示。使用该选项可以
    > 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(分支计数) 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维护的开放源代码工具,最初被设计用来支持Linux内核覆盖率的度量
    • 输出包括概述、覆盖率百分比、图表,能快速浏览覆盖率数据
    • 支持大项目,提供三个级别的视图:目录视图、文件视图、源码视图

    : 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
    

    相关文章

      网友评论

          本文标题:Untitled

          本文链接:https://www.haomeiwen.com/subject/vqurtttx.html