Skip to content

Fix MySQL profiling issues: double delays, stale counters, and custom sync API#271

Merged
emeryberger merged 1 commit intomasterfrom
fix-mysql-profiling-issues
Feb 25, 2026
Merged

Fix MySQL profiling issues: double delays, stale counters, and custom sync API#271
emeryberger merged 1 commit intomasterfrom
fix-mysql-profiling-issues

Conversation

@emeryberger
Copy link
Copy Markdown
Member

Summary

Addresses four issues reported when profiling MySQL with Coz after the LIEF/macOS port (PR #265):

  • Fix double delay application on Linux (Issue 1a): Guard the progress-point _call_coz_add_delays() call with __APPLE__. On Linux, delays are already applied in the SIGPROF handler; the unconditional call at every COZ_PROGRESS hit caused double application and TPS collapse under high concurrency.

  • Remove per-experiment delay sync block (Issue 1b): The forced sync of all threads' local_delay to global_delay before each experiment (added in the macOS port) caused a thundering herd of nanosleep calls. The existing cool-off period between experiments already naturally syncs threads.

  • Process pending samples in catch_up() and post_block() on Linux (Issue 4, BCOZ fix): Samples accumulate in per-thread perf_event buffers between 10ms timer signals. Now calls process_samples() (not just add_delays()) to ensure delay counters are current before unblocking other threads.

  • Add custom synchronization API (Issue 3): New COZ_PRE_BLOCK, COZ_CATCH_UP, COZ_POST_BLOCK(skip_delays) macros for programs using synchronization not intercepted by Coz (e.g., MySQL mutexes, RocksDB internal locks).

  • Add slope and R² to coz plot --text (Issue 2): Linear regression slope and R-squared columns help users assess result reliability.

Test plan

  • cmake . && make — clean build on macOS (no new warnings)
  • coz run --- ./benchmarks/toy/toy — profile output produced with experiments, new Slope/R² columns display correctly
  • coz run --- ./benchmarks/lock_test/lock_test — mutex-heavy benchmark profiles correctly (exercises catch_up/post_block changes and validates removed delay sync doesn't break results)
  • Linux CI build and test
  • MySQL profiling verification (requires MySQL test setup)

🤖 Generated with Claude Code

…nters, and custom sync API

Address four issues reported when profiling MySQL after the LIEF/macOS port:

1a. Guard progress-point delay check with __APPLE__. On Linux, delays are
    already applied in the SIGPROF handler; calling add_delays() again at
    every COZ_PROGRESS hit caused double application and TPS collapse.

1b. Remove per-experiment local_delay sync block added in the macOS port.
    Forcing all threads to the same baseline caused a thundering herd of
    nanosleep calls under high concurrency. The existing cool-off period
    between experiments already naturally syncs threads via add_delays().

4.  Call process_samples() (not just add_delays()) in catch_up() and
    post_block() on Linux. Samples accumulate in per-thread perf_event
    buffers between 10ms timer signals; processing them ensures delay
    counters are current before unblocking other threads (BCOZ fix).

3.  Add COZ_PRE_BLOCK, COZ_CATCH_UP, COZ_POST_BLOCK(skip_delays) macros
    and corresponding _coz_pre_block/_coz_post_block exports for programs
    using custom synchronization not intercepted by Coz (e.g., MySQL
    mutexes, RocksDB internal locks).

2.  Add linear regression slope and R-squared columns to `coz plot --text`
    output to help users assess result reliability and optimization impact.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@emeryberger emeryberger merged commit 9b1540f into master Feb 25, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant