Skip to content

Users/marantic amd/configurable json presets#4331

Draft
marantic-amd wants to merge 11 commits intodevelopfrom
users/marantic-amd/configurable-json-presets
Draft

Users/marantic amd/configurable json presets#4331
marantic-amd wants to merge 11 commits intodevelopfrom
users/marantic-amd/configurable-json-presets

Conversation

@marantic-amd
Copy link
Contributor

@marantic-amd marantic-amd commented Mar 23, 2026

Motivation

The rocprof-sys-run and rocprof-sys-sample CLI tools require users to manually set dozens of ROCPROFSYS_* environment variables to configure profiling. This is error-prone and has a steep learning curve. Additionally, running --help dumps 100+ options in a flat list, making it difficult to find relevant options.

This PR adds:

  1. A JSON-based preset system so users can configure profiling with a single --preset=<name> flag
  2. Domain flags (--gpu, --rocm, --cpu, --parallel) for composable configuration
  3. A layered, topic-based --help system that filters options by category
  4. Pre-run validation warnings and post-run output summaries
  5. A shared rocprofiler-systems-bin-common static library to eliminate code duplication between the two tools

Technical Details

JSON Configuration & Presets

  • 11 preset JSON files in share/rocprofiler-systems/presets/ covering general (balanced, detailed, profile-only), GPU (trace-gpu, workload-trace, trace-hw-counters), HPC (trace-hpc, trace-openmp, profile-mpi), and API tracing (sys-trace, runtime-trace) use cases
  • New CLI options: --preset=<name>, --list-presets, --explain=<name>, --export-config[=file]
  • Domain flags: --gpu[=metrics], --rocm[=domains], --cpu[=hz], --parallel[=runtimes] with shorthand expansion (e.g., hip → hip_runtime_api)
  • JSON schema file (schema.json) for preset validation
  • Presets are copied to the build directory at configure time via configure_file(COPYONLY) so they are discoverable without setting ROCPROFSYS_PRESET_DIR

Shared Library (rocprofiler-systems-bin-common)

  • New static library in source/bin/common/ extracting duplicated code from run/impl.cpp and sample/impl.cpp
  • argument_registration.hpp - shared template for preset/domain/export argument registration
  • json_config.cpp - JSON schema ↔ environment variable resolution and export
  • preset_loader.cpp - preset discovery, file loading, and environment application
  • common_utils.cpp - validation, help system, pre-execution info, configuration export
  • env_vars.hpp - centralized environment variable name constants

Topic-Based Help System

  • --help shows a compact summary with quick-start options and a topic index
  • --help=<topic> filters by group: preset, general, tracing, profiling, sampling, process, counters, backend, debug, misc
  • --help=<domain> shows curated cross-group options: gpu, cpu, rocm, parallel
  • --help=all shows full output (previous --help behavior)
  • Section extraction captures print_help() output via set_ostream(), parses group separator lines with ANSI escape code stripping, and emits only matching sections

Pre-Run Validation & Post-Run Summary

  • Always-visible warnings before execution (ROCm availability, output directory writability, domain flag conflicts)
  • Post-run output summary during library finalization showing output file locations

JIRA ID

AIPROFSYST-236
AIPROFSYST-238

Test Plan

  • Unit tests (source/bin/common/tests/):
    • test_help_system.cpp (17 tests) - topic/domain map validation, compact help content, group-based section extraction with ANSI stripping, domain-based cross-group extraction, continuation line handling
    • test_json_config.cpp - JSON schema resolution for all sections (tracing, profiling, sampling, GPU, ROCm, parallel, output, causal, hardware counters, advanced), env var export roundtrip, safe parsing edge cases
    • test_preset_loader.cpp - preset file loading, directory discovery, environment application, path traversal protection
  • Integration tests (tests/rocprof-sys-preset-tests.cmake) - all 11 presets on both run and sample, domain flag tests (--gpu, --rocm, --cpu, --parallel, --gpu=temp,power), preset+domain combinations, export config tests, list/explain tests
  • Manual verification: --help, --help=gpu, --help=sampling, --help=preset, --help=all, --help=invalid, -h

Test Result

  • All unit tests pass
  • Both rocprof-sys-run and rocprof-sys-sample build and run correctly with all help modes and preset configurations

Submission Checklist

@github-actions github-actions bot added documentation Improvements or additions to documentation project: rocprofiler-systems labels Mar 23, 2026
* Only sets variables that are not already set in the environment.
*/
void
apply_preset_to_environment(const preset_info& info, bool override_existing = false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be put in class..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants