コンテンツにスキップ

Topics で読み物として読む

この HLD は実装詳細を含みます。機能の概念・設定・運用を読み物として読みたい場合は Topics 11 章: Reboot / Warm/Fast/Express/Cold を参照。

裏取りステータス: code-verified

verifier-batch-18 で確認:

  • sonic-buildimage/rules/configINCLUDE_BOOTCHART = y(systemd-bootchart のインストール有効)と ENABLE_BOOTCHART = n(boot 時自動起動は default off)を確認
  • sonic-utilities/scripts/sonic-bootchart に CLI 実装、tests/sonic_bootchart_test.py に単体テストを確認
  • /etc/systemd/bootchart.conf の Samples=4500 / Frequency=25 のデフォルト値、/run/log への SVG 出力パス、sonic-installer の migration 詳細は本リポでは追跡していない(HLD 記述準拠)

SONiC Boot Chart(systemd-bootchart 統合)

概要

SONiC は モジュール構成 で、各機能はスクリプト・ユーティリティ・daemon・docker container として実装される。多くの起動スクリプトが Jinja2 テンプレート展開や Python / Bash の短命プロセスを起動するため、boot 時間の劣化を引き起こしやすい1

HLDsystemd-bootchart を SONiC に統合し、boot プロセスの sampling profiling を行う仕組みを定義する。出力は SVG で可視化される。

要件1:

  • systemd-bootchart を SONiC OS に統合し、default install / default disable
  • ユーザは CLI で enable / disable
  • sample 数 / 頻度を CLI で設定可能
  • 設定 / 生成 SVG を表示

動作仕様

ビルド時オプション

INCLUDE_BOOTCHART=y/n で SONiC build に含めるかを制御する1:

make INCLUDE_BOOTCHART=y target/sonic-mellanox.bin   # 含める
make INCLUDE_BOOTCHART=n target/sonic-mellanox.bin   # 含めない

y の場合、Debian upstream から systemd-bootchart パッケージ(128 KB)を SONiC host に install する。

ENABLE_BOOTCHART=ydefault 状態の有効化 を制御するフラグも追加される。

既定設定

/etc/systemd/bootchart.conf に SONiC 既定値を提供1:

[Bootchart]
Samples=4500
Frequency=25

これは 3 分間 × 25 sample/sec = 4500 sample を収集する設定。

sonic-bootchart CLI

sonic-utilitiesscripts/ に新ユーティリティ sonic-bootchart を追加する。位置付けは sonic-kdump-configsonic-installer に近いスタンドアロン CLI1:

admin@sonic:~$ sudo sonic-bootchart
Usage: sonic-bootchart [OPTIONS] COMMAND [ARGS]...

Commands:
  config   Configure bootchart  (要 root)
  disable  Disable bootchart    (要 root)
  enable   Enable bootchart     (要 root)
  show     Display bootchart configuration

enable / disable

admin@sonic:~$ sudo sonic-bootchart enable
Running command: systemctl enable systemd-bootchart
admin@sonic:~$ sudo sonic-bootchart disable
Running command: systemctl disable systemd-bootchart

INCLUDE_BOOTCHART=n でビルドした image でこれを叩くとエラー1:

admin@sonic:~$ sudo sonic-bootchart enable
systemd-bootchart is not installed

enable は 永続的config save / config reload の影響を受けず、disable するまで boot 毎に走る1

config

admin@sonic:~$ sudo sonic-bootchart config --time-span 50 --frequency 10

このコマンドが /etc/systemd/bootchart.conf を直接更新する。次回 boot から 新値が使われる。

samples = frequency × time-span で換算される。

show

admin@sonic:~$ sudo sonic-bootchart show
Status     Operational Status   Frequency  Time Span (sec)  Output
enabled    in-active            10         50               /run/log/bootchart-20220504-1325.svg
フィールド 意味
Status systemctl is-enabled systemd-bootchart 出力(boot 時に走るか)
Operational Status systemctl is-active systemd-bootchart 出力(現在 sample 収集中か)
Frequency sample/sec
Time Span 起動後何秒間 sampling するか
Output 完了している場合に SVG パスを表示。未完了なら空

出力先

systemd-bootchart は SVG を /run/log/ に保存する。/run は tmpfs のため reboot で消える1。永続化したければ /var/log/ 等にコピーする運用が必要。

フロー

sequenceDiagram
    participant U as user
    participant CLI as sonic-bootchart
    participant SD as systemd
    participant BC as systemd-bootchart
    participant FS as /run/log
    U->>CLI: sudo sonic-bootchart enable
    CLI->>SD: systemctl enable systemd-bootchart
    U->>U: sudo reboot
    SD->>BC: 起動 (boot 早期)
    loop 3 minutes (default)
        BC->>BC: 25 Hz sampling
    end
    BC->>FS: bootchart-<ts>.svg 出力
    U->>CLI: sudo sonic-bootchart show
    CLI->>FS: SVG 一覧表示

設定

CLI / YANG / CONFIG_DB

本機能は YANG / CONFIG_DB に変更なし1/etc/systemd/bootchart.conf の直接書き換えで設定する独立ユーティリティ。

Command 用途
sudo sonic-bootchart enable 次回起動以降の sampling を有効化
sudo sonic-bootchart disable 無効化
sudo sonic-bootchart config --time-span <s> --frequency <hz> 収集パラメータ更新
sudo sonic-bootchart show 状態 / 出力 SVG を表示

設定例

# Image が INCLUDE_BOOTCHART=y でビルドされていることが前提
sudo sonic-bootchart enable

# 50 秒 × 10 Hz = 500 samples に縮小
sudo sonic-bootchart config --time-span 50 --frequency 10

# reboot して計測
sudo reboot

# 戻ってきたら SVG を確認
sudo sonic-bootchart show

制限事項

  • build flag が必要INCLUDE_BOOTCHART=y でビルドされていない image では使えない1
  • 出力先 /run/logtmpfs のため reboot で消失する。永続化が必要なら別途コピー
  • 設定変更は 次回 boot から 適用。現在 boot 中の sampling は変えられない
  • HLD の Open Items1:
    • SONiC installer での bootchart 設定マイグレーション(S2S アップグレード時の引き継ぎ)
    • boot 後 runtime に sampling を実行するモードの要望
  • enable / disable 状態は config save / config reload の影響を受けない1config_db.json には載らないため

干渉する機能

  • systemd: systemd-bootchart をサービスとして管理
  • sonic-installer: INCLUDE_BOOTCHART フラグの引き継ぎ(HLD 上は Open Item)
  • boot シーケンス全体: 早期に走る daemon のため、hostcfgd / database.service 起動前から sample 開始
  • 既存 systemd-bootchart: パッケージ自体の挙動(output / config パス)に従う

トラブルシューティング

  • sonic-bootchart enablenot installed → image を INCLUDE_BOOTCHART=y で再ビルド
  • reboot 後 SVG が無い → Operational Statusin-active か(= 完了済み)、Time Span が経過しているかを確認
  • SVG が生成されているのに古いまま → /run/log/bootchart-*.svg の timestamp、最新 boot の SVG が tmpfs に存在するか
  • 設定を変えても反映されない → config 後に 必ず reboot が必要、/etc/systemd/bootchart.conf の現在値を直接確認

コマンド例

boot 所要時間の breakdown を確認する。

systemd-analyze
systemd-analyze blame | head -20
systemd-analyze critical-chain
ls /host/boot-chart/

関連リファレンス

引用元


  1. sonic-net/SONiC doc/profiling/sonic_bootchart.md @ 49bab5b5ff0e924f1ea52b3d9db0dfa4191a7c06