跳转至

模块化与边界

本文定义 核心模块 vs 功能模块、公共接口、依赖规则与建议 ownership,目标是让并行开发互不打扰。

配合阅读:启用、注入与运行时控制、数据层、 扩展机制;术语见核心概念。


1. 分层模型

Probing 分四层。依赖只能向下(上层可调用下层,反之禁止)。

模块依赖方向与采集器隔离边界

层 职责 典型变更
L1 平台 SQL 引擎、存储、协议、插件 trait federation、memtable、config
L2 采集 写表 + 可选 Extension 控制 GPU、NCCL、主机、Python 运行时
L3 控制面 HTTP、CLI、组装根 新 endpoint、认证、cluster fan-out
L4 体验 UI、skills、extensions、Python 集成 诊断 UX、Agent、hooks、厂商扩展发现

组装根(唯一允许「把所有模块接在一起」的地方):

  • probing/server/src/engine.rs — 注册全部 ProbeDataSource + ProbeExtension
  • 根目录 src/lib.rs + Cargo.toml — wheel 打包 server + python 扩展

2. Crate 与目录对照

L1 — 平台核心(接口应稳定)

单元 路径 职责 禁止
probing-proto probing/proto/ 消息、DataFrame、Node、Query DTO 依赖 core/server/扩展
probing-memtable probing/memtable/ MEMT/MEMH/MEMC、mmap 发现 感知 SQL/HTTP/Python
probing-core probing/core/ DataFusion、federation、config、trait 依赖 server/cli/扩展
probing-macros probing/macros/ ProbeExtension 派生宏 业务逻辑

核心子模块:

子模块 路径 契约
Engine core/engine.rs async_query、enable(ProbeDataSource)
Federation core/federation/ global.*、六列联邦标签 — 联邦查询引擎
Memtable SQL core/memtable_sql.rs mmap → TableProvider
Config config.rs KV + extension options

L2 — 采集器(功能模块)

各采集器只写数据,彼此不互相调用。

单元 路径 表 / schema Extension
probing-python probing/extensions/python/ python.* PythonExt、Torch、Pprof
probing-cc probing/extensions/cc/ cpu.*、cluster.nodes、rdma.*… Cpu、Rdma
probing-gpu probing/extensions/gpu/ gpu.* Gpu
probing-nccl-profiler probing/extensions/nccl-profiler/ nccl.proxy_ops、nccl.net_qp 仅 NCCL ABI

Python 侧采集(同层,不同语言):

单元 路径 表
Torch python/probing/profiling/ torch_trace、comm_collective
Span python/probing/tracing/ trace_event
并行 role python/probing/parallel.py 写入 role 列
用户插件 python/probing/ext/ @table → python.*

L3 — 控制面

单元 路径 职责
probing-server probing/server/ 路由、认证、initialize_engine()、fan-out、torchrun 心跳(torchrun_cluster.rs)
probing-cli probing/cli/ HTTP 客户端;inject/query/repl/skill

HTTP 契约:probing/server/API.md + tests/regression/spec/api_spec.json。

宿主进程不变量: probing-server 寄生在被观测应用内。engine、listener 或上报组件故障时, 不得调用 process::exit、中止进程或以其他方式终止宿主;故障必须限制在 probing 内部,并通过 组件状态、日志和 readiness 暴露。

L4 — 体验层

单元 路径 职责
web/ Dioxus 页面、可视化、Investigate Agent
skills/ 符号链接 → python/probing/bundled_skills/ skill 内容 SSOT 的编写别名
probing-skills probing/crates/skills/ 共享 loader、解释器、runner(CLI / Web / MCP)
python/probing/extensions/ entry points Skills + magics + 厂商包发现(代码 SSOT)
python/probing/ Python 包 hooks、query()、agent 安装辅助

3. 公共接口(契约)

新功能应扩展下列契约之一,而不是新增跨模块直连。

3.1 ProbeDataSource — 注册 SQL 表

定义: probing/core/src/core/data_source.rs 注册: EngineBuilder::with_data_source(在 server/engine.rs 接线)

类型 场景 示例
Table 固定 schema gpu.devices
Namespace 动态表 python.*、mmap 发现

规则: schema/scan 在采集 crate 内;跨信号用 SQL JOIN,不在 scan() 里调别的采集器。

3.2 ProbeExtension — 类型化配置与 HTTP 契约

定义: probing/core/src/core/probe_extension.rs

能力 机制
身份 ProbeExtension::name 定义注册命名空间
配置 ProbeExtensionConfig 声明 key/alias 并实现 set / get / options
副作用 set_* 里启停采样线程
HTTP ProbeExtensionCall::routes 声明 method/content-type/CORS/readiness,call 负责执行

规则: 注册阶段校验扩展名、重复 route、配置 key/alias 冲突;数据走表,控制走 Extension;trait 默认实现禁止 todo!()。

3.3 Python @table — 应用数据插件

见 扩展机制。训练行应带 local_step、global_step、rank、role(见 核心概念)。

3.4 Skill 契约 — 诊断工作流

SSOT: python/probing/bundled_skills/<id>/ + catalog.yaml(仓库根 skills/ 为符号链接别名)

字段 作用
requires.any_tables 前置条件
spec.steps[].sql 唯一引擎接口
interpretation.rules 确定性结论
next_steps 技能链

规则: Skill 只通过 SQL / 文档化 HTTP 访问数据;不含 Rust/Python 业务代码。

  • 内容 SSOT: python/probing/bundled_skills/(仓库根 skills/ 为指向该目录的符号链接别名)。
  • 发现: python/probing/extensions/ entry point + GET /apis/pythonext/skills/*。
  • 执行 SSOT: probing-skills — CLI(probing/cli/skill/)、Web WASM (web/src/agent/runner.rs)、MCP(server 内 run_skill / plan_skill)。
  • Python probing/skills/ 仅负责发现与 agent 安装,不是执行路径。

3.5 线协议 — CLI / Web ↔ Server

定义: probing/proto/

Endpoint 载荷
POST /query Message<Query> → Message<Data>
POST /query/dto 稳定外部 DTO
GET /apis/* 按 API.md 返回 JSON / SVG
GET /ws REPL

规则: CLI / Web 运行时不得链接 probing-core(CLI 仅 proto;Web 仅 HTTP + proto 类型)。破坏性 API 变更须同步 api_spec.json 与契约测试。

3.6 Federation 标签(固定,勿自创)

列 含义
_host 对端主机
_addr 对端地址
_rank torch rank
_node_rank 节点 / worker 组 rank(GROUP_RANK)
_local_rank 节点内 GPU 序号(LOCAL_RANK)
_role 并行 role key

4. 依赖规则

依赖只沿公开契约向下,采集器之间彼此隔离

依赖矩阵(目标态)

proto memtable core cc/gpu/py server cli
proto —
memtable —
core ✓ ✓ —
extensions ✓ ✓ ✓ —
server ✓ ✓ ✓ ✓ —
cli ✓ opt —
web ✓

4.1 PyPI 打包耦合(cdylib → probing-cli)

Maturin 只构建 一个 native 产物(根 Cargo.toml 的 probing._core cdylib)。PyPI 上的 probing 命令 不是 独立 Rust 二进制:

Wheel 在根动态库中组装 CLI 入口,但不形成运行时反向依赖

这是为适配 maturin wheel 工作流(pyproject.toml 的 [tool.maturin] + [project.scripts])的 可接受编译期耦合,不是采集器在运行时反向调用控制面。

契约(保持边界薄):

  • 根 src/lib.rs(maturin cdylib 组装根)可调用 probing_cli::pyo3::cli_main 并导出为 _core.cli_main。probing-python 本身不依赖 probing-cli。
  • 禁止 从采集器/server 引用 cli 的 inject、skill 内部、ctrl 等模块。
  • 非 PyPI 安装仍可选用独立 Rust binary(cli/src/main.rs);PyPI 用户走 Python 入口。

若 CLI 继续膨胀,可拆 probing-cli-lib(共享 cli_main + HTTP 客户端),而不是让 采集器或 cdylib 扩散 import cli crate 内部。


训练写入与查询读取通过表契约汇合

推论: 新指标 → 新表;跨信号分析 → SQL 或 skill; retention 只动 memtable 配置。


6. 按关注点划界

关注点 归属 接口
SQL 解析、federation 重写 probing-core Engine::async_query
表/列语义文档 probing-core 代码优先 docs 注册表 + resources/tables.yaml overlay → probe.probing.table_docs / column_docs
mmap 格式、冷压缩 probing-memtable RowWriter, ColdStore
Torchrun 集群心跳 probing-server torchrun_cluster.rs、cluster_report_backoff.rs、PUT /apis/nodes
混合 Python/C 栈 probing-python/features python.backtrace、pprof
macOS 线程 SIGUSR2 probing-core signal::send_sigusr2_to_thread_id
Torch 模块采样 python/profiling python.torch_trace
Collective 墙钟 python/profiling/collective python.comm_collective
PyTorch Flight Recorder 桥接 python/profiling/flight_recorder python.torch_nccl_flight_record, python.torch_nccl_pg_status
NCCL wait 分解 nccl-profiler nccl.proxy_ops
主机 CPU / RDMA probing-cc cpu.*, rdma.*
GPU 显存 / 利用率 probing-gpu gpu.*
集群节点注册 core/cluster + server/report cluster.nodes、PUT/GET /apis/nodes
跨 rank fan-out server/cluster_fanout global.*、/apis/cluster/query
认证、限流 probing-server middleware
inject、query CLI probing-cli HTTP → server
诊断 skill skills/ steps.yaml
Training step 矩阵 UI web/src/next/pages/training.rs GET /apis/training/step_matrix
Agent 路由 web/agent + skills catalog skill 元数据

7. 建议 Ownership

团队域 路径 可独立演进
平台 core, memtable, proto, macros 不碰采集器
主机/GPU extensions/cc, extensions/gpu 不碰 Python/web
运行时 Python extensions/python, python/probing/profiling 不碰 NCCL 插件
NCCL nccl-profiler, python/nccl 不碰 Torch hooks
控制面 server, cli 不碰 skill 内容
诊断 skills/, cli/skill, web/agent 不碰采集内部
Web UI web/(agent loader 除外) 不碰 Rust 采集

合入前自检:

  1. 依赖方向是否正确?
  2. 新数据是否只通过表 / @table?
  3. 新诊断是否只加 skill,而非 server 特例?
  4. HTTP 变更是否更新 API.md + api_spec?
  5. Federation 是否只用标准标签?

8. 已知边界违规(技术债)

问题 现状 目标
python → cli ~~probing-python → probing-cli~~ 已完成 — 无 crate 依赖;wheel cli_main 仅在根 src/lib.rs 组装(§4.1)
python → cc ~~probing-python → probing-cc~~ 已完成 — send_sigusr2_to_thread_id 迁至 probing-core::signal
core → NCCL/HCCL ~~probing-core → nccl/hccl shim(builtin-schema-docs)供 semantic_catalog~~ 已完成 — register_docs() 在 server/engine.rs 组装根调用;probing-core 默认 feature 为空
core → skills YAML ~~semantic_catalog include_str!(skills/semantic/tables.yaml)~~ 已完成 — overlay 在 probing/core/resources/tables.yaml;描述 SSOT 为 docs 注册表
server → python features ~~server/profiling.rs / training 火焰图 handler~~ 已完成 — 火焰图仅走 torchextension / pprofextension ProbeExtensionCall
server → REPL 内部 ~~PythonRepl~~ /ws 仅用 ReplSession 门面
组装集中 全在 server/engine.rs 可选 extension manifest
Skill 三份 loader ~~Rust/Python/Web 编译期 embed~~ 已完成 — probing-skills 为 loader/interpret/runner SSOT;Python 保留发现 entry point + PyO3 序列化桥;Web 从 API 反序列化为共享类型
kmsg 采集器 已注册(Linux/kmsg feature gate) Done

集群成员与外部运行时表

cluster.nodes 的现行成员来源是 Torchrun 集群心跳:L3 probing-server 通过分层 HTTP PUT 和 TCPStore 旁路键注册 rank,不写 torch rendezvous 键。Rust ctor 默认调用 maybe_start_torchrun_cluster();细节见 分布式成员与控制面。

pulsing.* 只是被 mmap catalog 发现的外部表,与其他厂商表遵守相同的数据源契约。Probing 目前不会把 Pulsing gossip 成员自动合并进 cluster.nodes,也没有由 Probing 启动 Pulsing ActorSystem 的现行实现。


9. 新功能决策树

新能力依据新增的事实和状态选择所属模块

反模式: 在 engine.rs 写业务;Web 查不存在的表;采集器在写路径里 query;Skill 内嵌 Rust 分支;在 probing-skills 之外执行 skill(Python/Web 重复 runner)。


10. 相关文档

文档 范围
启用、注入与运行时控制 运行时进入目标进程和服务就绪
数据层 MEMT/MEMC 内部实现
扩展机制 对外扩展路径(表 + skill + NCCL)
分布式 联邦与集群
分布式成员与控制面 分层 torchrun 成员注册与健康状态
分布式 Profiler 查询与可视化 万 Rank Timeline 查询和可视化目标设计
NCCL Profiler NCCL 插件边界
web/DESIGN.md 前端模块布局
AGENTS.md Agent 使用 skill