@@ -87,6 +87,7 @@ def test_python_select_by_libpython(
8787 "3.7-musl-uwsgi" ,
8888 ],
8989)
90+ @pytest .mark .flaky (reruns = 3 , reruns_delay = 2 )
9091@pytest .mark .parametrize ("profiler_type" , ["py-spy" , "pyperf" ])
9192def test_python_matrix (
9293 application_pid : int ,
@@ -119,9 +120,15 @@ def test_python_matrix(
119120 ):
120121 pytest .xfail ("This combination fails, see https://github.com/Granulate/gprofiler/issues/714" )
121122
122- with PythonProfiler (1000 , 2 , profiler_state , profiler_type , True , None , False , python_pyspy_process = []) as profiler :
123+ # Use longer duration for pyperf to ensure enough samples are collected for reliable assertions
124+ duration = 5 if profiler_type == "pyperf" else 2
125+ # Timeout should be longer than duration to allow profiling to complete
126+ snapshot_timeout = duration + 5
127+ with PythonProfiler (
128+ 1000 , duration , profiler_state , profiler_type , True , None , False , python_pyspy_process = []
129+ ) as profiler :
123130 try :
124- profile = snapshot_pid_profile (profiler , application_pid )
131+ profile = snapshot_pid_profile (profiler , application_pid , timeout = snapshot_timeout )
125132 except TimeoutError :
126133 if profiler ._ebpf_profiler is not None and profiler ._ebpf_profiler .process is not None :
127134 PythonEbpfProfiler ._check_output (profiler ._ebpf_profiler .process , profiler ._ebpf_profiler .output_path )
@@ -183,8 +190,14 @@ def test_dso_name_in_pyperf_profile(
183190 if is_aarch64 () and profiler_type == "pyperf" :
184191 pytest .skip ("PyPerf doesn't support aarch64 architecture, see https://github.com/intel/gprofiler/issues/499" )
185192
186- with PythonProfiler (1000 , 2 , profiler_state , profiler_type , True , None , True , python_pyspy_process = []) as profiler :
187- profile = snapshot_pid_profile (profiler , application_pid )
193+ # Use longer duration for pyperf to ensure enough samples are collected
194+ duration = 5 if profiler_type == "pyperf" else 2
195+ # Timeout should be longer than duration to allow profiling to complete
196+ snapshot_timeout = duration + 5
197+ with PythonProfiler (
198+ 1000 , duration , profiler_state , profiler_type , True , None , True , python_pyspy_process = []
199+ ) as profiler :
200+ profile = snapshot_pid_profile (profiler , application_pid , timeout = snapshot_timeout )
188201 python_version , _ , _ = application_image_tag .split ("-" )
189202 interpreter_frame = "PyEval_EvalFrameEx" if python_version == "2.7" else "_PyEval_EvalFrameDefault"
190203 collapsed = profile .stacks
0 commit comments