Skip to content

Remove dead call-depth instrumentation from the per-test coverage build - #118370

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:impl/coverage-drop-orphaned-finstrument-functions
Sep 13, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:impl/coverage-drop-orphaned-finstrument-functions

Conversation

@groeneai

@groeneai groeneai commented Sep 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

03147_system_columns_access_checks is killed at the 600s per-test cap on Stateless tests (amd_llvm_coverage_per_test, per_test_coverage, 5/8) on two consecutive nightlies (2026-09-04, 2026-09-05) after 17 days at 95-130s; the kill lands inside its 1000-table fixture, so its duration oracle asserts nothing there.

0599d405a0661f3 replaced the -finstrument-functions shadow stack with an entry call count read from the profile counters, but WITH_COVERAGE_DEPTH still adds -finstrument-functions-after-inlining to the global C and C++ flags, so every function entry and exit in the binary, contrib included, calls two empty stubs in base/base/coverage.cpp. base/base is compiled with ${COVERAGE_FLAGS}, so those stubs carry their own counters: on SELECT count() FROM numbers(10000000) they reach 6213755 and 6212763, 5.3x the next hottest function counter and 23.5% of all counter increments. Once continuous mode began working those counters moved into a MAP_SHARED mapping of a merge-pool file, so concurrent clients store into the same file-backed pages at call frequency.

Deleting them cannot change what per-test coverage measures: the hooks are empty, min_depth comes from the entry counter or from XRay, and the WITH_COVERAGE_DEPTH macro comes from the CMake option. Measured, coverageDiag() map_size drops by exactly 2, nothing else moves, and the runner's coverage self-test and system.coverage_indirect_calls stay green. The second commit stops requesting continuous mode for client profiles this lane discards.

Local A/B, the lane's cmake flags, 8 CPUs pinned, randomization off, arms interleaved

Medians; 03147 n=6-7 per arm, the others 1-3.

test master +deletion +both commits
03147_system_columns_access_checks 150.2s 93.2s 34.8s
01161_all_system_tables 59.2s 31.2s 14.9s
02475_bson_each_row_format (115 clients, never two at once) 14.0s 12.8s 12.1s

02475 is the control: clients that never overlap never share a live mapping, and it does not move. Nothing got slower. Ranges: master 113-199s, deletion 79-130s, both 33-37s. 44 tests on this lane exceed their 17-day maximum by >=1.5x on both failing days.

On my host the failing arm runs at 113-199s, not at the cap, so this measures the mechanism's size, not that CI lands under 600s. Everything here sits behind WITH_COVERAGE_DEPTH, which only Build (amd_llvm_coverage_per_test) sets and only nightly_coverage.py schedules, so PR CI neither runs nor builds it; a build break there is this diff's real risk, so I built both arms cold with that job's cmake flags. Owner's call, not taken here: this lane reads no client .profraw, so client profiling could be dropped rather than switched. No related open issue found.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Drop the orphaned -finstrument-functions-after-inlining instrumentation and its two empty __cyg_profile_func_* stubs from the WITH_COVERAGE_DEPTH build, and stop requesting LLVM continuous mode for client profiles on the per-test coverage lane.


Workflow [PR]
Sync PR [sync-upstream/pr/118370]

Version info

  • Merged into: 26.9.1.1339 (included in 26.9 and later)

…trumentation

0599d40 replaced the -finstrument-functions shadow stack with an entry
call count read from the LLVM profile counters, but WITH_COVERAGE_DEPTH kept
injecting -finstrument-functions-after-inlining into the global C and C++ flags.
Every function entry and exit in the whole binary, contrib included, therefore
still calls two empty stubs in base/base/coverage.cpp that nothing consumes.

base/base/CMakeLists.txt compiles base/base with ${COVERAGE_FLAGS}, so the stubs
carry their own profile counters: no_instrument_function stops them recursing, it
does not stop them being profiled. Their entry counters are incremented once per
function entry and once per function exit program-wide, which makes them the two
hottest function counters in the process: on a SELECT count() FROM
numbers(10000000) they reach 6213755 and 6212763, 5.3x the next hottest function
counter and together 23.5% of all counter increments.
With -mllvm -runtime-counter-relocation and
the %c pattern both effective, those counters live in a MAP_SHARED mapping of the
profile pool file, so processes that run concurrently store into the same
file-backed words at function-call frequency.

The removal cannot change what per-test coverage measures: the hooks are empty,
min_depth comes from the entry counter (or from XRay where
CLICKHOUSE_XRAY_INSTRUMENT_COVERAGE is defined), and the WITH_COVERAGE_DEPTH
macro that compiles in CoverageCollection.cpp, LLVMCoverageMapping.cpp and
SYSTEM SET COVERAGE TEST comes from the CMake option, not from this flag.

Also correct the option description, the coverage.h min_depth doc and the two
build-flag lines in .claude/docs/relevant_tests.md, which all still described the
deleted shadow stack.
…verage

The per-test coverage job never reads client .profraw files: ci/jobs/functional_tests.py
merges them only for the non-per-test coverage job. Under %c a client's counters live in
a MAP_SHARED mapping of one of the two merge-pool files, so the clients a test runs
concurrently store into the same file-backed pages at counter-update frequency, and the
lane pays that for a profile it discards.

Measured with the Build (amd_llvm_coverage_per_test) cmake flags, pinned to 8 CPUs (the
shape $(nproc) reports on the lane's runner), --collect-per-test-coverage --jobs 1 and
randomization off, on a tree that already has the orphaned
-finstrument-functions-after-inlining instrumentation removed:

  03147_system_columns_access_checks    93.2s -> 34.8s   (medians, n=6-7 per arm)
  01161_all_system_tables               31.2s -> 14.9s
  02475_bson_each_row_format            12.8s -> 12.1s

02475 spawns 115 clients but never two at once, and it does not move: the cost belongs to
clients whose lifetimes overlap and therefore share a live mapping, not to client count.

The lanes that do consume client profiles keep %c, so the kill-safety property that
motivated it there is unchanged.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 6, 2026
@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Two commits, 5 files, +14/-19. Reviewed cold, then by an independent second model; one fix round
(commit-message accuracy, tree unchanged), and the second pass came back clean.

  • ⚠️ The removal is behind WITH_COVERAGE_DEPTH, which only Build (amd_llvm_coverage_per_test)
    sets and only nightly_coverage.py schedules, so no PR check compiles it. Both arms were built
    cold with that job's cmake flags instead, and the regular coverage build's flags for the changed
    file are byte-identical before and after.
  • 💡 Noted, not changed: nightly_coverage.py:14, ci/defs/defs.py:475 and the ranking table in
    .claude/docs/relevant_tests.md still call the build "depth instrumentation". None of them names
    the removed flag and all predate this change, and the doc quotes find_tests.py's own
    SHALLOW_DEPTH / DIRECT_CALL_MAX_DEPTH, so rewording it would need the CMake option renamed
    too. Left for whoever wants that rename.

@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5541335]

Summary: ✅


AI Review

Summary

This PR removes the obsolete -finstrument-functions-after-inlining path from WITH_COVERAGE_DEPTH builds and switches per-test-coverage client profiles away from LLVM continuous mode. I did not find a correctness or compatibility issue in the current code: the deleted __cyg_profile_func_* hooks have no remaining in-tree consumers, the min_depth fallback already comes from the entry counter or XRay path, and per-test coverage still exports coverage from system.coverage_log and system.coverage_indirect_calls, not from client .profraw files.

Missing context / blind spots
  • ⚠️ The WITH_COVERAGE_DEPTH configuration is not exercised by the normal PR checks, so the remaining risk is confined to that special build/runtime path. A cold build with -DWITH_COVERAGE=ON -DWITH_COVERAGE_DEPTH=ON plus the existing coverage self-test would fully close that gap.
Final Verdict

✅ No new findings.

LLVM Coverage Report

Measured on commit 5541335.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

Changed lines: Changed C/C++ lines covered: 0/0 (nothing coverable) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 6, 2026
@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @alexbakharew @fm4v, could you review this? Since 0599d40 replaced the shadow stack with an entry-count read, WITH_COVERAGE_DEPTH has kept injecting -finstrument-functions-after-inlining for two empty stubs whose own profile counters end up the two hottest function counters in the process, and now that continuous mode is effective those counters live in a shared file-backed mapping. Removing them and dropping %c for the client profiles this lane discards takes 03147_system_columns_access_checks from 150s to 35s in my local A/B with the lane cmake flags.

@clickhouse-gh clickhouse-gh Bot added the comp-build-system Build system (CMake, compilation, platform builds). label Sep 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 554133521 with master 319bfd73f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@groeneai

groeneai commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

A second test on this lane goes red from the same mechanism, and it is the second commit that carries its margin.

03710_parallel_alter_comment_rename_selects keeps 12 clients live at once (4 rename, 4 alter comment, 4 select threads) and wraps every client call in timeout 30. On per_test_coverage shard 2/8 it was green 27 runs in a row at 48-69 s (2026-07-30 to 2026-08-27), and it has failed rc 124 on both nightlies where that shard has actually run since the lane came back, 2026-09-04 and 2026-09-07 (09-05 and 09-06 that shard errored at job level). From the shard's job.log:

❌ Query timed out(30032 ms): RENAME DATABASE ..._03710_parallel_alter_comment_rename_selects TO ..._03710_parallel_alter_comment_rename_selects_2 -- thread 4

At sha e568d262 it is green on every other lane: amd_debug 20.7 s, amd_release 18.4 s, arm_asan_ubsan azure 53.0 s, amd_tsan 188.7 s, amd_asan_ubsan db disk 200.4 s. Its duration ratio does not show the regression because timeout censors the measurement at the bound (81.4 s and 41.1 s against a 48-69 s baseline), so it cannot appear in a slowest-tests comparison; the rc is the only signal it emits.

Its shape is concurrently live clients plus a per-call bound, so the arm that decides it is the client pattern rather than the stub deletion: under %c%2m, initializeProfileForContinuousMode() takes the doMerging() branch and maps the counter section as shared memory "into each participating process" (contrib/llvm-project/compiler-rt/lib/profile/InstrProfilingFile.c), and %2m gives 12 concurrent clients 2 pool files to share. The A/B above splits 93.2 s (deletion only) from 34.8 s (both commits), and a 30 s per-call bound is decided in that gap.

I am not proposing a change to the test. Its 30 s wrapper is a hang detector, and it held for 27 consecutive runs on this lane before 2026-08-28.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Sep 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into ClickHouse:master with commit 98d3af8 Sep 13, 2026
174 of 175 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 13, 2026
Marouane-elfadli pushed a commit to Marouane-elfadli/ClickHouse that referenced this pull request Nov 6, 2026
On the per-test coverage lanes every process of the coverage binary merged
its counters at exit into a merge-pool file shared by the whole job (`%2m`
for stateless clients and the job env, `%4m` for integration containers and
host clients), without continuous mode. The exit-time merge maps the pool
file, merges it, truncates it and rewrites it from offset 0. A process
SIGKILLed during that rewrite (02435's `thread_cancel`, the runner's
process-group kill on a timeout) can leave the value-profile records cut
inside a record. Every later process whose pool slot (`getpid() % N`) is
that file then reads past the mapping in `lprofMergeValueProfData` and dies
with SIGSEGV after its output, and the file stays poisoned. NightlyCoverage
`Stateless tests (amd_llvm_coverage_per_test, per_test_coverage, 2/8)` on
358b830 lost 251 results this way: all 392 crashing client PIDs were even
(pool slot 0), and the 163 sequential tests, which use another pool file,
all passed.

Those lanes never merge a `.profraw`: per-test coverage is read inside the
server from the static counter section and exported from
`system.coverage_log`. So point `LLVM_PROFILE_FILE` at `/dev/null` there:
no process opens, reads or merges a pool file any more. The other lanes keep
their `%c` values, which never merge. Not `%p` (thousands of files, ClickHouse#97020),
not `%c` again (the shared-mapping slowdown ClickHouse#118370 removed).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-build-system Build system (CMake, compilation, platform builds). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants