| 58 | std::once_flag g_coverage_map_once; |
| 59 | |
| 60 | void ensureCoverageMapLoaded() |
| 61 | { |
| 62 | std::call_once(g_coverage_map_once, [] |
| 63 | { |
| 64 | const auto regions = readLLVMCoverageMapping("/proc/self/exe"); |
| 65 | g_coverage_map.reserve(regions.size()); |
| 66 | for (const CoverageRegion & r : regions) |
| 67 | { |
| 68 | const CoverageKey key{r.name_hash, r.func_hash, r.counter_id}; |
| 69 | auto [it, inserted] = g_coverage_map.emplace(key, r); |
| 70 | if (!inserted) |
| 71 | { |
| 72 | /// Keep the narrowest region for this counter. Prefer branch regions |
| 73 | /// over code regions of the same width — they carry directional info. |
| 74 | const uint32_t existing_width = it->second.line_end - it->second.line_start; |
| 75 | const uint32_t new_width = r.line_end - r.line_start; |
| 76 | if (new_width < existing_width |
| 77 | || (new_width == existing_width && r.is_branch && !it->second.is_branch)) |
| 78 | it->second = r; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | LOG_INFO( |
| 83 | getLogger("CoverageCollection"), |
| 84 | "Loaded {} counter regions from LLVM coverage mapping ({} raw regions)", |
| 85 | g_coverage_map.size(), regions.size()); |
| 86 | }); |
| 87 | } |
| 88 | |
| 89 | } // anonymous namespace |
| 90 |
no test coverage detected