Skip to content

Commit

Permalink
src/sage/misc/gperftools.py: replace libc shenanigans with cysignals
Browse files Browse the repository at this point in the history
When the profiler is starting, this module goes to a lot of trouble to
do... exactly what cysignals is designed to do. And cysignals does not
fail on musl. So let's use cysignals instead?
  • Loading branch information
orlitzky committed Oct 17, 2024
1 parent 6d3cb13 commit 7c161ed
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions src/sage/misc/gperftools.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,6 @@ def _repr_(self):
"""
return 'Profiler logging to {0}'.format(self.filename())

def _libc(self):
"""
Return libc.
OUTPUT: a ctypes shared library handle
EXAMPLES::
sage: from sage.misc.gperftools import Profiler
sage: Profiler()._libc()
<CDLL '...', handle ... at ...>
"""
global libc
if libc is not None:
return libc
name = find_library('c')
if name:
libc = ctypes.CDLL(name)
return libc
else:
raise ImportError('failed to open libc')

def _libprofiler(self):
"""
Return libprofiler.
Expand Down Expand Up @@ -159,7 +137,8 @@ def start(self):
PROFILE: interrupts/evictions/bytes = ...
"""
from signal import SIGPROF, SIG_DFL
self._previous_sigprof_handler = self._libc().signal(SIGPROF, SIG_DFL)
from cysignals.pysignals import setossignal
self._previous_sigprof_handler = setossignal(SIGPROF, SIG_DFL)

Check warning on line 141 in src/sage/misc/gperftools.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/gperftools.py#L140-L141

Added lines #L140 - L141 were not covered by tests
profiler = self._libprofiler()
self._t_start = time.time()
rc = profiler.ProfilerStart(str.encode(self.filename()))

Check warning on line 144 in src/sage/misc/gperftools.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/gperftools.py#L144

Added line #L144 was not covered by tests
Expand Down

0 comments on commit 7c161ed

Please sign in to comment.