Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import sysconfig
import textwrap
import time
import timeit
import types
import unittest
import warnings
Expand Down Expand Up @@ -2694,6 +2695,9 @@ def exceeds_recursion_limit():
return 150_000


# Is the host running the tests significantly slower than a typical PC?
is_slow_machine = timeit.timeit("2*2", number=10_000) > 0.0001

# Windows doesn't have os.uname() but it doesn't support s390x.
is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
skip_on_s390x = unittest.skipIf(is_s390x, 'skipped on s390x')
Expand Down
27 changes: 21 additions & 6 deletions Lib/test/test_profiling/test_sampling_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@
)
from profiling.sampling.gecko_collector import GeckoCollector

from test.support import (
SHORT_TIMEOUT,
captured_stderr,
captured_stdout,
force_not_colorized_test_class,
is_emscripten,
is_slow_machine,
requires_subprocess,
)
from test.support.os_helper import unlink
from test.support import force_not_colorized_test_class, SHORT_TIMEOUT
from test.support.socket_helper import find_unused_port
from test.support import requires_subprocess, is_emscripten
from test.support import captured_stdout, captured_stderr

PROCESS_VM_READV_SUPPORTED = False

Expand Down Expand Up @@ -1754,6 +1760,7 @@ def main_loop():
'''

def test_sampling_basic_functionality(self):
duration_sec = 10 if is_slow_machine else 2
with (
test_subprocess(self.test_script) as subproc,
io.StringIO() as captured_output,
Expand All @@ -1762,7 +1769,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 +1911,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 is_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 +1946,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 is_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