Skip to content

增加环境报告脚本#1

Open
ghangz wants to merge 1 commit into
MetaX-MACA:mainfrom
ghangz:mengz/add-env-report-script
Open

增加环境报告脚本#1
ghangz wants to merge 1 commit into
MetaX-MACA:mainfrom
ghangz:mengz/add-env-report-script

Conversation

@ghangz

@ghangz ghangz commented Jun 10, 2026

Copy link
Copy Markdown

这次改动补上了环境报告脚本,主要是为了解决集体通信测试与结果整理流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。

实现上补充了对应工具或脚本逻辑,同步更新了相关说明,同时尽量保持现有用法不变,避免影响已有流程。

这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new script tools/collect_env.sh to collect environment information in JSON format, along with usage examples in the README.md. The review feedback provides valuable suggestions to improve the robustness of the script: handling command failures gracefully under set -euo pipefail and avoiding login shell overhead, checking for the presence of python3 before execution, and properly escaping path variables to ensure valid JSON output.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tools/collect_env.sh
Comment on lines +11 to +19
command_output() {
local cmd="$1"
local exe="${cmd%% *}"
if [[ -x "${exe}" ]] || command -v "${exe}" >/dev/null 2>&1; then
bash -lc "${cmd}" 2>&1 | head -n 5 | json_string
else
printf 'null'
fi
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

由于脚本开启了 set -euo pipefail,如果 command_output 中执行的命令(例如 ${MACA_PATH}/mxgpu_llvm/bin/mxcc --version)因为缺少依赖库或其他原因执行失败(返回非 0 状态码),整个管道会返回非 0 状态码,导致脚本立即异常退出。这会导致环境收集脚本无法输出任何 JSON 结果,违背了“收集环境信息用于排查”的初衷。

此外,使用 bash -lc 会启动一个登录 Shell,这可能会加载用户的 .bash_profile.bashrc,从而输出额外的欢迎信息(MOTD)或环境变量警告,干扰版本信息的提取。

建议:

  1. 避免使用 bash -lc,改用 bash -c
  2. 妥善处理命令失败的情况,捕获其标准错误和输出,即使命令失败也将其作为字符串写入 JSON,以便于排查。
Suggested change
command_output() {
local cmd="$1"
local exe="${cmd%% *}"
if [[ -x "${exe}" ]] || command -v "${exe}" >/dev/null 2>&1; then
bash -lc "${cmd}" 2>&1 | head -n 5 | json_string
else
printf 'null'
fi
}
command_output() {
local cmd="$1"
local exe="${cmd%% *}"
if [[ -x "${exe}" ]] || command -v "${exe}" >/dev/null 2>&1; then
local out
out=$(bash -c "${cmd}" 2>&1 | head -n 5) || true
printf '%s' "${out}" | json_string
else
printf 'null'
fi
}

Comment thread tools/collect_env.sh
Comment on lines +4 to +5
MACA_PATH="${MACA_PATH:-/opt/maca}"
TEST_DIR="${TEST_DIR:-${MACA_PATH}/samples/mccl_tests/perf/mccl_perf}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

由于脚本依赖 python3 来处理 JSON 字符串转义,如果运行环境未安装 python3,脚本会在执行到 json_string 时报错退出。建议在脚本开头增加对 python3 是否存在的检查,并给出友好的错误提示。

Suggested change
MACA_PATH="${MACA_PATH:-/opt/maca}"
TEST_DIR="${TEST_DIR:-${MACA_PATH}/samples/mccl_tests/perf/mccl_perf}"
MACA_PATH="${MACA_PATH:-/opt/maca}"
TEST_DIR="${TEST_DIR:-${MACA_PATH}/samples/mccl_tests/perf/mccl_perf}"
if ! command -v python3 >/dev/null 2>&1; then
echo "Error: python3 is required to run this script." >&2
exit 1
fi

Comment thread tools/collect_env.sh
Comment on lines +23 to +24
"maca_path": "$(printf '%s' "${MACA_PATH}")",
"test_dir": "$(printf '%s' "${TEST_DIR}")",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

如果 MACA_PATHTEST_DIR 路径中包含特殊字符(例如双引号、反斜杠等),直接拼接到 JSON 中会导致生成的 JSON 格式失效。既然已经定义了 json_string 函数,建议直接利用它来对路径进行安全转义,同时去掉模板中硬编码的双引号。

Suggested change
"maca_path": "$(printf '%s' "${MACA_PATH}")",
"test_dir": "$(printf '%s' "${TEST_DIR}")",
"maca_path": $(printf '%s' "${MACA_PATH}" | json_string),
"test_dir": $(printf '%s' "${TEST_DIR}" | json_string),

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant