Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cppreportcard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ jobs:
id: analysis_inputs
run: |
cmake -S . -B build/report -G Ninja \
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++-18 \
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DLINKERBOT_TRANSPORT_BUILD_TESTS=ON -DLINKERBOT_TRANSPORT_BUILD_EXAMPLES=ON \
-DLINKERBOT_TRANSPORT_BUILD_BENCHMARKS=ON
-DLINKERBOT_TRANSPORT_BUILD_BENCHMARKS=ON -DLINKERBOT_PERF_BUILD_STRESS=ON
cmake --build build/report --parallel 4
cmake --install build/report --prefix "$PWD/build/report-install"
cmake -S examples/quickstart -B build/report-quickstart -G Ninja \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
shell: bash
run: |
set -o pipefail
git ls-files -z -- '*.cpp' '*.hpp' '*.h' \
git ls-files -z -- '*.c' '*.cpp' '*.hpp' '*.h' \
| xargs -0 clang-format-18 --dry-run --Werror 2>&1 \
| tee clang-format.log
- name: Configure the static-analysis database
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,13 @@ Temporary Items
# add your custom gitignore here:
!.gitignore
!.gitsubmodules

# Local benchmark runs; retain the historical baseline and selected formal results.
/benchmarks/results/*
!/benchmarks/results/arm64-linux-2026-11-03/
!/benchmarks/results/stress-20261110-152431/
/benchmarks/results/stress-20261110-152431/*
!/benchmarks/results/stress-20261110-152431/README.md
!/benchmarks/results/stress-20261110-152431/stress-report.md
!/benchmarks/results/stress-20261110-152431/stress-raw-data.tar.gz
/benchmarks/**/__pycache__/
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,13 @@ install(FILES examples/quickstart/CMakeLists.txt examples/quickstart/main.cpp
DESTINATION ${CMAKE_INSTALL_DATADIR}/linkerbot-transport/examples/quickstart)
install(DIRECTORY docs/ DESTINATION ${CMAKE_INSTALL_DATADIR}/linkerbot-transport/docs
FILES_MATCHING PATTERN "*.md" PATTERN "*.csv" PATTERN "ci-performance-*.json")
install(FILES benchmarks/README.md benchmarks/summarize.py
install(FILES benchmarks/README.md
DESTINATION ${CMAKE_INSTALL_DATADIR}/linkerbot-transport/benchmarks)
install(DIRECTORY benchmarks/results/
install(FILES benchmarks/micro/README.md benchmarks/micro/summarize.py
DESTINATION ${CMAKE_INSTALL_DATADIR}/linkerbot-transport/benchmarks/micro)
install(FILES benchmarks/stress/README.md
DESTINATION ${CMAKE_INSTALL_DATADIR}/linkerbot-transport/benchmarks/stress)
install(DIRECTORY benchmarks/results/arm64-linux-2026-11-03
DESTINATION ${CMAKE_INSTALL_DATADIR}/linkerbot-transport/benchmarks/results
FILES_MATCHING PATTERN "*.md" PATTERN "*.csv")

Expand Down
9 changes: 8 additions & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ if(NOT TARGET linkerbot::can)
set(LINKERBOT_ALLOW_DEPENDENCY_DOWNLOADS OFF CACHE BOOL "" FORCE)
add_subdirectory(.. transport)
endif()
add_executable(linkerbot-perf main.cpp)
add_executable(linkerbot-perf micro/main.cpp)
target_link_libraries(linkerbot-perf PRIVATE linkerbot::can)
target_compile_features(linkerbot-perf PRIVATE cxx_std_17)
option(LINKERBOT_PERF_COUNT_ALLOCATIONS "Instrument benchmark C++ allocations" OFF)
target_compile_definitions(linkerbot-perf PRIVATE
LINKERBOT_PERF_COUNT_ALLOCATIONS=$<BOOL:${LINKERBOT_PERF_COUNT_ALLOCATIONS}>)

# Optional convenience target; the stress runner normally builds this separately
# in a fresh temporary directory against the selected local source tree.
option(LINKERBOT_PERF_BUILD_STRESS "Build end-to-end stress workers" OFF)
if(LINKERBOT_PERF_BUILD_STRESS)
add_subdirectory(stress)
endif()
89 changes: 23 additions & 66 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,34 @@
# Linux performance baselines
# 性能测试 / Benchmarks

Run these build commands from a complete source checkout. Installed packages
include the measurement notes, CSV results and summary script, but not the
benchmark build sources. Configure this standalone project in Release mode;
it needs no Catch2 or hardware:
本目录包含两类测试,均需完整源码仓库;软件测试结果不代表物理 CAN 带宽。

```sh
cmake -S benchmarks -B build/perf -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build/perf --parallel 4
./build/perf/linkerbot-perf --iterations 200000 --idle-ms 500 --repetitions 5
```
- [`micro/`](micro/README.md):内部操作基准,测订阅快照、订阅变更和 Session 空闲开销。`main.cpp` 输出 CSV,`summarize.py` 比较修改前后耗时、CPU 和分配次数。
- [`stress/`](stress/README.md):完整通信链路压测,扫描内存/vcan 的经典 CAN 与 CAN FD,逐帧校验,输出吞吐、P99、CPU、RSS、丢帧及性能对照报告。
- `results/`:结果集中存放。每次完整压测自动新建目录,避免覆盖;本机生成结果由 Git 忽略。已跟踪的基准记录和选定正式压测结果保留。

The default `LINKERBOT_PERF_COUNT_ALLOCATIONS=OFF` build is for timing and CPU
measurements. It does not override global allocation functions or update allocation
counters; its CSV rows have `allocation_tracking=0` and `NA` in both allocation
columns. Build a separate instrumented executable for allocation measurements:
已保存的 Ubuntu 正式结果:[Transport 0.3.4 压测报告(英文)](results/stress-20261110-152431/stress-report.md) · [原始数据包](results/stress-20261110-152431/stress-raw-data.tar.gz) · [英文归档校验说明](results/stress-20261110-152431/README.md)。测试于 2026-11-10 完成,共 119 档,四类吞吐均通过两次 60 秒确认。被测通信库提交为 `0e190032d65ed0b315337b45b3779cf4f650ed68`,运行发生在工具迁入仓库之前;报告和压缩包保留当时的版本、路径及计数,中文说明已翻译为英文。

```sh
cmake -S benchmarks -B build/perf-alloc -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DLINKERBOT_PERF_COUNT_ALLOCATIONS=ON
cmake --build build/perf-alloc --parallel 4
./build/perf-alloc/linkerbot-perf --iterations 200000 --idle-ms 500 --repetitions 5
```
从通信库根目录运行完整压测:

Instrumented rows have `allocation_tracking=1`. Use them for allocation counts,
not for the primary performance comparison: atomic counter updates add overhead
only to operations that allocate, and can exaggerate the benefit of removing
allocations. Compare before/after timing with instrumentation OFF, and compare
before/after allocation counts with it ON. Keep all remaining build and run
conditions the same within each comparison.
```bash
python3 benchmarks/stress/run.py --quick # 快速验证,非正式结果
python3 benchmarks/stress/run.py # 正式流程,约 40 分钟
```

Redirect stdout to a CSV file outside the source tree. Keep the source commit,
compiler/standard-library versions, flags, kernel, CPU architecture, affinity and
container CPU limits with each result. Run before and after binaries under the
same conditions, preferably in alternating order. Do not compare sanitizer builds.
默认结果为 `results/quick-YYYYMMDD-HHMMSS/` 或 `results/stress-YYYYMMDD-HHMMSS/`(相对于 benchmarks)。每个结果目录仅保留报告和原始数据压缩包;构建和展开采样均使用临时目录。允许用 `--output DIR` 指定其他位置。

`snapshot_copy` or `snapshot_view` measures one registry snapshot plus invocation of every subscriber;
`operations` is the number of snapshots, not callbacks. `checksum` must equal
`subjects * operations`. `mutation` measures a subscribe/unsubscribe pair while
holding the stated number of existing subscribers. These direct registry cases
isolate software overhead and do not measure CAN throughput or scheduler latency.
`mutation_snapshot` additionally acquires and releases a snapshot after each
subscribe and each unsubscribe, exposing cold snapshot-rebuild costs. Each
operation is still one subscribe/unsubscribe pair; its checksum must equal
`operations * (2 * subjects + 1)`. Plain `mutation` does not acquire snapshots.
The same source automatically selects `snapshot_view()` when the revision provides
it, otherwise `snapshot()`. The CSV scenario records the selected path; compare
these rows by subscriber count and repetition. The invocation loop and all other
instrumentation remain identical.
内部基准的现有构建方式保持不变:

Alternatively, the parent project may enable its optional benchmark target via
`-DLINKERBOT_TRANSPORT_BUILD_BENCHMARKS=ON`; the standalone project does not force the
parent project's test/example choices when the library target already exists.
```bash
cmake -S benchmarks -B build/perf -DCMAKE_BUILD_TYPE=Release
cmake --build build/perf --parallel 4
mkdir -p benchmarks/results/micro-example
./build/perf/linkerbot-perf --iterations 200000 --idle-ms 500 --repetitions 5 \
> benchmarks/results/micro-example/before-timing.csv
```

`idle_unrouted` creates 0/1/8/32 Sessions with no inbox; `idle_routed` also retains
one subscribed inbox per Session, without injecting any frames. Each Session
owns one passive transport. Its reader
uses a 10 ms condition-variable timeout. The zero-Session case measures the
baseline cost of the measuring process. A 200 ms warmup precedes each sample;
creation and shutdown are excluded. `transport_reads` separately identifies
reader activity, so it must not be mistaken for writer wakeups.
完整的两种分配计数模式与 before/after 比较流程见 [micro/README.md](micro/README.md)。需要同时构建完整压测程序时,可加 `-DLINKERBOT_PERF_BUILD_STRESS=ON`;通常由 `stress/run.py` 单独构建,保证每次使用新的 Release 产物。

All times are nanoseconds. `cpu_ns` and context switches come from process-wide
Linux counters and include every benchmark thread. Voluntary switches are a
proxy for scheduling activity, not an exact count of Session wakeups. Allocation
counts/bytes include successful C++ global new/new[] calls (including aligned
forms) during measurement; requested bytes do not include allocator metadata,
direct C malloc, kernel allocations or resident memory. Atomic instrumentation
itself adds overhead. The instrumented benchmark does not intercept deallocation
or measure peak live memory. Never compare an instrumented binary's time with an
uninstrumented binary's time.
安装包仅包含测量说明、micro 汇总脚本和已跟踪的 ARM64 基准记录,不包含测试构建源码、本机 stress/quick 结果或 `results/history/`。

Warmup, setup, output and cleanup are outside allocation measurement. CSV keeps
raw per-repetition results; report medians and dispersion rather than one fastest
sample. Preserve callback ordering, cancellation barriers, self-unsubscribe,
concurrent unsubscribe/clear, and cleanup/recovery behavior when optimizing.
历史结果整理至 `results/history/`,保留当时的版本、数值和命令。新结果不替代历史证据。原有压缩备份仍位于工作区的 `archives/`,不纳入通信库发布包。
78 changes: 78 additions & 0 deletions benchmarks/micro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Linux performance baselines

Run these build commands from a complete source checkout. Installed packages
include the measurement notes, recorded baseline CSVs and summary script, but not
the benchmark build sources. The source lives in `benchmarks/micro/`; run build
commands from the repository root. Configure this standalone project in Release mode;
it needs no Catch2 or hardware:

```sh
cmake -S benchmarks -B build/perf -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build/perf --parallel 4
./build/perf/linkerbot-perf --iterations 200000 --idle-ms 500 --repetitions 5
```

The default `LINKERBOT_PERF_COUNT_ALLOCATIONS=OFF` build is for timing and CPU
measurements. It does not override global allocation functions or update allocation
counters; its CSV rows have `allocation_tracking=0` and `NA` in both allocation
columns. Build a separate instrumented executable for allocation measurements:

```sh
cmake -S benchmarks -B build/perf-alloc -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DLINKERBOT_PERF_COUNT_ALLOCATIONS=ON
cmake --build build/perf-alloc --parallel 4
./build/perf-alloc/linkerbot-perf --iterations 200000 --idle-ms 500 --repetitions 5
```

Instrumented rows have `allocation_tracking=1`. Use them for allocation counts,
not for the primary performance comparison: atomic counter updates add overhead
only to operations that allocate, and can exaggerate the benefit of removing
allocations. Compare before/after timing with instrumentation OFF, and compare
before/after allocation counts with it ON. Keep all remaining build and run
conditions the same within each comparison.

Redirect stdout to a CSV file in a new ignored `benchmarks/results/micro-YYYYMMDD-HHMMSS/` directory. Keep the source commit,
compiler/standard-library versions, flags, kernel, CPU architecture, affinity and
container CPU limits with each result. Run before and after binaries under the
same conditions, preferably in alternating order. Do not compare sanitizer builds.

`snapshot_copy` or `snapshot_view` measures one registry snapshot plus invocation of every subscriber;
`operations` is the number of snapshots, not callbacks. `checksum` must equal
`subjects * operations`. `mutation` measures a subscribe/unsubscribe pair while
holding the stated number of existing subscribers. These direct registry cases
isolate software overhead and do not measure CAN throughput or scheduler latency.
`mutation_snapshot` additionally acquires and releases a snapshot after each
subscribe and each unsubscribe, exposing cold snapshot-rebuild costs. Each
operation is still one subscribe/unsubscribe pair; its checksum must equal
`operations * (2 * subjects + 1)`. Plain `mutation` does not acquire snapshots.
The same source automatically selects `snapshot_view()` when the revision provides
it, otherwise `snapshot()`. The CSV scenario records the selected path; compare
these rows by subscriber count and repetition. The invocation loop and all other
instrumentation remain identical.

Alternatively, the parent project may enable its optional benchmark target via
`-DLINKERBOT_TRANSPORT_BUILD_BENCHMARKS=ON`; the standalone project does not force the
parent project's test/example choices when the library target already exists.

`idle_unrouted` creates 0/1/8/32 Sessions with no inbox; `idle_routed` also retains
one subscribed inbox per Session, without injecting any frames. Each Session
owns one passive transport. Its reader
uses a 10 ms condition-variable timeout. The zero-Session case measures the
baseline cost of the measuring process. A 200 ms warmup precedes each sample;
creation and shutdown are excluded. `transport_reads` separately identifies
reader activity, so it must not be mistaken for writer wakeups.

All times are nanoseconds. `cpu_ns` and context switches come from process-wide
Linux counters and include every benchmark thread. Voluntary switches are a
proxy for scheduling activity, not an exact count of Session wakeups. Allocation
counts/bytes include successful C++ global new/new[] calls (including aligned
forms) during measurement; requested bytes do not include allocator metadata,
direct C malloc, kernel allocations or resident memory. Atomic instrumentation
itself adds overhead. The instrumented benchmark does not intercept deallocation
or measure peak live memory. Never compare an instrumented binary's time with an
uninstrumented binary's time.

Warmup, setup, output and cleanup are outside allocation measurement. CSV keeps
raw per-repetition results; report medians and dispersion rather than one fastest
sample. Preserve callback ordering, cancellation barriers, self-unsubscribe,
concurrent unsubscribe/clear, and cleanup/recovery behavior when optimizing.
File renamed without changes.
2 changes: 1 addition & 1 deletion benchmarks/summarize.py → benchmarks/micro/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"directory", nargs="?", type=Path,
default=Path(__file__).parent / "results" / "arm64-linux-2026-11-03",
default=Path(__file__).resolve().parents[1] / "results" / "arm64-linux-2026-11-03",
)
args = parser.parse_args()
try:
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/results/arm64-linux-2026-11-03/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ From the repository root, validate the CSV schema, modes and checksums and
summarize medians and ranges with:

```sh
python3 benchmarks/summarize.py benchmarks/results/arm64-linux-2026-11-03
python3 benchmarks/micro/summarize.py benchmarks/results/arm64-linux-2026-11-03
```

The uninstrumented median for snapshot acquisition plus invocation at 1, 8 and
Expand Down
22 changes: 22 additions & 0 deletions benchmarks/results/stress-20261110-152431/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Transport 0.3.4 Stress Test Results

- [Stress test report](stress-report.md)
- [Raw data archive](stress-raw-data.tar.gz)

The test ran on November 10, 2026 against commit `0e190032d65ed0b315337b45b3779cf4f650ed68`. It covered 119 configurations, including six failed overload configurations. All four scenarios completed two consecutive 60-second lossless confirmations.

This English edition retains the condensed test-information section. The report, diagnostic descriptions and archived Python tool snapshot have been translated. All numeric measurements, CSV samples, logs, environment metadata, compiler records, C/C++ sources and compiled artifacts are unchanged. The archive includes `localization.json` with the original hashes and translation scope, and a regenerated `manifest.json`.

## Verify the English Archive

Use the translated verifier bundled in the archive. The current repository verifier renders Chinese reports and is intended for its original-format output, not this English edition. From this directory, run:

```sh
archive_path="$PWD/stress-raw-data.tar.gz"
verify_dir=$(mktemp -d)
tar -xzf "$archive_path" -C "$verify_dir" tool-source/run.py
PYTHONDONTWRITEBYTECODE=1 python3 "$verify_dir/tool-source/run.py" --verify "$archive_path"
rm -r -- "$verify_dir"
```

The verifier checks every archive checksum, per-configuration JSON records, validity assessments, socket counters, RSS summaries, the linked-library checksum, confirmation records and report regeneration. Verification does not run the stress test or open a hardware channel. Expected summary: 119 records, four confirmed scenarios, unchanged source, and no run-level errors. The six failed overload configurations remain recorded separately.
Binary file not shown.
Loading
Loading