Skip to content

Commit 4cd238d

Browse files
authored
Merge branch 'main' into upgrade-latest-psycopg-version
2 parents 93cd0c8 + 3fc3fac commit 4cd238d

30 files changed

+493
-208
lines changed

.github/workflows/build_deploy.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ jobs:
111111
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
112112
with:
113113
persist-credentials: false
114+
115+
- name: Enable sccache
116+
uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # 0.0.9
117+
118+
- name: Add addtional GHA cache-related env vars
119+
uses: actions/github-script@v7
120+
with:
121+
script: |
122+
core.exportVariable('ACTIONS_CACHE_URL', process.env['ACTIONS_CACHE_URL'])
123+
core.exportVariable('ACTIONS_RUNTIME_URL', process.env['ACTIONS_RUNTIME_URL'])
124+
114125
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
115126
with:
116127
name: source-dist
@@ -128,6 +139,10 @@ jobs:
128139
- name: Install source package
129140
env:
130141
CMAKE_BUILD_PARALLEL_LEVEL: 12
142+
CARGO_BUILD_JOBS: 12
143+
SCCACHE_GHA_ENABLED: true
144+
SCCACHE_CACHE_SIZE: 1G
145+
DD_USE_SCCACHE: 1
131146
run: pip install dist/*.tar.gz
132147

133148
- name: Test the source package

.github/workflows/build_python_3.yml

Lines changed: 84 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -83,52 +83,26 @@ jobs:
8383
fail-fast: false
8484
matrix:
8585
include: ${{ fromJson(needs.build-wheels-matrix.outputs.include) }}
86-
env:
87-
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DDTRACE: ${{ needs.compute_version.outputs.library_version }}
88-
CIBW_SKIP: ${{ inputs.cibw_skip }}
89-
CIBW_PRERELEASE_PYTHONS: ${{ inputs.cibw_prerelease_pythons }}
90-
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
91-
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
92-
CIBW_MUSLLINUX_I686_IMAGE: ghcr.io/datadog/dd-trace-py/pypa_musllinux_1_2_i686:latest
93-
CIBW_BEFORE_ALL_WINDOWS: ${{ matrix.os == 'windows-latest' && 'rustup target add i686-pc-windows-msvc' || (matrix.os == 'windows-11-arm' && 'rustup target add aarch64-pc-windows-msvc') }}
94-
CIBW_BEFORE_ALL_MACOS: rustup target add aarch64-apple-darwin
95-
CIBW_BEFORE_ALL_LINUX: |
96-
if [[ "$(uname -m)-$(uname -i)-$(uname -o | tr '[:upper:]' '[:lower:]')-$(ldd --version 2>&1 | head -n 1 | awk '{print $1}')" != "i686-unknown-linux-musl" ]]; then
97-
curl -sSf https://sh.rustup.rs | sh -s -- -y;
98-
fi
99-
CIBW_ENVIRONMENT_LINUX: PATH=$HOME/.cargo/bin:$PATH CMAKE_BUILD_PARALLEL_LEVEL=24 CMAKE_ARGS="-DNATIVE_TESTING=OFF" SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DDTRACE=${{ needs.compute_version.outputs.library_version }}
100-
# SYSTEM_VERSION_COMPAT is a workaround for versioning issue, a.k.a.
101-
# `platform.mac_ver()` reports incorrect MacOS version at 11.0
102-
# See: https://stackoverflow.com/a/65402241
103-
CIBW_ENVIRONMENT_MACOS: CMAKE_BUILD_PARALLEL_LEVEL=24 SYSTEM_VERSION_COMPAT=0 CMAKE_ARGS="-DNATIVE_TESTING=OFF" SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DDTRACE=${{ needs.compute_version.outputs.library_version }}
104-
CIBW_ENVIRONMENT_WINDOWS: SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DDTRACE=${{ needs.compute_version.outputs.library_version }}
105-
# cibuildwheel repair will copy anything's under /output directory from the
106-
# build container to the host machine. This is a bit hacky way, but seems
107-
# to be the only way getting debug symbols out from the container while
108-
# we don't mess up with RECORD file.
109-
CIBW_REPAIR_WHEEL_COMMAND_LINUX: |
110-
mkdir -p /output/debugwheelhouse &&
111-
python scripts/extract_debug_symbols.py {wheel} --output-dir /output/debugwheelhouse &&
112-
python scripts/zip_filter.py {wheel} \*.c \*.cpp \*.cc \*.h \*.hpp \*.pyx \*.md &&
113-
mkdir ./tempwheelhouse &&
114-
unzip -l {wheel} | grep '\.so' &&
115-
auditwheel repair -w ./tempwheelhouse {wheel} &&
116-
mv ./tempwheelhouse/*.whl {dest_dir} &&
117-
rm -rf ./tempwheelhouse
118-
CIBW_REPAIR_WHEEL_COMMAND_MACOS: |
119-
mkdir -p ./debugwheelhouse &&
120-
python scripts/extract_debug_symbols.py {wheel} --output-dir ./debugwheelhouse &&
121-
python scripts/zip_filter.py {wheel} \*.c \*.cpp \*.cc \*.h \*.hpp \*.pyx \*.md &&
122-
MACOSX_DEPLOYMENT_TARGET=12.7 delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
123-
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: python scripts/zip_filter.py "{wheel}" "*.c" "*.cpp" "*.cc" "*.h" "*.hpp" "*.pyx" "*.md" && mv "{wheel}" "{dest_dir}"
124-
CIBW_TEST_COMMAND: "python {project}/tests/smoke_test.py"
125-
12686
steps:
12787
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
12888
with:
12989
persist-credentials: false
13090
fetch-depth: 0
13191

92+
- name: Enable sccache
93+
if: runner.os != 'Windows'
94+
uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # 0.0.9
95+
with:
96+
disable_annotations: true
97+
98+
- name: Add addtional GHA cache-related env vars
99+
uses: actions/github-script@v7
100+
if: runner.os != 'Windows'
101+
with:
102+
script: |
103+
core.exportVariable('ACTIONS_CACHE_URL', process.env['ACTIONS_CACHE_URL'])
104+
core.exportVariable('ACTIONS_RUNTIME_URL', process.env['ACTIONS_RUNTIME_URL'])
105+
132106
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
133107
name: Install Python
134108
with:
@@ -144,7 +118,76 @@ jobs:
144118
uses: pypa/cibuildwheel@c923d83ad9c1bc00211c5041d0c3f73294ff88f6 # v3.1.4
145119
with:
146120
only: ${{ matrix.only }}
147-
121+
env:
122+
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DDTRACE: ${{ needs.compute_version.outputs.library_version }}
123+
CIBW_SKIP: ${{ inputs.cibw_skip }}
124+
CIBW_PRERELEASE_PYTHONS: ${{ inputs.cibw_prerelease_pythons }}
125+
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
126+
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
127+
CIBW_MUSLLINUX_I686_IMAGE: ghcr.io/datadog/dd-trace-py/pypa_musllinux_1_2_i686:latest
128+
CIBW_BEFORE_ALL_WINDOWS: ${{ matrix.os == 'windows-latest' && 'rustup target add i686-pc-windows-msvc' || (matrix.os == 'windows-11-arm' && 'rustup target add aarch64-pc-windows-msvc') }}
129+
CIBW_BEFORE_ALL_MACOS: rustup target add aarch64-apple-darwin
130+
CIBW_BEFORE_ALL_LINUX: |
131+
if [[ "$(uname -m)-$(uname -i)-$(uname -o | tr '[:upper:]' '[:lower:]')-$(ldd --version 2>&1 | head -n 1 | awk '{print $1}')" != "i686-unknown-linux-musl" ]]; then
132+
curl -sSf https://sh.rustup.rs | sh -s -- -y;
133+
fi
134+
CIBW_ENVIRONMENT_LINUX: >
135+
PATH=$HOME/.cargo/bin:$PATH
136+
CARGO_BUILD_JOBS=24
137+
CMAKE_BUILD_PARALLEL_LEVEL=24
138+
CMAKE_ARGS="-DNATIVE_TESTING=OFF"
139+
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DDTRACE=${{ needs.compute_version.outputs.library_version }}
140+
SCCACHE_GHA_ENABLED=true
141+
SCCACHE_DIR=/host/${{ env.SCCACHE_DIR }}
142+
SCCACHE_PATH=/host/${{ env.SCCACHE_PATH }}
143+
SCCACHE_CACHE_SIZE=1G
144+
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
145+
ACTIONS_RUNTIME_URL=${{ env.ACTIONS_RUNTIME_URL }}
146+
ACTIONS_RESULTS_URL=${{ env.ACTIONS_RESULTS_URL }}
147+
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
148+
ACTIONS_CACHE_SERVICE_V2=${{ env.ACTIONS_CACHE_SERVICE_V2 }}
149+
DD_USE_SCCACHE=1
150+
# SYSTEM_VERSION_COMPAT is a workaround for versioning issue, a.k.a.
151+
# `platform.mac_ver()` reports incorrect MacOS version at 11.0
152+
# See: https://stackoverflow.com/a/65402241
153+
CIBW_ENVIRONMENT_MACOS: >
154+
CMAKE_BUILD_PARALLEL_LEVEL=24
155+
CARGO_BUILD_JOBS=24
156+
SYSTEM_VERSION_COMPAT=0
157+
CMAKE_ARGS="-DNATIVE_TESTING=OFF"
158+
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DDTRACE=${{ needs.compute_version.outputs.library_version }}
159+
SCCACHE_GHA_ENABLED=true
160+
SCCACHE_CACHE_SIZE=1G
161+
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
162+
ACTIONS_RUNTIME_URL=${{ env.ACTIONS_RUNTIME_URL }}
163+
ACTIONS_RESULTS_URL=${{ env.ACTIONS_RESULTS_URL }}
164+
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
165+
ACTIONS_CACHE_SERVICE_V2=${{ env.ACTIONS_CACHE_SERVICE_V2 }}
166+
DD_USE_SCCACHE=1
167+
CIBW_ENVIRONMENT_WINDOWS: >
168+
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DDTRACE=${{ needs.compute_version.outputs.library_version }}
169+
# cibuildwheel repair will copy anything's under /output directory from the
170+
# build container to the host machine. This is a bit hacky way, but seems
171+
# to be the only way getting debug symbols out from the container while
172+
# we don't mess up with RECORD file.
173+
CIBW_REPAIR_WHEEL_COMMAND_LINUX: |
174+
mkdir -p /output/debugwheelhouse &&
175+
python scripts/extract_debug_symbols.py {wheel} --output-dir /output/debugwheelhouse &&
176+
python scripts/zip_filter.py {wheel} \*.c \*.cpp \*.cc \*.h \*.hpp \*.pyx \*.md &&
177+
mkdir ./tempwheelhouse &&
178+
unzip -l {wheel} | grep '\.so' &&
179+
auditwheel repair -w ./tempwheelhouse {wheel} &&
180+
mv ./tempwheelhouse/*.whl {dest_dir} &&
181+
rm -rf ./tempwheelhouse
182+
CIBW_REPAIR_WHEEL_COMMAND_MACOS: |
183+
mkdir -p ./debugwheelhouse &&
184+
python scripts/extract_debug_symbols.py {wheel} --output-dir ./debugwheelhouse &&
185+
python scripts/zip_filter.py {wheel} \*.c \*.cpp \*.cc \*.h \*.hpp \*.pyx \*.md &&
186+
MACOSX_DEPLOYMENT_TARGET=12.7 delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
187+
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: python scripts/zip_filter.py "{wheel}" "*.c" "*.cpp" "*.cc" "*.h" "*.hpp" "*.pyx" "*.md" && mv "{wheel}" "{dest_dir}"
188+
CIBW_BEFORE_TEST_LINUX: /host/${{ env.SCCACHE_PATH }} --show-stats
189+
CIBW_BEFORE_TEST_MACOS: ${{ env.SCCACHE_PATH }} --show-stats
190+
CIBW_TEST_COMMAND: "python {project}/tests/smoke_test.py"
148191
- name: Validate wheel RECORD files
149192
shell: bash
150193
run: |

.riot/requirements/16ebde6.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

ddtrace/internal/datadog/profiling/dd_wrapper/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ add_library(
5454
src/code_provenance_interface.cpp
5555
src/ddup_interface.cpp
5656
src/profile.cpp
57+
src/profile_borrow.cpp
58+
src/profiler_stats.cpp
5759
src/sample.cpp
5860
src/sample_manager.cpp
5961
src/static_sample_pool.cpp

ddtrace/internal/datadog/profiling/dd_wrapper/include/ddup_interface.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#pragma once
22

3-
#include <stddef.h>
4-
#include <stdint.h>
3+
#include <cstdint>
54
#include <string_view>
65
#include <unordered_map>
76

87
// Forward decl of the return pointer
98
namespace Datadog {
109
class Sample;
11-
}
10+
} // namespace Datadog
1211

1312
#ifdef __cplusplus
1413
extern "C"
@@ -68,6 +67,10 @@ extern "C"
6867
int64_t line);
6968
void ddup_push_absolute_ns(Datadog::Sample* sample, int64_t timestamp_ns);
7069
void ddup_push_monotonic_ns(Datadog::Sample* sample, int64_t monotonic_ns);
70+
71+
void ddup_increment_sampling_event_count();
72+
void ddup_increment_sample_count();
73+
7174
void ddup_flush_sample(Datadog::Sample* sample);
7275
// Stack v2 specific flush, which reverses the locations
7376
void ddup_flush_sample_v2(Datadog::Sample* sample);

ddtrace/internal/datadog/profiling/dd_wrapper/include/profile.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#pragma once
22

33
#include "constants.hpp"
4+
#include "profiler_stats.hpp"
45
#include "types.hpp"
56

67
#include <atomic>
7-
#include <memory>
88
#include <mutex>
9-
#include <string>
10-
#include <string_view>
119
#include <vector>
1210

1311
extern "C"
@@ -17,9 +15,13 @@ extern "C"
1715

1816
namespace Datadog {
1917

18+
class ProfileBorrow;
19+
2020
// Serves to collect individual samples, as well as lengthen the scope of string data
2121
class Profile
2222
{
23+
friend class ProfileBorrow;
24+
2325
private:
2426
// Serialization for static state
2527
// - string table
@@ -45,6 +47,12 @@ class Profile
4547
// cannot be used until it's initialized by libdatadog
4648
ddog_prof_Profile cur_profile{};
4749

50+
Datadog::ProfilerStats profiler_stats{};
51+
52+
// Internal access methods - not for direct use
53+
ddog_prof_Profile& profile_borrow_internal();
54+
void profile_release();
55+
4856
public:
4957
// State management
5058
void one_time_init(SampleType type, unsigned int _max_nframes);
@@ -53,8 +61,8 @@ class Profile
5361

5462
// Getters
5563
size_t get_sample_type_length();
56-
ddog_prof_Profile& profile_borrow();
57-
void profile_release();
64+
65+
ProfileBorrow borrow();
5866

5967
// constref getters
6068
const ValueIndex& val();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
#include "profile.hpp"
4+
5+
namespace Datadog {
6+
7+
// Forward declaration
8+
class Profile;
9+
10+
// RAII wrapper for borrowing both profile and stats under a single lock
11+
class ProfileBorrow
12+
{
13+
private:
14+
Profile* profile_ptr;
15+
16+
public:
17+
explicit ProfileBorrow(Profile& profile);
18+
~ProfileBorrow();
19+
20+
// Disable copy
21+
ProfileBorrow(const ProfileBorrow&) = delete;
22+
ProfileBorrow& operator=(const ProfileBorrow&) = delete;
23+
24+
// Enable move
25+
ProfileBorrow(ProfileBorrow&& other) noexcept;
26+
ProfileBorrow& operator=(ProfileBorrow&& other) noexcept;
27+
28+
// Accessors
29+
ddog_prof_Profile& profile();
30+
ProfilerStats& stats();
31+
};
32+
33+
} // namespace Datadog
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
3+
#include <cstddef>
4+
5+
#include <string>
6+
#include <string_view>
7+
8+
namespace Datadog {
9+
10+
/*
11+
ProfilerStats holds statistics around Profiling to be sent along
12+
with the actual Profiles.
13+
14+
None of its methods are thread-safe and it should typically used with
15+
a mutex to protect access to the data.
16+
*/
17+
class ProfilerStats
18+
{
19+
private:
20+
std::string internal_metadata_json;
21+
22+
// Number of samples collected (one per thread)
23+
size_t sample_count = 0;
24+
25+
// Number of sampling events (one per collection cycle)
26+
size_t sampling_event_count = 0;
27+
28+
public:
29+
ProfilerStats() = default;
30+
~ProfilerStats() = default;
31+
32+
void increment_sample_count(size_t k_sample_count = 1);
33+
size_t get_sample_count();
34+
35+
void increment_sampling_event_count(size_t k_sampling_event_count = 1);
36+
size_t get_sampling_event_count();
37+
38+
// Returns a JSON string containing relevant Profiler Stats to be included
39+
// in the libdatadog payload.
40+
// The function returned a string_view to a statically allocated string that
41+
// is updated every time the function is called.
42+
std::string_view get_internal_metadata_json();
43+
44+
void reset_state();
45+
};
46+
47+
} // namespace Datadog

ddtrace/internal/datadog/profiling/dd_wrapper/include/sample.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "libdatadog_helpers.hpp"
44
#include "profile.hpp"
5+
#include "profile_borrow.hpp"
56
#include "types.hpp"
67

78
#include <string>
@@ -134,8 +135,7 @@ class Sample
134135
// Flushes the current buffer, clearing it
135136
bool flush_sample(bool reverse_locations = false);
136137

137-
static ddog_prof_Profile& profile_borrow();
138-
static void profile_release();
138+
static ProfileBorrow profile_borrow();
139139
static void postfork_child();
140140
Sample(SampleType _type_mask, unsigned int _max_nframes);
141141

0 commit comments

Comments
 (0)