Files
TheRock/rocm-systems/projects/rocprofiler-systems/examples/python
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00
..

Python

Overview

This directory contains Python examples demonstrating rocprofiler-systems' Python profiling capabilities. The examples show different instrumentation approaches: the @rocprofsys.profile() decorator for automatic function tracing, omni_user_region() for manual named regions, @noprofile for excluding specific functions, and rocprofsys.user.stop_trace() for runtime tracing control. Workloads include recursive Fibonacci computation, nested loops, and optional NumPy array operations.

Source Files

  • source.py - Uses @rocprofsys.profile() decorator and omni_user_region() for manual region instrumentation with selective tracing control.
  • source-numpy.py - Same as source.py with additional NumPy random array operations (falls back to standard random if NumPy is unavailable).
  • builtin.py - Uses the built-in @profile decorator without rocprofiler-systems-specific integration.
  • external.py - No profiling decorators; intended for external instrumentation via rocprof-sys-python.
  • noprofile.py - Demonstrates @noprofile to exclude specific functions (fibonacci, inefficient loops) from profiling while tracing only the outer run() function.
  • fill.py - Minimal loop-based test with include_args = True configuration for argument-level tracing.

Prerequisites

  • Python 3
  • rocprofiler-systems Python module
  • (Optional) NumPy for source-numpy.py

Running

Python examples are run via rocprof-sys-python or python -m rocprofsys:

# Using rocprof-sys-python wrapper
rocprof-sys-python -- ./source.py -n 5 -v 20

# Using python module
python -m rocprofsys -- ./source.py -n 5 -v 20

# Scripts without rocprofiler-systems decorators
rocprof-sys-python -- ./external.py -n 3 -v 15

# NumPy variant
rocprof-sys-python -- ./source-numpy.py -n 3 -v 20

Common arguments:

Flag Description Default
-n, --num-iterations Number of iterations 3
-v, --value Starting Fibonacci value 20
-s, --stop-profile Stop tracing after N iterations (0 = never) 0

Profiling with rocprofiler-systems

rocprof-sys-python -- ./source.py -n 5 -v 20
Variable Value Purpose
ROCPROFSYS_TRACE true Generate Perfetto trace with Python call stacks
ROCPROFSYS_PROFILE true Generate call-stack profile
ROCPROFSYS_USE_SAMPLING ON Enable statistical sampling
ROCPROFSYS_SAMPLING_FREQ 50 Sampling frequency (interrupts/sec)