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

fix(ci, profiling): build native macos arm64 wheel #12029

Merged
merged 42 commits into from
Jan 27, 2025

Conversation

taegyunkim
Copy link
Contributor

@taegyunkim taegyunkim commented Jan 22, 2025

Use macos-latest (M1) runner to build arm64 wheel, instead of building universal2 wheel on macos-13 (intel x86_64).

universal2 wheels didn't have native modules to run profiling with certain features.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

Copy link
Contributor

github-actions bot commented Jan 22, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/ci-mac-build-37f7e55c8289de61.yaml                   @DataDog/apm-python
.github/workflows/build_python_3.yml                                    @DataDog/python-guild @DataDog/apm-core-python
ddtrace/internal/datadog/profiling/cmake/AnalysisFunc.cmake             @DataDog/profiling-python
ddtrace/internal/datadog/profiling/crashtracker/CMakeLists.txt          @DataDog/profiling-python
ddtrace/internal/datadog/profiling/ddup/CMakeLists.txt                  @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack_v2/CMakeLists.txt              @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack_v2/test/CMakeLists.txt         @DataDog/profiling-python
pyproject.toml                                                          @DataDog/python-guild

@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Jan 22, 2025

Datadog Report

Branch report: taegyunkim/prof-11189-mac-build
Commit report: ffbaaf4
Test service: dd-trace-py

✅ 0 Failed, 130 Passed, 1468 Skipped, 5m 14.57s Total duration (35m 44.84s time saved)

@pr-commenter
Copy link

pr-commenter bot commented Jan 22, 2025

Benchmarks

Benchmark execution time: 2025-01-27 18:24:51

Comparing candidate commit c548e12 in PR branch taegyunkim/prof-11189-mac-build with baseline commit 75179ef in branch main.

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

Copy link
Contributor

@nsrip-dd nsrip-dd left a comment

Choose a reason for hiding this comment

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

I ran into an ImportError when trying this on my M1 macbook. I downloaded the python 3.13 macos arm64 wheel from the build artifacts (link) and installed it in a virtual environment, then ran a trivial program with ddtrace-run:

% python3 --version
Python 3.13.0
% pip install ddtrace-2.21.0.dev58+g664c6b2a9-cp313-cp313-macosx_12_0_arm64.whl
... stuff ...
% env DD_PROFILING_ENABLED=true ./venv/bin/ddtrace-run python3 test.py
failed to enable profiling
Traceback (most recent call last):
  File "/Users/nick.ripley/sandbox/python/ddtracepy-pr-12029/venv/lib/python3.13/site-packages/ddtrace/bootstrap/preload.py", line 66, in <module>
    import ddtrace.profiling.auto  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nick.ripley/sandbox/python/ddtracepy-pr-12029/venv/lib/python3.13/site-packages/ddtrace/internal/module.py", line 295, in _exec_module
    self.loader.exec_module(module)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/nick.ripley/sandbox/python/ddtracepy-pr-12029/venv/lib/python3.13/site-packages/ddtrace/profiling/__init__.py", line 5, in <module>
    from .profiler import Profiler  # noqa:F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nick.ripley/sandbox/python/ddtracepy-pr-12029/venv/lib/python3.13/site-packages/ddtrace/internal/module.py", line 295, in _exec_module
    self.loader.exec_module(module)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/nick.ripley/sandbox/python/ddtracepy-pr-12029/venv/lib/python3.13/site-packages/ddtrace/profiling/profiler.py", line 28, in <module>
    from ddtrace.profiling.collector import stack
  File "/Users/nick.ripley/sandbox/python/ddtracepy-pr-12029/venv/lib/python3.13/site-packages/ddtrace/internal/module.py", line 234, in _create_module
    return self.loader.create_module(spec)
           ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
ImportError: dlopen(/Users/nick.ripley/sandbox/python/ddtracepy-pr-12029/venv/lib/python3.13/site-packages/ddtrace/profiling/collector/stack.cpython-313-darwin.so, 0x0002): symbol not found in flat namespace '__PyThread_CurrentExceptions'

Is that expected to work?

@taegyunkim
Copy link
Contributor Author

taegyunkim commented Jan 24, 2025

@nsrip-dd Profiling doesn't support 3.13 yet but it also failed on 3.12 on my m1 mac. I thought I checked this, but turns out not. Thank you for catching this. Found the missing link flag to properly build on mac and not explicitly include libpython as a dependency. Updated cmake and we run delocate-wheel as we used to

@taegyunkim taegyunkim enabled auto-merge (squash) January 27, 2025 14:44
@taegyunkim taegyunkim disabled auto-merge January 27, 2025 14:52
@taegyunkim taegyunkim changed the title ci: build native macos arm64 wheel fix(ci): build native macos arm64 wheel Jan 27, 2025
@taegyunkim taegyunkim changed the title fix(ci): build native macos arm64 wheel fix(ci, profiling): build native macos arm64 wheel Jan 27, 2025
@taegyunkim taegyunkim requested a review from a team as a code owner January 27, 2025 15:56
@taegyunkim taegyunkim removed the changelog/no-changelog A changelog entry is not required for this PR. label Jan 27, 2025
Copy link
Contributor

@nsrip-dd nsrip-dd left a comment

Choose a reason for hiding this comment

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

LGTM! Confirmed the fix as follows:

Installed a macos Python 3.12 wheel prior to this fix. Ran with the following command and got an error like so:

% env DD_PROFILING_TIMELINE_ENABLED=true DD_PROFILING_ENABLED=true ./venv/bin/ddtrace-run python3 test.py
Failed to load libdd (module 'ddtrace.internal.datadog.profiling.ddup' has no attribute 'config') (dlopen(/Users/nick.ripley/sandbox/python/ddtracepy-pr-12029/venv/lib/python3.12/site-packages/ddtrace/internal/datadog/profiling/ddup/_ddup.cpython-312-darwin.so, 0x0002): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.12/Python
  Referenced from: <7DC51F2E-55D6-3BEA-BCEE-8F3192B9B2EC> /Users/nick.ripley/sandbox/python/ddtracepy-pr-12029/venv/lib/python3.12/site-packages/ddtrace/internal/datadog/profiling/ddup/_ddup.cpython-312-darwin.so
  Reason: tried: '/Library/Frameworks/Python.framework/Versions/3.12/Python' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.12/Python' (no such file), '/Library/Frameworks/Python.framework/Versions/3.12/Python' (no such file)), falling back to legacy mode

Then I installed a wheel after the fix:

% env DD_PROFILING_TIMELINE_ENABLED=true DD_PROFILING_ENABLED=true ./venv/bin/ddtrace-run python3 test.py
% # ran to completion with no error

@taegyunkim taegyunkim merged commit b922886 into main Jan 27, 2025
701 checks passed
@taegyunkim taegyunkim deleted the taegyunkim/prof-11189-mac-build branch January 27, 2025 18:58
github-actions bot pushed a commit that referenced this pull request Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.20 Profiling Continous Profling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: module 'ddtrace.internal.datadog.profiling.ddup' has no attribute 'SampleHandle'
3 participants