18
18
19
19
REFERENCE:
20
20
21
- Uses the `Google performance analysis tools
21
+ This uses the `Google performance analysis tools
22
22
<https://github.com/gperftools/gperftools>`_. Note that they are not
23
23
included in Sage, you have to install them yourself on your system.
24
24
35
35
# https://www.gnu.org/licenses/
36
36
# ****************************************************************************
37
37
38
- import sys
39
38
import ctypes
39
+ import sys
40
40
import time
41
- from sage . structure . sage_object import SageObject
41
+
42
42
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
45
44
46
45
47
46
libc = None
50
49
51
50
class Profiler (SageObject ):
52
51
53
- def __init__ (self , filename = None ):
52
+ def __init__ (self , filename = None ) -> None :
54
53
"""
55
54
Interface to the gperftools profiler.
56
55
@@ -71,7 +70,7 @@ def __init__(self, filename=None):
71
70
else :
72
71
self ._filename = filename
73
72
74
- def filename (self ):
73
+ def filename (self ) -> str :
75
74
"""
76
75
Return the file name.
77
76
@@ -86,7 +85,7 @@ def filename(self):
86
85
"""
87
86
return self ._filename
88
87
89
- def _repr_ (self ):
88
+ def _repr_ (self ) -> str :
90
89
"""
91
90
Return string representation.
92
91
@@ -98,7 +97,7 @@ def _repr_(self):
98
97
sage: Profiler()
99
98
Profiler logging to .../tmp....perf
100
99
"""
101
- return 'Profiler logging to {0}' . format ( self .filename ())
100
+ return f 'Profiler logging to { self .filename ()} '
102
101
103
102
def _libprofiler (self ):
104
103
"""
@@ -167,7 +166,7 @@ def stop(self):
167
166
'less than 100ms' , RuntimeWarning )
168
167
169
168
@cached_method
170
- def _pprof (self ):
169
+ def _pprof (self ) -> str :
171
170
"""
172
171
Return the name of the ``pprof`` binary.
173
172
@@ -190,10 +189,10 @@ def _pprof(self):
190
189
from subprocess import check_output , CalledProcessError , STDOUT
191
190
for name in potential_names :
192
191
try :
193
- version = check_output ([name , '--version' ], stderr = STDOUT )
192
+ bytes_version = check_output ([name , '--version' ], stderr = STDOUT )
194
193
except (CalledProcessError , OSError ):
195
194
continue
196
- version = bytes_to_str ( version )
195
+ version = bytes_version . decode ( )
197
196
if 'gperftools' not in version :
198
197
from warnings import warn
199
198
warn ('the "{0}" utility does not appear to be the gperftools profiler'
@@ -202,7 +201,7 @@ def _pprof(self):
202
201
return name
203
202
raise OSError ('unable to run pprof, please install gperftools' )
204
203
205
- def _executable (self ):
204
+ def _executable (self ) -> str :
206
205
"""
207
206
Return the name of the Sage Python interpreter.
208
207
@@ -341,7 +340,7 @@ def crun(s, evaluator):
341
340
prof .top ()
342
341
343
342
344
- def run_100ms ():
343
+ def run_100ms () -> None :
345
344
"""
346
345
Used for doctesting.
347
346
0 commit comments