Files
TheRock/rocm-systems/projects/rocprofiler-systems/examples/user-api/README.md
T
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

2.9 KiB

User API

Overview

This example demonstrates the rocprofiler-systems user API for instrumenting application code with named regions and custom annotations. It computes Fibonacci numbers across multiple threads while marking execution phases - initialization, thread creation, computation, and waiting - as named profiling regions. A custom callback adds errno annotations to each region push, showing how to attach application-specific metadata to trace events. Selective per-thread tracing is also demonstrated.

Source Files

  • user-api.cpp - Calls rocprofsys_user_configure() to register custom callbacks, uses rocprofsys_user_push_region() / rocprofsys_user_pop_region() to delimit named regions, and rocprofsys_user_push_annotated_region() to attach annotations. Also demonstrates rocprofsys_user_stop_thread_trace() / rocprofsys_user_start_thread_trace() for selective thread tracing.

Prerequisites

  • CMake 3.25+
  • C++17 compiler
  • rocprofiler-systems user library (rocprofiler-systems::rocprofiler-systems-user-library)

Building

Standalone build:

cmake -B <build_dir> -S <project_root>/examples/user-api -DCMAKE_PREFIX_PATH=/opt/rocm
cmake --build <build_dir>

As part of the examples suite:

cmake -B <build_dir> -S <project_root>/examples/ -DCMAKE_PREFIX_PATH=/opt/rocm
cmake --build <build_dir> --target user-api

Running

# Default: fib(10), min(16, ncpus) threads, 50000 iterations
./user-api

# Custom: fib(15), 8 threads, 10000 iterations
./user-api 15 8 10000

Arguments:

Position Description Default
1 Fibonacci number to compute 10
2 Number of threads min(16, hardware concurrency)
3 Number of iterations per thread 50000

Profiling with rocprofiler-systems

rocprof-sys-run -- ./user-api 10 4 1000
Variable Value Purpose
ROCPROFSYS_TRACE true Generate Perfetto trace with user regions
ROCPROFSYS_PROFILE true Generate call-stack profile
ROCPROFSYS_USE_SAMPLING ON Enable statistical sampling

For binary rewrite instrumentation:

rocprof-sys-instrument -l --min-instructions=8 -E custom_push_region \
    -o user-api.inst -- ./user-api
./user-api.inst 10 4 1000
Option Purpose
-l Instrument at the loop level so the Fibonacci loop in run() is profiled
--min-instructions=8 Lower the default threshold (1024) so small functions like run() are included
-E custom_push_region Exclude the user callback from instrumentation to avoid recursion and trace noise (the callback runs on every region push; instrumenting it would profile the profiler rather than the workload)

IMPORTANT NOTE

The rocprof-sys-user library will be removed in a future release. Please use rocprofiler-sdk-roctx instead!