Skip to content

Commit 5c74cb5

Browse files
committed
docs: 补充UbDiag两层分发用户指南
1 parent 9b8a428 commit 5c74cb5

1 file changed

Lines changed: 155 additions & 0 deletions

File tree

docs/ubdiag_integration_guide.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Mooncake UbDiag 两层分发使用指南
2+
3+
Mooncake 通过统一的 CMake 接口提供 UbDiag 两层分发能力。默认模式将
4+
PerfPoint 编译为空实现;启用模式从同一份 UbDiag 源码同步构建 SDK 动态库
5+
与命令行工具,供 Mooncake 性能采集与分析使用。
6+
7+
## 1. 模式选择
8+
9+
| 模式 | CMake 选项 | 适用场景 | 构建产物 |
10+
|------|------------|----------|----------|
11+
| Layer 0:禁用模式 | `MOONCAKE_ENABLE_UBDIAG=OFF`(默认) | 不需要性能采集,保持零运行时依赖 | 仅使用 UbDiag 头文件;不生成或链接 `libubdiag` |
12+
| Layer 1:启用模式 | `MOONCAKE_ENABLE_UBDIAG=ON` | 使用 PerfPoint、分位数、PerfLog 和 CSV 分析 Mooncake | 同步生成 `libubdiag.so``ubdiag` CLI |
13+
14+
模式由编译期选项决定,不能在运行时切换。建议为两种模式使用独立构建目录。
15+
16+
## 2. 默认禁用模式
17+
18+
未指定 `MOONCAKE_ENABLE_UBDIAG` 时,Mooncake 默认使用 Layer 0:
19+
20+
```bash
21+
cmake -S . -B build
22+
cmake --build build -j
23+
```
24+
25+
也可以显式指定:
26+
27+
```bash
28+
cmake -S . -B build -DMOONCAKE_ENABLE_UBDIAG=OFF
29+
cmake --build build -j
30+
```
31+
32+
CMake 配置阶段应输出:
33+
34+
```text
35+
UbDiag: UBDIAG_DISABLE(空函数,零依赖)
36+
```
37+
38+
该模式使用 UbDiag `v0.5.1` 的同一份公共头文件,并通过
39+
`UBDIAG_DISABLE` 将 PerfPoint 编译为空函数。Mooncake 无需启动 UbDiag,
40+
也不需要安装 CLI 或动态库。可使用以下命令确认目标程序未链接 UbDiag:
41+
42+
```bash
43+
ldd <mooncake-binary> | grep libubdiag
44+
```
45+
46+
命令应无输出。
47+
48+
## 3. 启用 UbDiag
49+
50+
需要采集 Mooncake PerfPoint 数据时,使用独立目录重新配置并构建:
51+
52+
```bash
53+
cmake -S . -B build-ubdiag -DMOONCAKE_ENABLE_UBDIAG=ON
54+
cmake --build build-ubdiag -j
55+
```
56+
57+
CMake 配置阶段应输出:
58+
59+
```text
60+
UbDiag: FetchContent 编译 v0.5.1(库+CLI)
61+
```
62+
63+
默认构建目录下的关键产物为:
64+
65+
```text
66+
build-ubdiag/_deps/ubdiag-build/src/sdk/libubdiag.so
67+
build-ubdiag/_deps/ubdiag-build/src/cli/ubdiag
68+
```
69+
70+
运行前应使用本次构建生成的 CLI 和动态库:
71+
72+
```bash
73+
export UBDIAG_BUILD="$PWD/build-ubdiag/_deps/ubdiag-build"
74+
export UBDIAG_CLI="$UBDIAG_BUILD/src/cli/ubdiag"
75+
export LD_LIBRARY_PATH="$UBDIAG_BUILD/src/sdk${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
76+
```
77+
78+
不得混用系统中其他版本的 `ubdiag` CLI 或 `libubdiag.so`。CLI 与 SDK
79+
必须来自同一源码版本和同一次构建,以保证共享内存布局及功能开关一致。
80+
81+
## 4. 采集与分析
82+
83+
启动 UbDiag 共享内存,并启用 PerfLog:
84+
85+
```bash
86+
"$UBDIAG_CLI" start --perflog
87+
"$UBDIAG_CLI" status
88+
```
89+
90+
随后按 Mooncake 原有方式启动服务和业务负载。负载运行期间可执行:
91+
92+
```bash
93+
"$UBDIAG_CLI" show
94+
"$UBDIAG_CLI" show --detail
95+
"$UBDIAG_CLI" show --perflog
96+
"$UBDIAG_CLI" watch --interval 1000
97+
"$UBDIAG_CLI" history -n 5
98+
```
99+
100+
其中 `show` 输出聚合统计及 P99/P999/P9999,`show --detail` 输出按核数据,
101+
`show --perflog` 输出最近的单次探针记录。`watch` 使用 `Ctrl+C` 结束。
102+
103+
将分析结果导出为 CSV:
104+
105+
```bash
106+
mkdir -p ./ubdiag-results
107+
"$UBDIAG_CLI" show --csv ./ubdiag-results
108+
"$UBDIAG_CLI" show --detail --csv ./ubdiag-results
109+
"$UBDIAG_CLI" history --csv ./ubdiag-results
110+
```
111+
112+
分析结束后销毁共享内存:
113+
114+
```bash
115+
"$UBDIAG_CLI" stop
116+
```
117+
118+
## 5. 离线源码
119+
120+
构建环境无法访问 GitHub 时,预先准备精确版本的 UbDiag 源码,并通过
121+
`MOONCAKE_UBDIAG_SOURCE_DIR` 指定绝对路径:
122+
123+
```bash
124+
git clone --branch v0.5.1 https://github.com/LinQuickDev/ubdiag.git /opt/src/ubdiag
125+
cmake -S . -B build-ubdiag \
126+
-DMOONCAKE_ENABLE_UBDIAG=ON \
127+
-DMOONCAKE_UBDIAG_SOURCE_DIR=/opt/src/ubdiag
128+
cmake --build build-ubdiag -j
129+
```
130+
131+
`MOONCAKE_UBDIAG_SOURCE_DIR` 同样适用于默认禁用模式;将上述命令中的
132+
`MOONCAKE_ENABLE_UBDIAG` 改为 `OFF` 即可。两种模式均不会在已指定本地
133+
源码时访问 UbDiag 远端仓库。
134+
135+
推荐校验源码版本:
136+
137+
```bash
138+
git -C /opt/src/ubdiag rev-parse HEAD
139+
```
140+
141+
预期提交为 `705c6c37da45df2be4bc64c134dca0b7f30b2113`
142+
143+
## 6. 验收标准
144+
145+
| 检查项 | Layer 0 | Layer 1 |
146+
|--------|---------|---------|
147+
| Mooncake 可正常编译和运行 | 必须 | 必须 |
148+
| 目标程序链接 `libubdiag` |||
149+
| 生成 `ubdiag` CLI |||
150+
| `show` 返回 Mooncake PerfPoint 数据 | 不适用 | 必须 |
151+
| P99/P999/P9999、PerfLog、CSV | 不适用 | 必须 |
152+
153+
若启用模式下 CLI 无数据,应依次确认共享内存已启动、Mooncake 使用的是
154+
`build-ubdiag` 产物、运行时加载的是同目录 `libubdiag.so`,以及业务负载已
155+
实际经过 Mooncake PerfPoint 打点路径。

0 commit comments

Comments
 (0)