Skip to content

Cleanups related to INVALID_TIME - #6248

Open
eregon wants to merge 4 commits into
masterfrom
cleanup-INVALID_TIME
Open

Cleanups related to INVALID_TIME#6248
eregon wants to merge 4 commits into
masterfrom
cleanup-INVALID_TIME

Conversation

@eregon

@eregon eregon commented Aug 27, 2026

Copy link
Copy Markdown
Member

Review commit-by-commit.
Some of the commits are arguable, no problem to drop them if we think they are not worth it.

What does this PR do?

A few cleanups following #6006 (comment)

Motivation:

Cleaner/simpler code.

Change log entry

None

Additional Notes:

How to test the change?

eregon and others added 4 commits August 27, 2026 14:02
Since "Seed wall/cpu timestamps in initialize_context instead of
mark_thread_as_profiler_internal", `wall_time_at_previous_sample_ns` is
always seeded with a real clock value and is never set to INVALID_TIME,
so that branch of `update_time_since_previous_sample` was dead for the
wall-time path.

`handle_gvl_waiting` already relies on this invariant, as it compares
`wall_time_at_previous_sample_ns` without guarding for INVALID_TIME.

Move the fix up into `update_cpu_time_since_previous_sample`, which is
the only path where the baseline can be missing (when `cpu_time_now_ns`
fails to read the clock).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`gc_tracking.cpu_time_at_start_ns` and `gc_tracking.wall_time_at_start_ns`
are always written together in `on_gc_start` and cleared together in
`on_gc_finish` and `initialize_context`, and neither
`monotonic_wall_time_now_ns` nor `cpu_time_now_ns` can return
INVALID_TIME (they return 0 on failure), so the two can never disagree.

Check only the cpu-time field, which is what `update_time_since_previous_sample`
already does for the same "is this thread in GC?" question.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Only `system_epoch_ns_reference` is ever tested to decide whether the
monotonic-to-epoch state needs to be (re)computed; `delta_to_epoch_ns` is
unconditionally overwritten at that point, so initializing it to
INVALID_TIME just made it look like either field could be the marker.

The designated initializer still zeroes the field, so this is not a
behavior change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`monotonic_wall_time_now_ns` signals failure by returning 0, not
INVALID_TIME. `on_gc_finish` already bails out on a 0 end timestamp, but
`on_gc_start` stored a failed read as-is, so the matching `on_gc_finish`
would have computed a GC duration of "now minus the epoch" and
accumulated it.

Skip tracking the step instead, leaving the fields as INVALID_TIME so
`on_gc_finish` ignores it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@eregon
eregon requested a review from ivoanjo August 27, 2026 12:21
@eregon
eregon requested review from a team as code owners August 27, 2026 12:21
@dd-octo-sts dd-octo-sts Bot added the profiling Involves Datadog profiling label Aug 27, 2026
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 90.29% (-0.01%)

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

@Strech Strech 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.

LGTM 👍🏼

@pr-commenter

pr-commenter Bot commented Aug 27, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-27 12:49:11

Comparing candidate commit ff2d612 in PR branch cleanup-INVALID_TIME with baseline commit bfd0bfc in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 48 metrics, 1 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:tracing - Tracing.continue_trace!

  • unstable throughput [-2167.695op/s; +1720.728op/s] or [-5.601%; +4.446%]

@ivoanjo ivoanjo 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.

👍 LGTM

Comment on lines +887 to +889
// If our start timestamp is not OK, we don't start tracking this GC: leaving the fields as INVALID_TIME makes
// on_gc_finish skip it, rather than have it compute a bogus duration from a 0 start time
if (wall_time_at_start_ns == 0) return;

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.

Minor: I'm not sure it's worth explaining INVALID_TIME, as there's already a return above and doesn't explain it either.

Suggested change
// If our start timestamp is not OK, we don't start tracking this GC: leaving the fields as INVALID_TIME makes
// on_gc_finish skip it, rather than have it compute a bogus duration from a 0 start time
if (wall_time_at_start_ns == 0) return;
// If our start timestamp is not OK, we skip tracking this GC as well
if (wall_time_at_start_ns == 0) return;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiling Involves Datadog profiling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants