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] Small set of profiler cleanups from ASAN testing branch #3862

Merged
merged 9 commits into from
Aug 23, 2024

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Aug 22, 2024

What does this PR do?

I've been experimenting with building the profiler with AddressSanitizer (aka ASAN).

So far, I did not discover any issue in the profiler, but I ended up collecting a few tweaks and improvements:

  • Compiling the profiler with Clang 18 got me extra warnings to fix that I hadn't seem before
  • I needed to add a tiny asan-specific workaround for extension loading
  • I ended up doing a cleanup of our extconf.rb

Motivation:

Since I'm not sure I'll have the full ASAN testing working on CI soon, I decided to open up a PR with the fixes I had collected.

Additional Notes:

Although the PR is not big/particularly complex, it may be even easier to review commit-by-commit.

This PR is atop #3852 as it was easier for me to test all of the improvements together, but they are otherwise unrelated. I'll wait until #3852 is merged to master before merging this one.

How to test the change?

Validate that CI still passes, and with no compilation warnings. You can also try compiling the profiler locally with clang and confirm that there are also no warnings emitted by clang.

ASAN doesn't support RTLD_DEEPBIND (it outputs an error saying that
explicitly), so we need to omit it on those builds.
When building libdatadog with ASAN, not having empty strings for mapping
strings made libdatadog fail with `ddog_prof_Profile_add failed:
incomplete utf-8 byte sequence from index 0`.

Now I strongly suspect in practice this isn't an issue, but it's easy
to clean/fix, and makes it easier to experiment with ASAN builds.
This fixes the clang warning:
> warning: implicit conversion from 'unsigned long' to 'double' changes
> value from 18446744073709551615 to 18446744073709551616
> [-Wimplicit-const-int-float-conversion]

Rather than getting a bit fancy, I decided to simplify by using
UINT32_MAX instead, which is already quite an unrealistic value
for a sampling interval.
This fixes the clang warning:
> warning: implicit conversion loses integer precision: 'unsigned long'
> to 'unsigned int' [-Wshorten-64-to-32]

I've made the conversion explicit now, and also made sure no overflow
can happen.
Now that dd-trace-rb is Ruby 2.5+, we can drop our own home-baked
version and use mkmf's `append_cflags` directly.

(The `libdatadog_api` extension was already using this new helper as
well)
This fixes the clang warning

> warning: implicit conversion loses integer precision: 'uintptr_t'
> (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
@ivoanjo ivoanjo requested a review from a team as a code owner August 22, 2024 14:46
@github-actions github-actions bot added the profiling Involves Datadog profiling label Aug 22, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.85%. Comparing base (5bc00e1) to head (fe15909).

Additional details and impacted files
@@                       Coverage Diff                        @@
##           ivoanjo/check-profiler-memleaks    #3862   +/-   ##
================================================================
  Coverage                            97.85%   97.85%           
================================================================
  Files                                 1269     1269           
  Lines                                75868    75868           
  Branches                              3736     3736           
================================================================
+ Hits                                 74237    74240    +3     
+ Misses                                1631     1628    -3     

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

@pr-commenter
Copy link

pr-commenter bot commented Aug 22, 2024

Benchmarks

Benchmark execution time: 2024-08-22 15:21:02

Comparing candidate commit fe15909 in PR branch ivoanjo/fixes-from-asan-branch with baseline commit 5bc00e1 in branch ivoanjo/check-profiler-memleaks.

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

@ivoanjo ivoanjo added the dev/internal Other internal work that does not need to be included in the changelog label Aug 22, 2024
@ivoanjo ivoanjo added this to the 2.4.0 milestone Aug 22, 2024
ivoanjo added a commit that referenced this pull request Aug 23, 2024
**What does this PR do?**

This PR builds atop the work from #3852 and #3862 to enable running
the profiler test suite using the AddressSanitizer ("asan") tool
(see https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer ).

This check will enable us to find bugs in the profiler that may not
be otherwise caught.

**Motivation:**

Improve validation of the profiler native extension.

**Additional Notes:**

The "asan" tool is built into the clang compiler toolchain, and
needs Ruby to be built with a special configuration.

The special configuration is not yet available in the upstream
`ruby/setup-ruby` github action, so I needed to fork it and push
a small tweak to make it available.

(The Ruby builds were added in
ruby/ruby-dev-builder#10 ).

**How to test the change?**

Here's a passing CI run:
https://github.com/DataDog/dd-trace-rb/actions/runs/10524502494/job/29161364590

I've also tested locally by adding a memory leak (e.g. for instance
commenting out `ddog_Vec_Tag_drop(tags);` in `http_transport.c` and
confirmed the issue was flagged.
ivoanjo added a commit that referenced this pull request Aug 23, 2024
**What does this PR do?**

This PR builds atop the work from #3852 and #3862 to enable running
the profiler test suite using the AddressSanitizer ("asan") tool
(see https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer ).

This check will enable us to find bugs in the profiler that may not
be otherwise caught.

**Motivation:**

Improve validation of the profiler native extension.

**Additional Notes:**

The "asan" tool is built into the clang compiler toolchain, and
needs Ruby to be built with a special configuration.

The special configuration is not yet available in the upstream
`ruby/setup-ruby` github action, so I needed to fork it and push
a small tweak to make it available.

(The Ruby builds were added in
ruby/ruby-dev-builder#10 ).

**How to test the change?**

Here's a passing CI run:
https://github.com/DataDog/dd-trace-rb/actions/runs/10524502494/job/29161364590

I've also tested it by adding a memory leak (e.g. for instance
commenting out `ddog_Vec_Tag_drop(tags);` in `http_transport.c` and
confirmed the issue was flagged.

Here's the failing CI run:
https://github.com/DataDog/dd-trace-rb/actions/runs/10524803685/job/29162274392
Base automatically changed from ivoanjo/check-profiler-memleaks to master August 23, 2024 13:50
@ivoanjo ivoanjo merged commit 3679939 into master Aug 23, 2024
178 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/fixes-from-asan-branch branch August 23, 2024 13:51
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.

3 participants