@@ -79,6 +79,85 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
79
79
return [version_to_str (version ) for version in SUPPORTED_PYTHON_VERSIONS if min_version <= version <= max_version ]
80
80
81
81
82
+ def create_memory_allocator_venvs () -> List [Venv ]:
83
+ """Create venv variants for testing different Python memory allocators."""
84
+ import ctypes
85
+
86
+ allocator_configs = [
87
+ {
88
+ "name_suffix" : "pymalloc" ,
89
+ "env" : {"PYTHONMALLOC" : "pymalloc" },
90
+ "description" : "Python's default small object allocator"
91
+ },
92
+ {
93
+ "name_suffix" : "malloc" ,
94
+ "env" : {"PYTHONMALLOC" : "malloc" },
95
+ "description" : "System malloc allocator"
96
+ },
97
+ {
98
+ "name_suffix" : "malloc-debug" ,
99
+ "env" : {"PYTHONMALLOC" : "malloc_debug" },
100
+ "description" : "System malloc with debug hooks"
101
+ },
102
+ {
103
+ "name_suffix" : "pymalloc-debug" ,
104
+ "env" : {"PYTHONMALLOC" : "pymalloc_debug" },
105
+ "description" : "Python malloc with debug hooks"
106
+ }
107
+ ]
108
+
109
+ # Conditionally add jemalloc variant if the library is available
110
+ jemalloc_names = [
111
+ "libjemalloc.so.2" , # Ubuntu/Debian
112
+ "libjemalloc.so.1" , # Older versions
113
+ "libjemalloc.so" , # Generic
114
+ "libjemalloc.dylib" , # macOS (though less common)
115
+ ]
116
+
117
+ for lib_name in jemalloc_names :
118
+ try :
119
+ # Try to load jemalloc library (OSError is raised if not found)
120
+ ctypes .CDLL (lib_name )
121
+
122
+ allocator_configs .append ({
123
+ "name_suffix" : "jemalloc" ,
124
+ "env" : {
125
+ "PYTHONMALLOC" : "malloc" ,
126
+ "LD_PRELOAD" : lib_name
127
+ },
128
+ "description" : "jemalloc high-performance allocator"
129
+ })
130
+
131
+ break
132
+ except (OSError , AttributeError ):
133
+ # Library not found or ctypes issue - try next name
134
+ continue
135
+
136
+ venvs = []
137
+ for config in allocator_configs :
138
+ venvs .append (Venv (
139
+ name = f"profile-v2-{ config ['name_suffix' ]} " ,
140
+ command = "python -m tests.profiling.run pytest -v --no-cov --capture=no --benchmark-disable {cmdargs} tests/profiling_v2" ,
141
+ pys = select_pys (),
142
+ env = config ["env" ],
143
+ pkgs = _profile_v2_pkgs
144
+ ))
145
+
146
+ return venvs
147
+
148
+
149
+ # Common package configuration for profiling v2 tests
150
+ _profile_v2_pkgs = {
151
+ "gunicorn" : latest ,
152
+ "jsonschema" : latest ,
153
+ "lz4" : latest ,
154
+ "pytest-cpp" : latest ,
155
+ "pytest-benchmark" : latest ,
156
+ "py-cpuinfo" : "~=8.0.0" ,
157
+ "pytest-asyncio" : "==0.21.1" ,
158
+ "pytest-randomly" : latest ,
159
+ }
160
+
82
161
# Common venv configurations for appsec threats testing
83
162
_appsec_threats_iast_variants = [
84
163
Venv (
@@ -3291,26 +3370,17 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
3291
3370
env = {
3292
3371
"DD_PROFILING_ENABLE_ASSERTS" : "1" ,
3293
3372
"CPUCOUNT" : "12" ,
3373
+ # Default values for memory allocator testing - can be overridden with --pass-env
3374
+ "PYTHONMALLOC" : "pymalloc" ,
3294
3375
},
3295
- pkgs = {
3296
- "gunicorn" : latest ,
3297
- "jsonschema" : latest ,
3298
- "lz4" : latest ,
3299
- "pytest-cpp" : latest ,
3300
- #
3301
- # pytest-benchmark depends on cpuinfo which dropped support for Python<=3.6 in 9.0
3302
- # See https://github.com/workhorsy/py-cpuinfo/issues/177
3303
- "pytest-benchmark" : latest ,
3304
- "py-cpuinfo" : "~=8.0.0" ,
3305
- "pytest-asyncio" : "==0.21.1" ,
3306
- "pytest-randomly" : latest ,
3307
- },
3376
+ pkgs = _profile_v2_pkgs ,
3308
3377
venvs = [
3309
3378
Venv (
3310
3379
command = "python -m pytest {cmdargs} tests/profiling_v2/test_uwsgi.py" ,
3311
3380
pys = select_pys (),
3312
3381
pkgs = {"uwsgi" : "<2.0.30" },
3313
3382
),
3383
+ * create_memory_allocator_venvs (),
3314
3384
# Python 3.8 + 3.9
3315
3385
Venv (
3316
3386
pys = ["3.8" , "3.9" ],
0 commit comments