Skip to content

Commit e9bc459

Browse files
feat(profiling): add memory allocator testing variants (#14659)
[PROF-12490: Running memory allocator tests with different allocators](https://datadoghq.atlassian.net/browse/PROF-12490) ## Description Some clients might be using non-default allocator types in their Python code. The goal of this PR is to ensure that existing memory-related tests are working for (a) all standard allocator types and (b) `jemalloc`, a powerful implementation optimized to avoid memory fragmentation, and providing scalable concurrency, particularly in multithreaded applications. Allocators tested * profile-v2-pymalloc (default) * profile-v2-malloc * profile-v2-malloc-debug * profile-v2-pymalloc-debug **note:** there are perm issues for Docker containers setup affecting testing of **`jemalloc`**. Adding a defensive try/catch strategy to determine if it's installed. I will try to figure out Docker perm issues to install the lib in a follow up PR. ## Testing 1) Ran all `test_memory_collector*` tests ``` $ ./scripts/ddtest riot -v run -s -p 3.10 profile-v2 -- -s -vv -k "test_memory_collector" tests/profiling_v2/collector/test_memalloc.py ... 9 passed with 0 warnings, 0 failed ``` 2) Spot-checked that new allocator types are being used: ``` -------------------summary------------------- ✓ profile-v2: [111cc29] _DD_CIVISIBILITY_USE_CI_CONTEXT_PROVIDER=1 DD_TESTING_RAISE=1 DD_REMOTE_CONFIGURATION_ENABLED=false DD_INJECTION_ENABLED=1 DD_INJECT_FORCE=1 DD_PATCH_MODULES=unittest:false CMAKE_BUILD_PARALLEL_LEVEL=12 CARGO_BUILD_JOBS=12 DD_PROFILING_ENABLE_ASSERTS=1 CPUCOUNT=12 PYTHONMALLOC=pymalloc pythonInterpreter(_hint='3.10') 'mock' 'pytest' 'pytest-mock' 'coverage' 'pytest-cov' 'opentracing' 'hypothesis<6.45.1' 'gunicorn' 'jsonschema' 'lz4' 'pytest-cpp' 'pytest-benchmark' 'py-cpuinfo~=8.0.0' 'pytest-asyncio==0.21.1' 'pytest-randomly' 'uwsgi<2.0.30' ✓ profile-v2-pymalloc: [5178213] _DD_CIVISIBILITY_USE_CI_CONTEXT_PROVIDER=1 DD_TESTING_RAISE=1 DD_REMOTE_CONFIGURATION_ENABLED=false DD_INJECTION_ENABLED=1 DD_INJECT_FORCE=1 DD_PATCH_MODULES=unittest:false CMAKE_BUILD_PARALLEL_LEVEL=12 CARGO_BUILD_JOBS=12 DD_PROFILING_ENABLE_ASSERTS=1 CPUCOUNT=12 PYTHONMALLOC=pymalloc pythonInterpreter(_hint='3.10') 'mock' 'pytest' 'pytest-mock' 'coverage' 'pytest-cov' 'opentracing' 'hypothesis<6.45.1' 'gunicorn' 'jsonschema' 'lz4' 'pytest-cpp' 'pytest-benchmark' 'py-cpuinfo~=8.0.0' 'pytest-asyncio==0.21.1' 'pytest-randomly' ``` 3) Hard-coded invalid allocator names, such as "foo", and observed test failures due to "invalid allocator type" ## Risks None ## Additional Notes
1 parent a74aedd commit e9bc459

File tree

8 files changed

+217
-2
lines changed

8 files changed

+217
-2
lines changed

.riot/requirements/17a060e.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.13
3+
# by the following command:
4+
#
5+
# pip-compile --allow-unsafe --cert=None --client-cert=None --index-url=None --no-annotate --pip-args=None .riot/requirements/17a060e.in
6+
#
7+
attrs==25.3.0
8+
coverage[toml]==7.10.7
9+
gunicorn==23.0.0
10+
hypothesis==6.45.0
11+
iniconfig==2.1.0
12+
jsonschema==4.25.1
13+
jsonschema-specifications==2025.9.1
14+
lz4==4.4.4
15+
mock==5.2.0
16+
opentracing==2.4.0
17+
packaging==25.0
18+
pluggy==1.6.0
19+
py-cpuinfo==8.0.0
20+
pygments==2.19.2
21+
pytest==8.4.2
22+
pytest-asyncio==0.21.1
23+
pytest-benchmark==5.1.0
24+
pytest-cov==7.0.0
25+
pytest-cpp==2.6.0
26+
pytest-mock==3.15.1
27+
pytest-randomly==4.0.1
28+
referencing==0.36.2
29+
rpds-py==0.27.1
30+
sortedcontainers==2.4.0

.riot/requirements/18fddc3.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.9
3+
# by the following command:
4+
#
5+
# pip-compile --allow-unsafe --no-annotate .riot/requirements/18fddc3.in
6+
#
7+
attrs==25.3.0
8+
coverage[toml]==7.10.7
9+
exceptiongroup==1.3.0
10+
gunicorn==23.0.0
11+
hypothesis==6.45.0
12+
importlib-metadata==8.7.0
13+
iniconfig==2.1.0
14+
jsonschema==4.25.1
15+
jsonschema-specifications==2025.9.1
16+
lz4==4.4.4
17+
mock==5.2.0
18+
opentracing==2.4.0
19+
packaging==25.0
20+
pluggy==1.6.0
21+
py-cpuinfo==8.0.0
22+
pygments==2.19.2
23+
pytest==8.4.2
24+
pytest-asyncio==0.21.1
25+
pytest-benchmark==5.1.0
26+
pytest-cov==7.0.0
27+
pytest-cpp==2.6.0
28+
pytest-mock==3.15.1
29+
pytest-randomly==4.0.1
30+
referencing==0.36.2
31+
rpds-py==0.27.1
32+
sortedcontainers==2.4.0
33+
tomli==2.2.1
34+
typing-extensions==4.15.0
35+
zipp==3.23.0

.riot/requirements/1a1c5ae.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# pip-compile --allow-unsafe --no-annotate .riot/requirements/1a1c5ae.in
6+
#
7+
attrs==25.3.0
8+
coverage[toml]==7.6.1
9+
exceptiongroup==1.3.0
10+
gunicorn==23.0.0
11+
hypothesis==6.45.0
12+
importlib-metadata==8.5.0
13+
importlib-resources==6.4.5
14+
iniconfig==2.1.0
15+
jsonschema==4.23.0
16+
jsonschema-specifications==2023.12.1
17+
lz4==4.3.3
18+
mock==5.2.0
19+
opentracing==2.4.0
20+
packaging==25.0
21+
pkgutil-resolve-name==1.3.10
22+
pluggy==1.5.0
23+
py-cpuinfo==8.0.0
24+
pytest==8.3.5
25+
pytest-asyncio==0.21.1
26+
pytest-benchmark==4.0.0
27+
pytest-cov==5.0.0
28+
pytest-cpp==2.6.0
29+
pytest-mock==3.14.1
30+
pytest-randomly==3.15.0
31+
referencing==0.35.1
32+
rpds-py==0.20.1
33+
sortedcontainers==2.4.0
34+
tomli==2.2.1
35+
typing-extensions==4.13.2
36+
zipp==3.20.2

.riot/requirements/748e276.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile --allow-unsafe --cert=None --client-cert=None --index-url=None --no-annotate --pip-args=None .riot/requirements/748e276.in
6+
#
7+
attrs==25.3.0
8+
coverage[toml]==7.10.7
9+
gunicorn==23.0.0
10+
hypothesis==6.45.0
11+
iniconfig==2.1.0
12+
jsonschema==4.25.1
13+
jsonschema-specifications==2025.9.1
14+
lz4==4.4.4
15+
mock==5.2.0
16+
opentracing==2.4.0
17+
packaging==25.0
18+
pluggy==1.6.0
19+
py-cpuinfo==8.0.0
20+
pygments==2.19.2
21+
pytest==8.4.2
22+
pytest-asyncio==0.21.1
23+
pytest-benchmark==5.1.0
24+
pytest-cov==7.0.0
25+
pytest-cpp==2.6.0
26+
pytest-mock==3.15.1
27+
pytest-randomly==4.0.1
28+
referencing==0.36.2
29+
rpds-py==0.27.1
30+
sortedcontainers==2.4.0
31+
typing-extensions==4.15.0

.riot/requirements/dcbb0e8.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.12
3+
# by the following command:
4+
#
5+
# pip-compile --allow-unsafe --cert=None --client-cert=None --index-url=None --no-annotate --pip-args=None .riot/requirements/dcbb0e8.in
6+
#
7+
attrs==25.3.0
8+
coverage[toml]==7.10.7
9+
gunicorn==23.0.0
10+
hypothesis==6.45.0
11+
iniconfig==2.1.0
12+
jsonschema==4.25.1
13+
jsonschema-specifications==2025.9.1
14+
lz4==4.4.4
15+
mock==5.2.0
16+
opentracing==2.4.0
17+
packaging==25.0
18+
pluggy==1.6.0
19+
py-cpuinfo==8.0.0
20+
pygments==2.19.2
21+
pytest==8.4.2
22+
pytest-asyncio==0.21.1
23+
pytest-benchmark==5.1.0
24+
pytest-cov==7.0.0
25+
pytest-cpp==2.6.0
26+
pytest-mock==3.15.1
27+
pytest-randomly==4.0.1
28+
referencing==0.36.2
29+
rpds-py==0.27.1
30+
sortedcontainers==2.4.0
31+
typing-extensions==4.15.0

.riot/requirements/dd5c1a4.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile --allow-unsafe --cert=None --client-cert=None --index-url=None --no-annotate --pip-args=None .riot/requirements/dd5c1a4.in
6+
#
7+
attrs==25.3.0
8+
coverage[toml]==7.10.7
9+
exceptiongroup==1.3.0
10+
gunicorn==23.0.0
11+
hypothesis==6.45.0
12+
iniconfig==2.1.0
13+
jsonschema==4.25.1
14+
jsonschema-specifications==2025.9.1
15+
lz4==4.4.4
16+
mock==5.2.0
17+
opentracing==2.4.0
18+
packaging==25.0
19+
pluggy==1.6.0
20+
py-cpuinfo==8.0.0
21+
pygments==2.19.2
22+
pytest==8.4.2
23+
pytest-asyncio==0.21.1
24+
pytest-benchmark==5.1.0
25+
pytest-cov==7.0.0
26+
pytest-cpp==2.6.0
27+
pytest-mock==3.15.1
28+
pytest-randomly==4.0.1
29+
referencing==0.36.2
30+
rpds-py==0.27.1
31+
sortedcontainers==2.4.0
32+
tomli==2.2.1
33+
typing-extensions==4.15.0

riotfile.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3470,7 +3470,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
34703470
Venv(
34713471
name="profile-v2",
34723472
# NB riot commands that use this Venv must include --pass-env to work properly
3473-
command="python -m tests.profiling.run pytest -v --no-cov --capture=no --benchmark-disable {cmdargs} tests/profiling_v2", # noqa: E501
3473+
command="python -m tests.profiling.run pytest -v --no-cov --capture=no --benchmark-disable --ignore='tests/profiling_v2/collector/test_memalloc.py' {cmdargs} tests/profiling_v2", # noqa: E501
34743474
env={
34753475
"DD_PROFILING_ENABLE_ASSERTS": "1",
34763476
"CPUCOUNT": "12",
@@ -3567,6 +3567,25 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
35673567
),
35683568
],
35693569
),
3570+
Venv(
3571+
name="profile-v2-memalloc",
3572+
command="python -m tests.profiling.run pytest -v --no-cov --capture=no --benchmark-disable {cmdargs} tests/profiling_v2/collector/test_memalloc.py", # noqa: E501
3573+
# skipping v3.14 for now due to an unstable `lz4 ` lib issue: https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-py/-/jobs/1163312347
3574+
pys=select_pys(max_version="3.13"),
3575+
venvs=[
3576+
# standard allocators
3577+
Venv(
3578+
env={
3579+
"PYTHONMALLOC": [
3580+
"malloc",
3581+
"pymalloc",
3582+
"malloc_debug",
3583+
"pymalloc_debug",
3584+
],
3585+
},
3586+
),
3587+
],
3588+
),
35703589
],
35713590
),
35723591
Venv(

tests/profiling/suitespec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ suites:
104104
- '@profiling'
105105
- tests/profiling/suitespec.yml
106106
- tests/profiling_v2/*
107-
pattern: profile-v2$
107+
pattern: profile-v2
108108
retry: 2
109109
runner: riot

0 commit comments

Comments
 (0)