CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Code Coverage
Overview
This example demonstrates code coverage analysis by providing two functionally identical code paths - run_real() and run_fake() - that can be switched at runtime via the CODE_COVERAGE_USE_FAKE environment variable. Both functions perform multi-threaded Fibonacci computation with atomic result accumulation. By toggling which path executes, you can test profiler and coverage tool capabilities to detect exercised vs. unexercised code branches and measure instrumentation completeness across alternate execution paths.
Source Files
code-coverage.cpp- Definesfib()(recursive Fibonacci),run_real()andrun_fake()(identical Fibonacci computation with atomic accumulation), and a function-pointer-based dispatch selected by environment variable.code-coverage.py- Python companion script for coverage analysis.
Prerequisites
- CMake 3.25+
- C++ compiler with pthreads support
Building
Standalone build:
cmake -B <build_dir> -S <project_root>/examples/code-coverage
cmake --build <build_dir>
As part of the examples suite:
cmake -B <build_dir> -S <project_root>/examples/
cmake --build <build_dir> --target code-coverage
Running
# Default: run_real path, fib(10), min(16, ncpus) threads, 5000 iterations
./code-coverage
# Use alternate code path
CODE_COVERAGE_USE_FAKE=1 ./code-coverage
# Custom: fib(12), 4 threads, 2000 iterations
./code-coverage 12 4 2000
Arguments:
| Position | Description | Default |
|---|---|---|
| 1 | Fibonacci number to compute | 10 |
| 2 | Number of threads | min(16, hardware concurrency) |
| 3 | Number of iterations per thread | 5000 |
Environment:
| Variable | Description |
|---|---|
CODE_COVERAGE_USE_FAKE |
If set, switches to run_fake() code path |
Profiling with rocprofiler-systems
# Profile the default path
rocprof-sys-run -- ./code-coverage 10 4 2000
# Profile the alternate path
rocprof-sys-run -e CODE_COVERAGE_USE_FAKE=1 -- ./code-coverage 10 4 2000
Recommended Configuration
| Variable | Value | Purpose |
|---|---|---|
ROCPROFSYS_TRACE |
true |
Generate Perfetto trace |
ROCPROFSYS_PROFILE |
true |
Generate call-stack profile showing exercised functions |
ROCPROFSYS_USE_SAMPLING |
ON |
Enable sampling for coverage correlation |