Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Lib/test/test_profiling/test_sampling_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import subprocess
import sys
import tempfile
import timeit
import unittest
from collections import namedtuple
from unittest import mock
Expand All @@ -29,6 +30,8 @@

PROCESS_VM_READV_SUPPORTED = False

SLOW_MACHINE = timeit.timeit("2*2", number=10_000) > 0.0001

try:
from _remote_debugging import PROCESS_VM_READV_SUPPORTED
import _remote_debugging
Expand Down Expand Up @@ -1754,6 +1757,7 @@ def main_loop():
'''

def test_sampling_basic_functionality(self):
duration_sec = 10 if SLOW_MACHINE else 2
with (
test_subprocess(self.test_script) as subproc,
io.StringIO() as captured_output,
Expand All @@ -1762,7 +1766,7 @@ def test_sampling_basic_functionality(self):
try:
profiling.sampling.sample.sample(
subproc.process.pid,
duration_sec=2,
duration_sec=duration_sec,
sample_interval_usec=1000, # 1ms
show_summary=False,
)
Expand Down Expand Up @@ -1904,7 +1908,10 @@ def test_sample_target_script(self):
script_file.flush()
self.addCleanup(close_and_unlink, script_file)

test_args = ["profiling.sampling.sample", "-d", "1", script_file.name]
duration = 10 if SLOW_MACHINE else 1
test_args = [
"profiling.sampling.sample", "-d", str(duration), script_file.name
]

with (
mock.patch("sys.argv", test_args),
Expand Down Expand Up @@ -1936,7 +1943,12 @@ def test_sample_target_module(self):
with open(module_path, "w") as f:
f.write(self.test_script)

test_args = ["profiling.sampling.sample", "-d", "1", "-m", "test_module"]
duration = 10 if SLOW_MACHINE else 1
test_args = [
"profiling.sampling.sample",
"-d", str(duration),
"-m", "test_module"
]

with (
mock.patch("sys.argv", test_args),
Expand Down
Loading