Skip to content

Code coverage for Java Profiler - #858

Merged
zhengyu123 merged 14 commits into
mainfrom
zgu/code-coverage
Oct 27, 2026
Merged

zhengyu123 merged 14 commits into
mainfrom
zgu/code-coverage

Conversation

@zhengyu123

@zhengyu123 zhengyu123 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?:
Adds comprehensive code coverage support for the Java Profiler, enabling both C++ coverage (via gcov/llvm-cov + gcovr) and Java coverage (via JaCoCo).

Key features:

  • New coverage build configuration (opt-in via -PenableCoverage)
  • coverageReport task generates both C++ and Java HTML reports
  • checkCoverageTools preflight task validates all required tools before the ~30-minute build/test cycle
  • Atomic counter updates (-fprofile-update=atomic) to prevent GCC bug 68080 corruption from concurrent threads
  • Child JVM coverage: JaCoCo agent forwarded to processes spawned by AbstractProcessProfilerTest.launch()
  • Deferred test failures: known-flaky tests don't block report generation

Motivation:
Enable code coverage measurement for the profiler's native and Java code to identify untested code paths and improve test coverage.

Additional Notes:

  • Coverage build is completely opt-in and has no impact on default/release builds
  • The coverage configuration is not publishable (excluded from artifacts)
  • Both gtest (C++) and Java integration tests contribute to the C++ coverage report
  • Container images updated with gcovr installation for CI coverage runs
  • New NativeBuildConfig.isDebugInstrumented() consolidates debug/coverage/sanitizer build detection

How to test the change?:

# Run full coverage report (C++ and Java)
./gradlew :ddprof-lib:coverageReport -PenableCoverage

# Run only the coverage tests without generating report
./gradlew :ddprof-test:testCoverage -PenableCoverage

# Check coverage tools are installed
./gradlew :ddprof-lib:checkCoverageTools -PenableCoverage

Reports are generated at:

  • C++: ddprof-lib/build/reports/coverage/cpp/index.html
  • Java: ddprof-lib/build/reports/coverage/java/html/index.html

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a security review (run the dd:platform-security-review
    skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: PROF-16230

Unsure? Have a question? Request a review!

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: be33268 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #40558283618 | Commit: 6fc794f | Duration: 19m 31s (longest job)

✅ All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - ✅ - -
8-ibm - ✅ - -
8-j9 ✅ ✅ - -
8-librca - - ✅ ✅
8-orcl - ✅ - -
11 - ✅ - -
11-j9 ✅ ✅ - -
11-librca - - ✅ ✅
17 ✅ ✅ - -
17-graal ✅ ✅ - -
17-j9 ✅ ✅ - -
17-librca - - ✅ ✅
21 ✅ ✅ - -
21-graal ✅ ✅ - -
21-librca - - ✅ ✅
25 ✅ ✅ - -
25-graal ✅ ✅ - -
25-librca - - ✅ ✅

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-10-27 18:49:20 UTC

zhengyu123 and others added 2 commits October 12, 2026 16:23
…rage tasks

- Package the `coverage` native library jar and consumable configuration
  when -PenableCoverage is set, so :ddprof-test:testCoverage can resolve it
  (still excluded from publishing).
- gtestCoverageReport now also depends on :ddprof-test:testCoverage and
  merges the gtest and Java-test .gcda data into one gcovr report; negative
  hit counts are warned about instead of failing the report.
- Build the coverage config with -fprofile-update=atomic so concurrent
  profiler threads don't corrupt gcov counters, and link it on Linux with
  -Wl,-z,nodelete like the debug config.
- Clear stale .gcda files before each gtestCoverage_<test> and testCoverage
  run, and derive the gcov tool from the configured compiler instead of
  the gcov on PATH.
- Enable JaCoCo on testDebug/testSlowDebug only when jacocoTestReport is
  requested (drops -PdisableJacoco). When a coverage report is requested,
  test failures are deferred rather than ignored: the report is generated,
  then the build fails listing the failed test tasks.
- Add NativeBuildConfig so debug-only tests also run against the coverage
  build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dd-octo-sts

dd-octo-sts Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 be33268f

zhengyu123 and others added 7 commits October 14, 2026 07:44
Merge branch 'main' into zgu/code-coverage
- Build the coverage config on configureDebug and add only the
  --coverage flags, so it measures the same binary as testDebug.
- Add a BuildConfiguration.publishable flag (false for coverage) and
  filter packaging/publishing on it instead of the "coverage" name.
- Pick Apple's llvm-cov on macOS only when the compiler is Apple clang,
  so a Homebrew g++-<N> gets its matching gcov-<N>.
- Always rerun testCoverage/testSlowCoverage, since cleanLibCoverageData
  always clears the .gcda counts (the musl Exec tasks could otherwise be
  UP-TO-DATE).
- Gate the coverage test tasks and cleanLibCoverageData on
  :ddprof-lib:checkCoverageTools.
- Point jacocoTestReport at the known .exec files instead of walking the
  build directory, and use tasks.named { } instead of tasks.matching { }.
- Treat the coverage build as a debug build in LazyTraceIdJfrValidationTest,
  ReferenceChainAssertions and BaseContextWallClockTest.
- Install llvm in the Ubuntu test image for the unversioned llvm-cov.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zhengyu123
zhengyu123 marked this pull request as ready for review October 23, 2026 15:48
@zhengyu123
zhengyu123 requested a review from a team as a code owner October 23, 2026 15:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T00:21:36.513935Z be33268 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7cc60dd1f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Ordinary test tasks keep JaCoCo disabled, avoiding instrumentation changes to profiler assertions. No actionable defects were identified; runtime generation of the C++ and Java coverage reports remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit b7cc60d

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Preflight dependency checks and report failure deferral do not consistently respect the tasks actually scheduled.

2 open issues
What changed in this PR

Adds opt-in native and Java coverage reporting to the profiler’s build and test infrastructure, without publishing coverage artifacts.

Changes:

  • Adds a coverage build configuration, tool preflight checks, and combined gcovr/JaCoCo reports.
  • Instruments coverage test JVMs and child processes, with deferred test-failure reporting.
  • Updates test build detection and container tooling for coverage runs.
File Description
utils/​run-containers-tests.sh Installs coverage tools in test containers.
ddprof-test/​src/​test/​java/​com/​datadoghq/​profiler/​wallclock/​BaseContextWallClockTest.java Includes coverage builds in distribution assertions.
ddprof-test/​src/​test/​java/​com/​datadoghq/​profiler/​UnwindFailuresTest.java Recognizes coverage as DEBUG-instrumented.
ddprof-test/​src/​test/​java/​com/​datadoghq/​profiler/​referencechains/​ReferenceChainAssertions.java Uses shared build detection.
ddprof-test/​src/​test/​java/​com/​datadoghq/​profiler/​NativeBuildConfig.java Centralizes native build classification.
ddprof-test/​src/​test/​java/​com/​datadoghq/​profiler/​JVMAccessTest.java Enables debug-gated tests for coverage.
ddprof-test/​src/​test/​java/​com/​datadoghq/​profiler/​JavaProfilerTest.java Enables debug-gated tests for coverage.
ddprof-test/​src/​test/​java/​com/​datadoghq/​profiler/​cpu/​LazyTraceIdJfrValidationTest.java Allows validation in coverage builds.
ddprof-test/​src/​test/​java/​com/​datadoghq/​profiler/​AbstractProfilerTest.java Applies debug-build handling to coverage.
ddprof-test/​src/​test/​java/​com/​datadoghq/​profiler/​AbstractProcessProfilerTest.java Forwards JaCoCo instrumentation to child JVMs.
ddprof-test/​build.gradle.kts Configures Java coverage collection and reporting.
ddprof-lib/​build.gradle.kts Adds preflight checks, combined reports, and publication filtering.
build-logic/​conventions/​src/​main/​kotlin/​com/​datadoghq/​profiler/​ProfilerTestPlugin.kt Supports additional JVM arguments for musl tests.
build-logic/​conventions/​src/​main/​kotlin/​com/​datadoghq/​native/​util/​PlatformUtils.kt Shares Google Test availability detection.
build-logic/​conventions/​src/​main/​kotlin/​com/​datadoghq/​native/​model/​BuildConfiguration.kt Adds configuration publishability control.
build-logic/​conventions/​src/​main/​kotlin/​com/​datadoghq/​native/​gtest/​GtestPlugin.kt Reuses shared Google Test detection.
build-logic/​conventions/​src/​main/​kotlin/​com/​datadoghq/​native/​config/​ConfigurationPresets.kt Defines the opt-in coverage preset.

Review effort: Balanced

Comment thread ddprof-lib/build.gradle.kts Resolved
Comment thread ddprof-test/build.gradle.kts Resolved
# Conflicts:
#	ddprof-lib/build.gradle.kts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e7918bd86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/build.gradle.kts Resolved

@rkennke rkennke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice, carefully commented work. Coverage is truly opt-in (inactive config, not publishable, JaCoCo disabled for every non-coverage test task), and the atomic counter flag, gcov/compiler matching and up-front tool check are all good decisions. Inline comments are mostly about robustness. I've skipped points the other bots already raised and replied in their threads where I had more to add or disagreed.

Note that CI never passes -PenableCoverage, so the green runs only show that the default build is unaffected; none of the new coverage paths are exercised.

Questions:

  • Has a full coverageReport run with at least one failing test been tried, on both the glibc (Test) and musl (Exec) paths? That would confirm the deferral and its ordering (see the comment on ddprof-test/build.gradle.kts L159).
  • What wall-clock time and coverage numbers does a full run give? That would help decide whether this becomes a nightly job later.

Comment thread ddprof-test/build.gradle.kts Resolved
Comment thread ddprof-test/build.gradle.kts Resolved
Comment thread ddprof-lib/build.gradle.kts Resolved
Comment thread ddprof-test/build.gradle.kts Resolved
Comment thread ddprof-test/build.gradle.kts Resolved
Comment thread utils/run-containers-tests.sh Resolved
@zhengyu123
zhengyu123 requested a review from rkennke October 27, 2026 12:32

@rkennke rkennke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you, looks good to me!

@kaahos kaahos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me thanks!

@zhengyu123
zhengyu123 merged commit e599ccb into main Oct 27, 2026
271 of 294 checks passed
@zhengyu123
zhengyu123 deleted the zgu/code-coverage branch October 27, 2026 19:10
@github-actions github-actions Bot added this to the 1.53.0 milestone Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants