Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO-TICKET] Fix profiler inline helpers not working when optimization disabled #3856

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Aug 21, 2024

What does this PR do?

This PR makes sure that every inline helper in the profile is marked as static inline.

As documented in https://gcc.gnu.org/onlinedocs/gcc/Inline.html#Inline:

When a function is both inline and static, if all calls to the function
are integrated into the caller, and the function’s address is never
used, then the function’s own assembler code is never referenced.

this is different from just inline:

When an inline function is not static, then the compiler must assume
that there may be calls from other source files; since a global
symbol can be defined only once in any program, the function must not
be defined in the other source files, so the calls therein cannot
be integrated. Therefore, a non-static inline function is always
compiled on its own in the usual fashion.

In practice, this manifested as errors such as

symbol lookup error: datadog_profiling_native_extension.3.4.0_x86_64-linux.so:
undefined symbol: monotonic_wall_time_now_ns

when building Ruby or the profiler with optimization disabled (-O0).

With this fix, these errors no longer show up when building with optimization disabled.

Motivation:

Avoid runtime failures in the profiler on Ruby builds with optimization disabled / when debugging the profiler.

Additional Notes:

Most of these methods with only inline were still unreleased to customers so hopefully nobody was impacted by this issue.

For consistency, I've also made sure that all methods are static inline as we had a mix of inline static as well.

How to test the change?

I was able to trigger the issue by running

$ DDTRACE_DEBUG=true bundle exec rake clean compile
$ bundle exec rspec spec/datadog/profiling/

…on disabled

**What does this PR do?**

This PR makes sure that every `inline` helper in the profile is
marked as `static inline`.

As documented in
<https://gcc.gnu.org/onlinedocs/gcc/Inline.html#Inline>:

> When a function is both inline and static, if all calls to the function
> are integrated into the caller, and the function’s address is never
> used, then the function’s own assembler code is never referenced.

this is different from just `inline`:

> When an inline function is not static, then the compiler must assume
> that there may be calls from other source files; since a global
> symbol can be defined only once in any program, the function must not
> be defined in the other source files, so the calls therein cannot
> be integrated. Therefore, a non-static inline function is always
> compiled on its own in the usual fashion.

In practice, this manifested as errors such as

> symbol lookup error: datadog_profiling_native_extension.3.4.0_x86_64-linux.so:
> undefined symbol: monotonic_wall_time_now_ns

when building Ruby or the profiler with optimization disabled (`-O0`).

With this fix, these errors no longer show up when building with
optimization disabled.

**Motivation:**

Avoid runtime failures in the profiler on Ruby builds with
optimization disabled / when debugging the profiler.

**Additional Notes:**

Most of these methods with only `inline` were still unreleased
to customers so hopefully nobody was impacted by this issue.

For consistency, I've also made sure that all methods are
`static inline` as we had a mix of `inline static` as well.

**How to test the change?**

I was able to trigger the issue by running

```
$ DDTRACE_DEBUG=true bundle exec rake clean compile
$ bundle exec rspec spec/datadog/profiling/
```
This change was a very poor early attempt at working around the
`inline` function issue, and is no longer needed (and was not successful
anyway).
@ivoanjo ivoanjo requested a review from a team as a code owner August 21, 2024 13:34
@github-actions github-actions bot added the profiling Involves Datadog profiling label Aug 21, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.85%. Comparing base (84e92fa) to head (0ca54ec).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3856      +/-   ##
==========================================
- Coverage   97.86%   97.85%   -0.02%     
==========================================
  Files        1271     1271              
  Lines       75975    75975              
  Branches     3739     3739              
==========================================
- Hits        74352    74343       -9     
- Misses       1623     1632       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pr-commenter
Copy link

pr-commenter bot commented Aug 21, 2024

Benchmarks

Benchmark execution time: 2024-08-21 14:07:23

Comparing candidate commit 0ca54ec in PR branch ivoanjo/fix-use-of-inline with baseline commit 84e92fa in branch master.

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

scenario:profiler - sample timeline=false

  • 🟥 throughput [-0.752op/s; -0.717op/s] or [-10.347%; -9.868%]

scenario:profiler - stack collector

  • 🟥 throughput [-153.919op/s; -152.423op/s] or [-4.983%; -4.935%]

@ivoanjo ivoanjo merged commit 7b22f21 into master Aug 21, 2024
186 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/fix-use-of-inline branch August 21, 2024 14:19
@github-actions github-actions bot added this to the 2.3.0 milestone Aug 21, 2024
@ivoanjo ivoanjo added the dev/internal Other internal work that does not need to be included in the changelog label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev/internal Other internal work that does not need to be included in the changelog profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants