Created
May 27, 2022 02:01
-
-
Save mdusher/0c3987934e4353d08de997cd9240927e to your computer and use it in GitHub Desktop.
check-jemalloc-prof.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Check if libjemalloc was built with `--enable-prof` (and thus has | |
memory profiling capabilities) or not. | |
Author: Ori Livneh | |
No copyright restriction | |
Original Source: https://gist.github.com/atdt/736137113e577795e5fc | |
Able to specify the path to libjemalloc as the first argument. | |
""" | |
import ctypes | |
import ctypes.util | |
import errno | |
import os | |
import sys | |
jemalloc_so = "" | |
if len(sys.argv) > 1: | |
jemalloc_so = sys.argv[1] | |
else: | |
jemalloc_so = ctypes.util.find_library('jemalloc') | |
if jemalloc_so is None: | |
sys.exit('Could not find libjemalloc! Is it installed?') | |
jemalloc = ctypes.CDLL(jemalloc_so, use_errno=True) | |
has_prof = ctypes.c_bool(False) | |
has_prof_len = ctypes.c_size_t(ctypes.sizeof(has_prof)) | |
rv = jemalloc.mallctl('config.prof', ctypes.byref(has_prof), | |
ctypes.byref(has_prof_len), None, None) | |
if rv != 0: | |
err = ctypes.get_errno() | |
raise OSError(err, os.strerror(err)) | |
if has_prof: | |
print('OK: jemalloc was built with `--enable-prof`.') | |
sys.exit(0) | |
else: | |
print('NOT OK: jemalloc was not built with `--enable-prof`.') | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment