Sample a process using the provided collector. Args: pid: Process ID to sample collector: Collector instance to use for gathering samples duration_sec: How long to sample for (seconds), or None to run until the process exits or interrupted all_threads
(
pid,
collector,
*,
duration_sec=None,
all_threads=False,
realtime_stats=False,
mode=PROFILING_MODE_WALL,
async_aware=None,
native=False,
gc=True,
opcodes=False,
blocking=False,
)
| 372 | |
| 373 | |
| 374 | def sample( |
| 375 | pid, |
| 376 | collector, |
| 377 | *, |
| 378 | duration_sec=None, |
| 379 | all_threads=False, |
| 380 | realtime_stats=False, |
| 381 | mode=PROFILING_MODE_WALL, |
| 382 | async_aware=None, |
| 383 | native=False, |
| 384 | gc=True, |
| 385 | opcodes=False, |
| 386 | blocking=False, |
| 387 | ): |
| 388 | """Sample a process using the provided collector. |
| 389 | |
| 390 | Args: |
| 391 | pid: Process ID to sample |
| 392 | collector: Collector instance to use for gathering samples |
| 393 | duration_sec: How long to sample for (seconds), or None to run until |
| 394 | the process exits or interrupted |
| 395 | all_threads: Whether to sample all threads |
| 396 | realtime_stats: Whether to print real-time sampling statistics |
| 397 | mode: Profiling mode - WALL (all samples), CPU (only when on CPU), |
| 398 | GIL (only when holding GIL), ALL (includes GIL and CPU status), |
| 399 | EXCEPTION (only when thread has an active exception) |
| 400 | native: Whether to include native frames |
| 401 | gc: Whether to include GC frames |
| 402 | opcodes: Whether to include opcode information |
| 403 | blocking: Whether to stop all threads before sampling for consistent snapshots |
| 404 | |
| 405 | Returns: |
| 406 | The collector with collected samples |
| 407 | """ |
| 408 | # Get sample interval from collector |
| 409 | sample_interval_usec = collector.sample_interval_usec |
| 410 | |
| 411 | # PROFILING_MODE_ALL implies no skipping at all |
| 412 | if mode == PROFILING_MODE_ALL: |
| 413 | skip_non_matching_threads = False |
| 414 | else: |
| 415 | # For most modes, skip non-matching threads |
| 416 | # Gecko collector overrides this by setting skip_idle=False |
| 417 | skip_non_matching_threads = True |
| 418 | |
| 419 | profiler = SampleProfiler( |
| 420 | pid, |
| 421 | sample_interval_usec, |
| 422 | all_threads=all_threads, |
| 423 | mode=mode, |
| 424 | native=native, |
| 425 | gc=gc, |
| 426 | opcodes=opcodes, |
| 427 | skip_non_matching_threads=skip_non_matching_threads, |
| 428 | collect_stats=realtime_stats, |
| 429 | blocking=blocking, |
| 430 | ) |
| 431 | profiler.realtime_stats = realtime_stats |
searching dependent graphs…