跳到主要内容

JSON 接口规范

本页直接由 xprobe/protocol 与 v0.7.0 生成的 26 个 schemas/*.json 提取,用于编写 --spec 输入或解析 xprobe stdout / 产物 JSON 时直接查表。

严格反序列化与命名差异
  • 所有输入与输出结构均启用 #[serde(deny_unknown_fields)]:未知字段或不支持的 schema_version 会直接反序列化失败。
  • CLI vs JSON 命名差异:命令行 --match 使用 kebab-case(first-after、stack-nested、stream-order),而 JSON match_policy 字段使用 snake_case(first_after、stack_nested、stream_order)。

输入 Spec 接口(--spec)​

1. MeasurementSpec(单边测量,schema_version: "2.0")​

字段类型必填说明
schema_version"2.0"✅协议版本
targetTargetIdentity✅{ pid: u32, process_start_time?: u64 }
start_selectorstring✅起始事件 selector
end_selectorstring✅结束事件 selector
match_policyMatchPolicy✅exact | first_after | nearest | stack_nested | stream_order
timeout_msinteger✅前台采集超时(毫秒)
measurement_mode"exact" | "aggregate"—默认 exact
samplesinteger | null—目标匹配对数(与 duration_ms 至少填其一)
duration_msinteger | null—采集窗口毫秒数
max_eventsinteger | null—事件上限
max_groupsinteger | null—aggregate 模式下最大分组数
namestring | null—可选名称

2. MeasurementGraphSpec(1–8 边测量图,schema_version: "3.0")​

字段类型必填说明
schema_version"3.0"✅协议版本
targetGraphTarget✅{ pid: u32, process_start_time?: u64 }
endpointsRecord<string, string>✅1–8 个命名端点到 selector 字符串的映射
edgesGraphEdgeSpec[]✅1–8 条边:{ name, from, to, match_policy, samples? }
timeout_msinteger✅前台采集超时(毫秒)
duration_msinteger | null—图级时长;要么每条边设 samples,要么整图设 duration_ms
max_eventsinteger | null—总事件容量上限
namestring | null—可选图名称

3. CpuSamplingSpec & SyscallAggregateSpec(schema_version: "2.0")​

  • CpuSamplingSpec 必填字段:schema_version ("2.0"), target, sample_event ("cpu_clock"), frequency_hz, duration_ms, timeout_ms, max_samples, max_groups, stack_depth, max_threads;可选:name。
  • SyscallAggregateSpec 必填字段:schema_version ("2.0"), target, duration_ms, timeout_ms, max_groups, max_inflight;可选:name。

命令输出接口(stdout JSON)​

doctor (capability.schema.json)​

字段类型必填说明
schema_version"2.0"✅协议版本
okboolean✅诊断流程是否完成(非所有采集器均可用)
capabilitiesCapabilities✅各采集器能力布尔值
environmentEnvironment✅内核、OS、NVIDIA 驱动、CUDA/CUPTI 路径与 namespace
checksSystemChecks✅各项检查状态(available | restricted | unavailable | unknown)
warningsWarning[]—附加告警

discover (discover.schema.json)​

字段类型必填说明
schema_version"2.0"✅协议版本
okboolean✅是否成功
rootTargetIdentity✅根进程身份
limitinteger✅请求的上限
total_candidatesinteger✅匹配总数
truncatedboolean✅是否因 limit 截断
candidatesCudaProcessCandidate[]✅CUDA context 持有者(PID、start_time、PPID、exe、cmdline、GPU UUID)
warningsWarning[]—如 NVML_PROCESS_UNAVAILABLE、NVML_PID_NAMESPACE_MISMATCH

validate (validate.schema.json / measurement-graph-validate.schema.json)​

字段(单边 2.0)类型必填说明
schema_version"2.0"✅Graph 校验为 "3.0"
ok / validboolean✅命令是否完成 / 配置是否通过校验
targetTargetIdentity✅目标进程身份
start / endValidatedEndpoint✅端点解析结果(Graph 校验中为 endpoints 与 edges)
match_policyMatchPolicy✅请求的策略
policy_recommendationPolicyRecommendation✅最强兼容策略、原因与备选列表
requirementsValidationRequirements✅含 agent_activation、target_mutation 与所需权限
issues / warningsValidationIssue[] / Warning[]—校验错误与警告

measure 各模式输出顶层字段对比​

模式 / Schema版本顶层必填字段顶层可选字段
单边测量 (measurement-result)3.0schema_version, ok, session_id, status, measurement, quality, correlation, clock, collection, evidencewarnings
Measurement Graph (measurement-graph-result)3.0schema_version, ok, session_id, status, target, edges, collectionartifact, name, warnings
环形触发 (trigger-result)3.0schema_version, ok, session_id, status, target, trigger, observed, windows, collection, warnings—
外部 Python 采样 (python-sample-result)3.0schema_version, ok, session_id, status, target, inventory, collectionartifact, warnings
GPU 聚合 (aggregate-inventory-result)3.0schema_version, ok, session_id, status, inventory, collectionwarnings
同窗快照 (triage-result)3.0schema_version, ok, session_id, status, target, window_ms, findings, threads, cpu_hotspots, python_hotspots, syscalls, gpu_devices, gpu_activity, sources, not_coveredcgroup, cuda_devices, gil_released_proportion, warnings
CPU 采样 (cpu-sample-inventory-result)2.0schema_version, ok, session_id, status, target, inventory, collection, symbolizationwarnings
Syscall 聚合 (syscall-aggregate-result)2.0schema_version, ok, session_id, status, target, inventory, collectionwarnings
统一错误 (error)2.0schema_version, ok (false), error ({ code, message, recoverable, details, hints })—

产物文件接口(JSONL 与 Manifest)​

  • Event JSONL(event.schema.json,2.0):
    • 必填:schema_version, session_id, event_id, sequence, source, event_type, pid, tid, timestamp_raw, timestamp_ns, clock_domain
    • 可选:attributes, cpu, cuda, host, nvtx, process_start_time, timestamp_error_ns
  • Capture Manifest(capture-manifest.schema.json,1.0):
    • 必填:schema_version, artifact, target, window, selectors, all_gpu_activity, peer_copies, dropped_records, unknown_records, capture_failed
    • 可选:cuda_devices, record_limit_reached, wall_clock
  • Python Sample JSONL(python-sample-record.schema.json,3.0):
    • 必填:timestamp_ns, pid, gil, truncated, frames
    • 可选:native, tid

具体行样例、配对键与脚本解析方法见 数据格式、时钟与脚本组合。


核心枚举值查表​

枚举名全部合法取值
SessionStatuscompleted | timed_out | cancelled | failed
QualityVerdictgood | caution
CheckStatusavailable | restricted | unavailable | unknown
AgentActivationnot_required | already_loaded | injection_required | startup_required
ClockDomainhost_monotonic | cupti | cupti_normalized_to_host_monotonic
EventSourceebpf | cupti_callback | cupti_activity | marker
EventType(20 个)host_function_entry | host_function_exit | kernel_function_entry | kernel_function_exit | tracepoint | syscall_entry | syscall_exit | cuda_api_entry | cuda_api_exit | gpu_kernel_start | gpu_kernel_end | gpu_memcpy_start | gpu_memcpy_end | gpu_memset_start | gpu_memset_end | nvtx_range_start | nvtx_range_end | python_gc_start | python_gc_end | marker
MatchPolicy(JSON)exact | first_after | nearest | stack_nested | stream_order
CorrelationConfidenceexact | high | heuristic | ambiguous
CoverageSourcelive | unverified | manifest | unverified_merge
MemcpyKindHtoD | DtoH | DtoD | HtoH | PtoP | unknown
MemoryKindunknown | pageable | pinned | device | array | managed | device_static | managed_static
TriggerKindgap | idle | duration | latency
TriageSourceKindthread_time | cgroup | cpu_sample | syscall_aggregate | gpu_health | gpu_activity | python_sample
PythonSymbolizationStatusnot_detected | inactive | active | unsupported
PythonTidSourcenative | pthread | unmapped
ExportFormatjsonl | chrome

26 个 JSON Schemas 完整索引​

所有 Schema 均由 xprobe/protocol 通过 Rust schemars 自动生成,位于仓库 schemas/ 与安装目录 share/xprobe/schemas/。

版本Schema 文件用途
3.0measurement-result.schema.json单边 measure 结果
3.0measurement-graph-spec.schema.json1–8 边 Measurement Graph 输入 spec
3.0measurement-graph-validate.schema.jsonMeasurement Graph 校验结果
3.0measurement-graph-result.schema.jsonMeasurement Graph 测量结果
3.0aggregate-inventory-result.schema.jsonGPU --aggregate 聚合清单
3.0python-sample-result.schema.json--python-sample stdout 汇总
3.0python-sample-record.schema.json--python-sample JSONL 单条样本
3.0triage-result.schema.json--triage 多源同窗快照
3.0trigger-result.schema.json--trigger-* 环形触发结果
2.0capability.schema.jsondoctor 能力诊断报告
2.0discover.schema.jsondiscover CUDA 进程发现
2.0validate.schema.json单边 validate 校验结果
2.0measurement-spec.schema.json单边 measure --spec 输入
2.0event.schema.jsonEvent JSONL 单行事件
2.0error.schema.json统一错误响应
2.0cpu-sampling-spec.schema.json--cpu-sample 输入 spec
2.0cpu-sampling-validate.schema.json--cpu-sample 校验结果
2.0cpu-sample-inventory-result.schema.json--cpu-sample 热点清单
2.0syscall-aggregate-spec.schema.json--syscall-aggregate 输入 spec
2.0syscall-aggregate-validate.schema.json--syscall-aggregate 校验结果
2.0syscall-aggregate-result.schema.json--syscall-aggregate 聚合清单
2.0host-capture.schema.json主机采集离线输入格式
2.0inspect.schema.json目标进程元数据检查
2.0resolve.schema.json探针符号解析结果
2.0trace-export.schema.jsonTrace 导出元数据
1.0capture-manifest.schema.jsonEvent JSONL 伴生采集清单