gh-140137: Handle empty collections in profiling.sampling (#140154)

This commit is contained in:
Pablo Galindo Salgado 2025-10-15 14:59:12 +01:00 committed by GitHub
parent a05aece543
commit 0c66da8de4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 97 additions and 33 deletions

View file

@ -642,9 +642,14 @@ def sample(
if output_format == "pstats" and not filename:
stats = pstats.SampledStats(collector).strip_dirs()
print_sampled_stats(
stats, sort, limit, show_summary, sample_interval_usec
)
if not stats.stats:
print("No samples were collected.")
if mode == PROFILING_MODE_CPU:
print("This can happen in CPU mode when all threads are idle.")
else:
print_sampled_stats(
stats, sort, limit, show_summary, sample_interval_usec
)
else:
collector.export(filename)