Skip to content

Commit 00a63c5

Browse files
feat(profiling): add conditional jemalloc support for memory allocator testing
1 parent 6259e27 commit 00a63c5

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

riotfile.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
8181

8282
def create_memory_allocator_venvs() -> List[Venv]:
8383
"""Create venv variants for testing different Python memory allocators."""
84+
import ctypes
85+
8486
allocator_configs = [
8587
{
8688
"name_suffix": "pymalloc",
@@ -101,9 +103,36 @@ def create_memory_allocator_venvs() -> List[Venv]:
101103
"name_suffix": "pymalloc-debug",
102104
"env": {"PYTHONMALLOC": "pymalloc_debug"},
103105
"description": "Python malloc with debug hooks"
104-
},
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)
105115
]
106116

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+
107136
venvs = []
108137
for config in allocator_configs:
109138
venvs.append(Venv(
@@ -3348,7 +3377,6 @@ def create_memory_allocator_venvs() -> List[Venv]:
33483377
pys=select_pys(),
33493378
pkgs={"uwsgi": "<2.0.30"},
33503379
),
3351-
# Memory allocator testing variants
33523380
*create_memory_allocator_venvs(),
33533381
# Python 3.8 + 3.9
33543382
Venv(

0 commit comments

Comments
 (0)