From 872f0aed0c6db49b466974c747b6e65e0b461ede Mon Sep 17 00:00:00 2001 From: "systems-assistant[bot]" <221163467+systems-assistant[bot]@users.noreply.github.com> Date: Tue, 23 Sep 2025 13:17:08 -0400 Subject: [PATCH] Live attach/detach and its unit tests (#53) --- projects/rocprofiler-compute/CHANGELOG.md | 3 + projects/rocprofiler-compute/CMakeLists.txt | 9 + .../docs/how-to/live_attach_detach.rst | 46 +++ projects/rocprofiler-compute/pyproject.toml | 1 + .../sample/dynamic_shared/dynamic_shared.hip | 174 ++++++++++ .../sample/dynamic_shared/example_utils.hpp | 300 ++++++++++++++++++ projects/rocprofiler-compute/src/argparser.py | 22 ++ .../rocprof_compute_profile/profiler_base.py | 21 +- .../profiler_rocprof_v3.py | 13 +- .../profiler_rocprofiler_sdk.py | 19 +- .../rocprofiler-compute/src/utils/utils.py | 139 +++++++- .../rocprofiler-compute/tests/CMakeLists.txt | 9 + .../rocprofiler-compute/tests/conftest.py | 45 ++- .../tests/test_profile_general.py | 129 ++++++++ 14 files changed, 909 insertions(+), 21 deletions(-) create mode 100644 projects/rocprofiler-compute/docs/how-to/live_attach_detach.rst create mode 100644 projects/rocprofiler-compute/sample/dynamic_shared/dynamic_shared.hip create mode 100644 projects/rocprofiler-compute/sample/dynamic_shared/example_utils.hpp diff --git a/projects/rocprofiler-compute/CHANGELOG.md b/projects/rocprofiler-compute/CHANGELOG.md index 6a3424106d..81e578458b 100644 --- a/projects/rocprofiler-compute/CHANGELOG.md +++ b/projects/rocprofiler-compute/CHANGELOG.md @@ -5,6 +5,9 @@ Full documentation for ROCm Compute Profiler is available at [https://rocm.docs. ## Unreleased ### Added +* Live attach/detach feature that allows coupling with a workload process, without controlling its start or end. + * Use '--attach-pid' to specify the target process ID. + * Use '--attach-duration-msec' to specify time duration. * Add `rocpd` choice for `--format-rocprof-output` option in profile mode diff --git a/projects/rocprofiler-compute/CMakeLists.txt b/projects/rocprofiler-compute/CMakeLists.txt index 81ef31a2c5..7c51c1a70a 100644 --- a/projects/rocprofiler-compute/CMakeLists.txt +++ b/projects/rocprofiler-compute/CMakeLists.txt @@ -322,6 +322,15 @@ add_test( WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) +add_test( + NAME test_profile_live_attach_detach + COMMAND + ${Python3_EXECUTABLE} -m pytest -s -m live_attach_detach + --junitxml=tests/test_profile_live_attach_detach.xml ${COV_OPTION} + ${PROJECT_SOURCE_DIR}/tests/test_profile_general.py + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} +) + set_tests_properties( test_profile_kernel_execution test_profile_dispatch diff --git a/projects/rocprofiler-compute/docs/how-to/live_attach_detach.rst b/projects/rocprofiler-compute/docs/how-to/live_attach_detach.rst new file mode 100644 index 0000000000..9ffae34b93 --- /dev/null +++ b/projects/rocprofiler-compute/docs/how-to/live_attach_detach.rst @@ -0,0 +1,46 @@ +.. meta:: + :description: ROCm Compute Profiler: using Live Attach Detach + :keywords: ROCm Compute Profiler, Attach Detach + +*********************************************************** +Using Live Attach/Detach in ROCm Compute Profiler +*********************************************************** + +Live Attach/Detach is a new feature of ROCm Compute Profiler that allows coupling with a workload process, without controlling its start or end. The application can already be running before the profiler application is invoked. The profiler simply attaches to the process, collects the required counters, and then detaches—without altering the lifecycle of the workload. + +A specific attach is not repeatable, and it can only collect the set of counters that the hardware is capable of capturing in a single run. As such, in the current implementation, you must specify a subset of counter groups that can be collected within one run. This can be done either by using the ``--block`` option (for example, --block 3.1.1 4.1.1 5.1.1) or by providing a predefined set through the use of single pass counter collection ``--set``. + +Detachment can be achieved in two ways: + +a) By setting the ``--attach-duration-msec`` parameter to a specific duration (in milliseconds). In this case, the detachment occurs automatically after the specified time has elapsed since the ``rocprof`` subprocess started. +b) By pressing the Enter key after a successful attach within the same profiling terminal session. Upon a successful attach, a confirmation message is displayed in the terminal log of the workload process. + +--------------------- +Profiling options +--------------------- +For using profiling options for PC sampling the configuration needed are: + +* ``--attach-pid``: Should be the process ID of the process of workload's application. +* ``--attach-duration-msec``: (Optional) This is for setting up the synchronized detach, and is optional. Its unit is in milliseconds. When setting up, the detach will happen after this time has elapsed since the ``rocprof`` subprocess started. For example, setting it to 60000 yields 1 minute. + +**Sample command:** + +.. code-block:: shell + $ rocprof-compute profile -n try_live_attach_detach -b 3.1.1 4.1.1 5.1.1 --no-roof -VVV --attach-pid + + $ rocprof-compute profile -n try_live_attach_detach --set launch_stats --no-roof -VVV --attach-pid + + $ rocprof-compute profile -n try_live_attach_detach -b 3.1.1 4.1.1 5.1.1 --no-roof -VVV --attach-pid --attach-duration-msec