Skip to content

Commit 40ef438

Browse files
committed
avoid using bytes_to_string in gperftools
1 parent 7888c42 commit 40ef438

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/sage/misc/gperftools.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
REFERENCE:
2020
21-
Uses the `Google performance analysis tools
21+
This uses the `Google performance analysis tools
2222
<https://github.com/gperftools/gperftools>`_. Note that they are not
2323
included in Sage, you have to install them yourself on your system.
2424
@@ -35,13 +35,12 @@
3535
# https://www.gnu.org/licenses/
3636
# ****************************************************************************
3737

38-
import sys
3938
import ctypes
39+
import sys
4040
import time
41-
from sage.structure.sage_object import SageObject
41+
4242
from sage.misc.cachefunc import cached_method
43-
from sage.misc.compat import find_library
44-
from sage.cpython.string import bytes_to_str
43+
from sage.structure.sage_object import SageObject
4544

4645

4746
libc = None
@@ -50,7 +49,7 @@
5049

5150
class Profiler(SageObject):
5251

53-
def __init__(self, filename=None):
52+
def __init__(self, filename=None) -> None:
5453
"""
5554
Interface to the gperftools profiler.
5655
@@ -71,7 +70,7 @@ def __init__(self, filename=None):
7170
else:
7271
self._filename = filename
7372

74-
def filename(self):
73+
def filename(self) -> str:
7574
"""
7675
Return the file name.
7776
@@ -86,7 +85,7 @@ def filename(self):
8685
"""
8786
return self._filename
8887

89-
def _repr_(self):
88+
def _repr_(self) -> str:
9089
"""
9190
Return string representation.
9291
@@ -98,7 +97,7 @@ def _repr_(self):
9897
sage: Profiler()
9998
Profiler logging to .../tmp....perf
10099
"""
101-
return 'Profiler logging to {0}'.format(self.filename())
100+
return f'Profiler logging to {self.filename()}'
102101

103102
def _libprofiler(self):
104103
"""
@@ -167,7 +166,7 @@ def stop(self):
167166
'less than 100ms', RuntimeWarning)
168167

169168
@cached_method
170-
def _pprof(self):
169+
def _pprof(self) -> str:
171170
"""
172171
Return the name of the ``pprof`` binary.
173172
@@ -190,10 +189,10 @@ def _pprof(self):
190189
from subprocess import check_output, CalledProcessError, STDOUT
191190
for name in potential_names:
192191
try:
193-
version = check_output([name, '--version'], stderr=STDOUT)
192+
bytes_version = check_output([name, '--version'], stderr=STDOUT)
194193
except (CalledProcessError, OSError):
195194
continue
196-
version = bytes_to_str(version)
195+
version = bytes_version.decode()
197196
if 'gperftools' not in version:
198197
from warnings import warn
199198
warn('the "{0}" utility does not appear to be the gperftools profiler'
@@ -202,7 +201,7 @@ def _pprof(self):
202201
return name
203202
raise OSError('unable to run pprof, please install gperftools')
204203

205-
def _executable(self):
204+
def _executable(self) -> str:
206205
"""
207206
Return the name of the Sage Python interpreter.
208207
@@ -341,7 +340,7 @@ def crun(s, evaluator):
341340
prof.top()
342341

343342

344-
def run_100ms():
343+
def run_100ms() -> None:
345344
"""
346345
Used for doctesting.
347346

0 commit comments

Comments
 (0)