Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions projects/rocprofiler-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ Full documentation for ROCprofiler-SDK is available at [rocm.docs.amd.com/projec

### Added

**rocprofv3 (CLI):**

- `rocprofv3 --doctor` setup check:
- New `rocprofv3 --doctor` option that inspects the ROCprofiler-SDK installation and system configuration and reports what would prevent profiling from working, with a fix for each problem.
- Covers 10 check groups: installation, driver/device, runtime stack, counter collection, environment variables, container/virtualization, Python environment, filesystem, companion tools, and optional live smoke tests.
- Verifies that the ROCm libraries actually load (missing dependencies, mixed ROCm versions, old `libstdc++`), not only that they exist, and explains failed or crashed commands by matching their output against known error messages. Each diagnosis separates what the output shows from the candidate cause, and rates the cause `likely` only when facts on the machine corroborate it.
- Every check declares what it does to the machine (`passive`, `process`, or `gpu`); child processes are time-limited and their whole process tree is killed on timeout, Python package imports run in a child process, and the only file written is an exclusively-created temporary probe.
- Human-readable grouped text output with color-coded status and a copy-pasteable remediation section; machine-readable JSON output with a versioned schema for CI consumption.
- Extensible check framework with decorator-based registration; prerequisites run first and are pulled into `--only` selections, and skip propagation keeps one root cause from cascading. A check that breaks is reported as `error` (a doctor bug), never as a system failure.
- Exit code 0 (warnings only), 1 (at least one failure), 2 (tool error, an `--only` pattern matching no check, or a broken check with no failures).
- Works with every ROCm installation layout, not only `/opt/rocm`: legacy system packages, TheRock system packages (`/opt/rocm/core-X.Y`), TheRock Python packages, tarballs, and custom prefixes. The inspected root, how it was found, and the installation type are reported, and remediation commands match the installation type.

### Changed

### Resolved issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ set_property(
TARGET @PACKAGE_NAME@::rocprofv3-avail
PROPERTY IMPORTED_LOCATION ${@PACKAGE_NAME@_ROOT_DIR}/@CMAKE_INSTALL_BINDIR@/rocprofv3-avail)

# the script behind `rocprofv3 --doctor`; installed in libexec, not on PATH
add_executable(@PACKAGE_NAME@::rocprofv3-doctor IMPORTED)
set_property(
TARGET @PACKAGE_NAME@::rocprofv3-doctor
PROPERTY IMPORTED_LOCATION
${@PACKAGE_NAME@_ROOT_DIR}/@CMAKE_INSTALL_LIBEXECDIR@/rocprofiler-sdk/rocprofv3-doctor)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
@PACKAGE_NAME@
Expand Down
94 changes: 85 additions & 9 deletions projects/rocprofiler-sdk/source/bin/rocprofv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
"rocm_version": "@rocm_version_FULL_VERSION@",
}

# `rocprofv3 --doctor` execs this script. SYNC: DOCTOR_FLAG and DOCTOR_COMMAND in
# source/lib/python/rocprofv3/doctor_result.py, and source/libexec/rocprofiler-sdk/
# rocprofv3-doctor/CMakeLists.txt for where it is installed.
DOCTOR_FLAG = "--doctor"
DOCTOR_LIBEXEC_DIR = "@CMAKE_INSTALL_LIBEXECDIR@"

# Perfetto's TraceConfig BufferConfig.size_kb field is a uint32_t, and the
# tracing service allocates size_kb * 1024 bytes and rejects the config when
# that byte count does not fit in a uint32_t. So although the option is named
Expand Down Expand Up @@ -348,7 +354,6 @@ def resolve_library_path(val, args, is_sdk_lib=True):


def get_att_paths(args):

ROCPROFV3_DIR = os.path.dirname(os.path.realpath(__file__))
ROCM_DIR = os.path.dirname(ROCPROFV3_DIR)
if args.rocm_root is not None:
Expand Down Expand Up @@ -377,7 +382,6 @@ def get_att_paths(args):


def check_att_capability(args, att_lib_name="librocprof-trace-decoder.so"):

library_paths = get_att_paths(args)

for path in library_paths:
Expand Down Expand Up @@ -478,7 +482,6 @@ def __call__(self, parser, args, values, option_string=None):


def parse_arguments(args=None):

usage_examples = """

%(prog)s requires double-hyphen (--) before the application to be executed, e.g.
Expand Down Expand Up @@ -1177,6 +1180,18 @@ def add_parser_bool_argument(gparser, *args, **kwargs):
default=True,
)

# NOTE: --doctor is intercepted in main() before parse_arguments() runs, so
# this entry exists only to document the flag in --help. Any remaining
# arguments are forwarded verbatim to the doctor, which is why the
# interception cannot be deferred to argparse: flags such as --format have
# incompatible meanings in the two.
advanced_options.add_argument(
DOCTOR_FLAG,
action="store_true",
help="""Check whether this machine and ROCm installation are ready for profiling, report what would stop rocprofv3 from working and how to fix it, then exit. Options after --doctor configure the check (for example: rocprofv3 --doctor --format json); see rocprofv3 --doctor --help.""",
default=False,
)

add_parser_bool_argument(
advanced_options,
"--attach-sync-output",
Expand Down Expand Up @@ -1392,7 +1407,6 @@ def _dedup(_line, _sep):


def parse_input(input_file):

_, extension = os.path.splitext(input_file)
if extension == ".txt" or extension == ".text":
warning("""
Expand Down Expand Up @@ -1608,7 +1622,6 @@ def int_auto(num_str):


def run(app_args, args, **kwargs):

app_env = dict(os.environ)
use_execv = kwargs.get("use_execv", True)
app_pass = kwargs.get("pass_id", None)
Expand Down Expand Up @@ -2120,7 +2133,6 @@ def convert_triplet(delay, duration, repeat):
update_env(f"ROCPROF_{env_val}", val, overwrite=True)

def log_config(_env):

cfg_init_message = "\n- rocprofv3 configuration{}:\n".format(
"" if app_pass is None else f" (pass {app_pass})"
)
Expand Down Expand Up @@ -2309,7 +2321,6 @@ def log_config(_env):
)

if args.pc_sampling_unit or args.pc_sampling_method or args.pc_sampling_interval:

if (
not args.pc_sampling_beta_enabled
and os.environ.get("ROCPROFILER_PC_SAMPLING_BETA_ENABLED", None) is None
Expand Down Expand Up @@ -2339,7 +2350,6 @@ def log_config(_env):
update_env("ROCPROF_PC_SAMPLING_INTERVAL", args.pc_sampling_interval)

if args.spm or args.spm_sample_interval or args.spm_sample_interval_unit:

if (
not args.spm_beta_enabled
and os.environ.get("ROCPROFILER_SPM_BETA_ENABLED", None) is None
Expand Down Expand Up @@ -2392,7 +2402,6 @@ def log_config(_env):
update_env("ROCPROF_MINIMUM_OUTPUT_BYTES", args.minimum_output_data * 1024)

if args.advanced_thread_trace:

update_env("ROCPROF_ADVANCED_THREAD_TRACE", True, overwrite=True)
update_env("ROCPROF_ATT_NO_INTERCEPT", args.att_no_intercept, overwrite=True)

Expand Down Expand Up @@ -2537,7 +2546,74 @@ def log_config(_env):
return exit_code


def find_doctor_script():
"""Path of the script behind --doctor, or None.

Installed and build trees keep it at <prefix>/<libexecdir>/rocprofiler-sdk/;
a source checkout keeps it under source/libexec/.
"""
prefix = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
libexec_dirs = ["libexec"]
if not DOCTOR_LIBEXEC_DIR.startswith("@"):
libexec_dirs.insert(0, DOCTOR_LIBEXEC_DIR)
candidates = [
os.path.join(prefix, libexec_dir, "rocprofiler-sdk", "rocprofv3-doctor")
for libexec_dir in libexec_dirs
]
candidates.append(
os.path.join(
prefix,
"libexec",
"rocprofiler-sdk",
"rocprofv3-doctor",
"rocprofv3-doctor.py",
)
)
for candidate in candidates:
if os.path.isfile(candidate):
return candidate
return None


def dispatch_doctor(raw_args):
"""Replace this process with the doctor, passing the remaining arguments.

Intercepted before parse_arguments() because rocprofv3 and the doctor both
define --format and --output with different meanings; letting argparse see
the doctor's flags would be an error rather than a passthrough.

exec rather than a child process: no rocprofv3 process lingers while the
doctor runs (it would otherwise appear to the doctor as a running
profiler), and signals and the exit status pass straight through.
Returns only when the doctor cannot be started.
"""
args = [itr for itr in raw_args if itr != DOCTOR_FLAG]
script = find_doctor_script()
if script is None:
sys.stderr.write(
"rocprofv3: the {} component is not installed next to this rocprofv3 "
"({}); reinstall rocprofiler-sdk\n".format(
DOCTOR_FLAG, os.path.dirname(os.path.realpath(__file__))
)
)
return 2

sys.stdout.flush()
sys.stderr.flush()
try:
os.execv(sys.executable, [sys.executable, script] + args)
except OSError as exc:
sys.stderr.write("rocprofv3: cannot run {} ({})\n".format(script, exc))
return 2


def main(argv=None):
raw_args = list(sys.argv[1:] if argv is None else argv)
# only rocprofv3's own options count: everything after "--" belongs to the
# application and must reach it verbatim, "--doctor" included
profiler_args = raw_args[: raw_args.index("--")] if "--" in raw_args else raw_args
if DOCTOR_FLAG in profiler_args:
return dispatch_doctor(profiler_args)

cmd_args, app_args = parse_arguments(argv)

Expand Down
1 change: 1 addition & 0 deletions projects/rocprofiler-sdk/source/docs/_toc.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ subtrees:
- file: how-to/kernel-naming-filtering
- file: how-to/rocprofv3-io-options
- file: how-to/using-rocprofv3-avail
- file: how-to/using-rocprofv3-doctor
- file: how-to/using-rocprofv3-process-attachment
- file: how-to/using-rocpd-output-format
- file: how-to/using-rocprofiler-sdk-roctx
Expand Down
Loading
Loading