Skip to content

Commit b07f88b

Browse files
committed
Address review
1 parent bf2da78 commit b07f88b

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

Lib/test/test_dtrace.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from test import support
1414
from test.support import findfile, MS_WINDOWS
15+
from test.support import os_helper
1516

1617

1718
if not support.has_subprocess_support:
@@ -209,29 +210,31 @@ class SystemTapBackend(TraceBackend):
209210
PROBE_PLACEHOLDER = "@PYTHON_SYSTEMTAP_PROBE@"
210211

211212
@staticmethod
212-
def _quote_systemtap_string(value):
213+
def quote_systemtap_string(value):
213214
return value.replace("\\", "\\\\").replace('"', '\\"')
214215

215-
def _python_probe(self):
216-
executable = self._quote_systemtap_string(sys.executable)
216+
def python_probe(self):
217+
executable = self.quote_systemtap_string(sys.executable)
217218
probe_binary = get_probe_binary()
218-
if probe_binary != sys.executable:
219-
probe_binary = self._quote_systemtap_string(probe_binary)
220-
return f'process("{executable}").library("{probe_binary}").mark'
221-
return f'process("{executable}").mark'
222-
223-
def _render_script(self, script_file):
224-
with open(script_file) as script:
225-
return script.read().replace(
226-
self.PROBE_PLACEHOLDER, self._python_probe()
227-
)
219+
if probe_binary == sys.executable:
220+
return f'process("{executable}").mark'
221+
222+
# Python built with --enable-shared
223+
probe_binary = self.quote_systemtap_string(probe_binary)
224+
return f'process("{executable}").library("{probe_binary}").mark'
225+
226+
def render_script(self, filename):
227+
with open(filename) as fp:
228+
script = fp.read()
229+
230+
return script.replace(self.PROBE_PLACEHOLDER, self.python_probe())
228231

229232
def trace(self, script_file, subcommand=None, *, timeout=None,
230233
check_returncode=False):
231234
with tempfile.NamedTemporaryFile(
232235
mode="w", encoding="utf-8", suffix=self.EXTENSION, delete=False
233236
) as script:
234-
script.write(self._render_script(script_file))
237+
script.write(self.render_script(script_file))
235238
generated_script_file = script.name
236239

237240
try:
@@ -242,7 +245,7 @@ def trace(self, script_file, subcommand=None, *, timeout=None,
242245
check_returncode=check_returncode,
243246
)
244247
finally:
245-
os.unlink(generated_script_file)
248+
os_helper.unlink(generated_script_file)
246249

247250

248251
class BPFTraceBackend(TraceBackend):

0 commit comments

Comments
 (0)