Systems Capstone: Telemetry Pipeline
Guided Challenges and Capstone

10.4 Systems Capstone: Telemetry Pipeline

Challenges 10.1 to 10.3 isolated ownership, allocation, and threading. This capstone assembles them into a small application: read a binary telemetry stream, validate records, aggregate statistics, and emit a deterministic text summary. Treat it as a portfolio piece that demonstrates systems habits, not a single-file homework snippet.

1. Single-threaded parser with std::span<const std::byte> and std::expected (Lessons 3.6, 6.7, 8.5). Lock correctness with unit tests before any threads exist.

2. Aggregation logic as pure functions over parsed records, easy to test without I/O.

3. Bounded queue from 10.3 (or your own) with an explicit shutdown signal so workers exit cleanly.

4. CMake targets separating library, executable, and tests (Lessons 0.4, 8.1, 8.8).

5. Sanitizers and one benchmark (Lessons 0.4, 8.9) only after correctness is proven.

Architecture sketch

* Input: file or stdin → read into a byte buffer or memory-mapped region.

* Parser: parseRecord(span)expected<Record, ParseError>; never read past span.size().

* Workers (optional phase): producer threads parse chunks; consumers aggregate into thread-safe accumulators or per-thread locals merged at the end.

* Output: deterministic summary (count, min, max, mean) written to stdout or a report file.

Requirements

1. Interface design: parsing through std::span<const std::byte> with std::expected<Record, ParseError> (C++23).

2. Ownership: no raw owning pointers; values, containers, and RAII throughout.

3. Concurrency: bounded queue plus shutdown that wakes blocked threads.

4. Build: library target, executable, and test targets in CMake.

5. Quality gate: unit tests; ASan/UBSan builds; TSan on the queue where supported.

Suggested repository shape

telemetry/
  CMakeLists.txt
  include/telemetry/parser.h
  include/telemetry/queue.h
  src/parser.cpp
  src/aggregator.cpp
  src/main.cpp
  tests/parser_tests.cpp
  tests/queue_tests.cpp
  benchmarks/aggregate_benchmark.cpp
Keep application code, tests, and benchmarks separate.

Acceptance checklist

- Malformed input returns a descriptive error without reading past the span.

- A fixed fixture yields exact count, min, max, and average.

- Queue shutdown wakes blocked producers and consumers.

- ctest --test-dir build passes.

- A benchmark documents compiler flags, hardware, hypothesis, result, and limitations.

Measurement discipline

Name one hypothesis before benchmarking, for example, batching 64 records per queue push reduces mutex traffic. Compare against a baseline on the same machine and build flags. Lesson 0.4 lists sanitizer versus perf roles; do not conflate them.

Stretch goals: little- and big-endian fixtures (Lesson 3.6), std::jthread stop-token shutdown test, std::pmr arena only if benchmarks justify the complexity.

Chapter 10 Knowledge CheckQuestion 1 of 3

Why must a custom UniquePtr delete its copy constructor and copy assignment operator?

Finished reading this lesson?