Skip to content

vaishnavibhat/Linux_gcov

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

Using GCOV and LCOV to collect granite training data

In the context of the Linux kernel, gcov refers to a code coverage analysis tool that helps developers understand which parts of the kernel code are being executed during runtime. It shows which lines of code were executed and how many times.

  1. Build the kernel with gcov support.
  2. Run tests or workloads that exercise the kernel
  3. Collect coverage data from /sys/kernel/debug/gcov/.
  4. Use gcov or tools like lcov or genhtml to visualize the coverage.

Steps to Follow:

  1. Build kernel with GCOV support (for RHEL systems)

    1.a) yumdownloader --assumeyes --source {package} . Download the src package from ftp3 as

     yumdownloader --source kernel-6.12.0-55.9.1.el10_0.src
    

    1.b) rpm -ivh kernel-6.12.0-55.9.1.el10_0.src

    1.c) Follow the steps from the link to extract the kernel sources that will be used to build the gcov kernel.

     https://w3.ibm.com/w3publisher/linux-internal-support/reference/building-kernels-and-packages/how-to-build-a-rhel-kernel-rpm
    

    1.d) Check the directory for the kernel sources: rpmbuild/BUILD/kernel-6.12.0-55.9.1.el10_0/linux-6.12.0-55.9.1.el10.ppc64le/

    1.e) Making config changes and compiling the gcov kernel:

     a) You can copy the kernel sources from the default location to a personalized location to build and configure the gcov or work with the same path.
        copy the files under /root/kernel/linux/linux-6.12.0-55.9.1.el10.ppc64le
    
     b) Copy the current config file from /boot to /root/kernel/linux/linux-6.12.0-55.9.1.el10.ppc64le
        #cp /boot/config-$(uname -r) .config
    
     c) Edit the .config to include the config changes
        CONFIG_LOCALVERSION="-gcov"
        CONFIG_GCOV_KERNEL=y
        CONFIG_ARCH_HAS_GCOV_PROFILE_ALL=y
        CONFIG_GCOV_PROFILE_ALL=y
        CONFIG_GCOV_PROFILE_FTRACE=y
    
     d) make oldconfig
    
     e) make -j$(nproc)
        make modules_install
        make install
    
     f) Reboot and log into to the gcov kernel
    
     g) Validate the gcov is enabled by checking the path
     
        /sys/kernel/debug/gcov/<kernel src path>
    
  2. Run tests or workloads that exercise the kernel

    To exercise the Linux kernel and generate meaningful coverage data for gcov, you can run a variety of test suites and stress tools. Few examples are: Linux Selftests (tools/testing/selftests), LTP (Linux Test Project), stress-ng etc.. Before running the tests, reset gcov and lcov counts.

     a) Reset the gcov count
    
        echo 1 > /sys/kernel/debug/gcov/reset
    
     b) Reset lcov count
    
        lcov --zerocounters
    
     c) Run your workload
    
  3. Collect coverage data from /sys/kernel/debug/gcov/

    The .gcno and .gcdo files are used to collect the coverage data. Data can be analyzed by gcov commandline or tools like lcov and genhtml. This step can be skipped if we plan to use lcov tool to analyze the data.

  4. Use lcov or genhtml to visualize the coverage.

    lcov -o /root/test.info -c -f -d /sys/kernel/debug/gcov/ -b /root/kernel/linux/linux-6.12.0-55.9.1.el10.ppc64le --ignore-errors inconsistent,negative,mismatch

  5. Generate html files with genhtml to create html report for the coverage.

    genhtml -o /root/test_dir /root/test.info --ignore-error inconsistent --ignore-error corrupt

The test_dir will have the coverage report and can be viewed with a browser.

About

Building gcov kernel and understanding the reports

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published