qnx-kev-mcp-inspector
# QNX 8.0 Kernel Trace & IPC Inspector (`qnx-kev-mcp-inspector`)
[](LICENSE)
[](https://qnx.software/)
[](src/mcp-server.mjs)
[](package.json)
**Deterministic host-side kernel trace (`.kev` / `traceprinter`) analyzer, interactive multi-CPU oscillograph studio, and Model Context Protocol (MCP) server for QNX Neutrino RTOS / SDP 8.0.**
- **Live Interactive Visual Studio:** [https://z121245017-ai.github.io/qnx-kev-mcp-inspector/](https://z121245017-ai.github.io/qnx-kev-mcp-inspector/)
- **60-Second Full HD (1080p) Demo Video:** [https://z121245017-ai.github.io/qnx-kev-mcp-inspector/demo.mp4](https://z121245017-ai.github.io/qnx-kev-mcp-inspector/demo.mp4)
- **15-Minute Hands-On QNX 8.0 Codelab:** [`docs/CODELAB.md`](docs/CODELAB.md)
---
## Why We Built This
Debugging real-time concurrency bugs on QNX SDP 8.0 (`STATE_REPLY` callback deadlocks, `_NTO_CHF_FIXED_PRIORITY` priority inversions, and Adaptive Partitioning Scheduler `APS` jitter) traditionally requires manually sifting through tens of thousands of `traceprinter` lines or loading heavy desktop GUI profilers that AI coding agents cannot read.
`qnx-kev-mcp-inspector` bridges **QNX SDP 8.0 kernel instrumentation (`tracelogger` / `traceprinter`)**, **deterministic graph & real-time scheduling math**, and **modern AI developer workflows (Claude Code, Cursor, VS Code Copilot)** with **zero external runtime dependencies**:
```mermaid
flowchart LR
Target["QNX SDP 8.0 Target\ntracelogger -> .kev / traceprinter"] --> Parser["Multi-Format Parser\n(.trace | qnx-trace-v1 | QNXKEV80)"]
Parser --> A1["1. IPC & Mutex Deadlock\nTarjan SCC + Johnson Cycles"]
Parser --> A2["2. Priority Inversion\n_NTO_CHF_FIXED_PRIORITY Math"]
Parser --> A3["3. Hard-RT WCET & IST\np50/p95/p99 + APS + Pulses"]
A1 & A2 & A3 --> A4["4. SDP 8.0 C Patch Advisor\nSIGEV_PULSE / ChannelCreate / APS"]
A4 --> Studio["Self-Contained Web Studio\ndocs/index.html"]
A4 --> MCP["MCP Server (stdio & HTTP/SSE)\nsrc/mcp-server.mjs"]
```
---
## Core Capabilities
### 1. Three Native Input Formats + Lossless Binary `.kev` Round-Trip
- **Authentic QNX `traceprinter` Logs:** Parses `TRACE_CYCLES_PER_SEC`, `PROCCREATE_NAME`, `THCREATE`, `THRUNNING`/`THREADY`/`THSEND`/`THRECEIVE`/`THREPLY`/`THMUTEX`/`THNANOSLEEP`/`THINTR`, `MSG_SENDV/11`, `MSG_RECEIVEV/14`, `MSG_REPLYV/15`, `MSG_SEND_PULSE/17`, `CHANNEL_CREATE/35`, `CONNECT_ATTACH/37`, `INT_ENTR`, and `APS_PARTITION`.
- **Structured `qnx-trace-v1` JSON / NDJSON Streams:** Clean programmatic trace exchange for CI regression gates.
- **Binary `QNXKEV80` `.kev` Codec (`src/kev-codec.mjs`):** Packed 32-byte binary event frames with symbol table and CRC32 integrity verification—works identically in Node.js and the browser (`Uint8Array` / `DataView`).
### 2. Four Deterministic QNX 8.0 Diagnostic Analyzers
1. **Synchronous IPC & Mutex Deadlock Detector (`src/analyzers/deadlock.mjs`):** Reconstructs live `(pid, tid) -> chid -> (server_pid, server_tid)` edges across `STATE_SEND`, `STATE_REPLY`, and `STATE_MUTEX`, running Tarjan SCC + Johnson minimal elementary cycle extraction to pinpoint multi-process `MsgSend()` callback rings.
2. **Unbounded Priority Inversion Detector (`src/analyzers/priority-inversion.mjs`):**Integrates exact microsecond slices where a high-priority `SCHED_FIFO` thread (`prio >= 50`) blocks in `STATE_REPLY` or `STATE_MUTEX` while a medium-priority thread preempts an unboosted server (`_NTO_CHF_FIXED_PRIORITY` on `ChannelCreate()` or missing `PTHREAD_PRIO_INHERIT`).
3. **Hard Real-Time WCET & IST Latency Auditor (`src/analyzers/wcet-latency.mjs`):** Computes `p50` / `p95` / `p99` / `max` `READY -> RUNNING` dispatch latency, `InterruptAttachEvent` (`IRQ_ENTER -> THRUNNING`) response latency, handler WCET overruns, `APS` partition budget exhaustion, and QNX pulse queue saturation (`SND_PULSE_DIS` / `EAGAIN`).
4. **Idiomatic QNX SDP 8.0 C Patch Advisor (`src/analyzers/remediation.mjs`):** Synthesizes ready-to-apply C diffs using `SIGEV_PULSE_INIT`, `MsgRegisterEvent`, `MsgDeliverEvent`, `ChannelCreate(_NTO_CHF_DISCONNECT | _NTO_CHF_UNBLOCK)`, and `SchedCtl(SCHED_APS_MODIFY_PARTITION, ...)`.
### 3. Interactive Single-Page Oscillograph Studio (`docs/index.html`)
- **Zero CDN / Zero External Requests:** Runs offline from `file://` or GitHub Pages.
- **Multi-CPU & Per-Thread Timeline Swimlanes + State Flamebars** with `1x–8x` zoom, cycle/microsecond crosshair ruler, and anomaly overlays.
- **Interactive SVG Wait-For & Channel Topology Graph** highlighting minimal deadlock cycles in red.
- **1-Click Fixture Loader** + drag-and-drop `.trace` / `.json` / `.kev` upload + in-browser `.kev` binary export & CRC32 round-trip verifier.
---
## Quick Start
```bash
git clone https://github.com/z121245017-ai/qnx-kev-mcp-inspector.git
cd qnx-kev-mcp-inspector
# Run the full test suite (Node.js >= 20 built-in test runner, 0 npm install needed)
npm test
# Inspect all 4 realistic QNX 8.0 embedded trace fixtures
node bin/qnx-inspector.mjs analyze adas_ipc_deadlock
node bin/qnx-inspector.mjs analyze ventilator_prio_inversion
node bin/qnx-inspector.mjs analyze industrial_ethercat_jitter
node bin/qnx-inspector.mjs analyze healthy_baseline
# Encode a traceprinter log into a binary .kev capture and decode back
node bin/qnx-inspector.mjs kev-encode fixtures/adas_ipc_deadlock.trace -o /tmp/adas.kev
node bin/qnx-inspector.mjs kev-decode /tmp/adas.kev --to traceprinter | head -n 20
```
---
## Included QNX 8.0 Embedded Trace Fixtures (`fixtures/`)
| Fixture | Domain Scenario | Deterministic Finding |
| :--- | :--- | :--- |
| `adas_ipc_deadlock.trace` (`.kev`) | 3-process ADAS emergency braking (`SensorFusion -> PathPlanner -> BrakeActuator`) | **`CRITICAL`**: 3-node `STATE_REPLY` / `STATE_SEND` cycle @ `2,450 us` (locked `5,550 us`) |
| `ventilator_prio_inversion.trace` | ICU ventilator `prio 63` airway PID loop + `prio 18` SPI sensor resmgr + `prio 35` HL7 telemetry | **`CRITICAL`**: `14,200 us` (`14.20 ms`) unbounded starvation caused by `_NTO_CHF_FIXED_PRIORITY` (`0x0001`) |
| `industrial_ethercat_jitter.trace` | `1 ms` cyclic EtherCAT DC IST (`irq:42`, `200 us` deadline) under OPC-UA burst & APS contention | **`CRITICAL`**: `p99 = 385 us` dispatch breach + `134 us` WCET overrun + `Fieldbus_RT` APS exhaustion + `SND_PULSE_DIS` |
| `healthy_baseline.trace` | Remediated dual-core QNX 8.0 reference capture | **`HEALTHY`**: `0` cycles, dynamic PI boost `prio 18 -> 63` verified, `100%` deadlines met (`p99 = 19 us`) |
---
## Model Context Protocol (MCP) Server Setup
`src/mcp-server.mjs` implements JSON-RPC 2.0 over `stdio` (both newline-delimited and `Content-Length` framed) plus optional HTTP/SSE (`--http 3848`).
### Claude Code / Cursor / VS Code (`.mcp.json`)
```json
{
"mcpServers": {
"qnx-kev-inspector": {
"command": "node",
"args": ["/path/to/qnx-kev-mcp-inspector/src/mcp-server.mjs"]
}
}
}
```
### Docker (Zero-Network Alpine Image / Glama Ready)
```json
{
"mcpServers": {
"qnx-kev-inspector": {
"command": "docker",
"args": ["run", "-i", "--rm", "qnx-kev-mcp-inspector"]
}
}
}
```
### Exposed MCP Tools, Prompts & Resources
- **Tools** (`readOnlyHint: true`, strict JSON Schemas):
- `inspect_qnx_trace` — Complete diagnostic report, flame breakdown, and QNX SDP 8.0 C patches.
- `detect_ipc_deadlocks` — Minimal Tarjan/Johnson Wait-For cycles and `MsgDeliverEvent` pulse patches.
- `audit_priority_inversions` — Microsecond preemption windows and `_NTO_CHF_FIXED_PRIORITY` / mutex PI audit.
- `audit_wcet_deadlines` — Per-thread/IST `p50`/`p95`/`p99`/`max` dispatch latency, WCET budget, APS, and pulse queue audit.
- **Prompts**: `diagnose-qnx-deadlock-and-inversion`, `audit-qnx-hard-rt-wcet`
- **Resources**: `qnx://reference/neutrino-constants` plus all 4 embedded QNX 8.0 trace fixtures (`qnx://fixtures/{fixtureName}`).
---
## Repository Structure
```text
qnx-kev-mcp-inspector/
├── bin/
│ └── qnx-inspector.mjs # CLI analyzer, .kev encoder/decoder, MCP launcher
├── docs/
│ ├── index.html # 100% self-contained single-page Visual Studio (0 CDN deps)
│ ├── demo.mp4 # 60s 1080p Full HD narrated walkthrough (-15.1 LUFS)
│ └── CODELAB.md # 15-minute QNX SDP 8.0 hands-on tutorial
├── fixtures/ # 4 realistic QNX 8.0 .trace captures + binary .kev fixture
├── scripts/
│ ├── generate-fixtures.mjs # Deterministic nanosecond/cycle fixture builder
│ ├── build-studio.mjs # Bundles src/ + fixtures/ into docs/index.html
│ └── render-demo-video.mjs # Headless Chrome CDP + FFmpeg 60s 1080p video renderer
├── src/
│ ├── qnx-constants.mjs # <sys/states.h>, <sys/neutrino.h>, <sys/trace.h> constants
│ ├── kev-codec.mjs # Lossless QNXKEV80 binary encoder/decoder + CRC32
│ ├── parser.mjs # Multi-format parser (traceprinter, JSON, binary .kev)
│ ├── index.mjs # Unified inspectTrace() + swimlane/flamebar builder
│ ├── mcp-server.mjs # Standard MCP Server (stdio + HTTP/SSE)
│ └── analyzers/
│ ├── deadlock.mjs # Tarjan SCC + Johnson minimal IPC/mutex cycle detector
│ ├── priority-inversion.mjs # Unbounded priority inversion & channel flag auditor
│ ├── wcet-latency.mjs # Hard-RT WCET, IST latency, APS & pulse queue auditor
│ └── remediation.mjs # Idiomatic QNX SDP 8.0 C unified diff generator
└── tests/
└── qnx-inspector.test.mjs # >= 28 end-to-end deterministic & MCP protocol tests
```
---
## License
Released under the [MIT License](LICENSE).
TDQS
Scored across 4 tools
Three tools cleanly map to distinct analysis domains (deadlock, priority inversion, WCET), and inspect_qnx_trace is explicitly documented as running all analyzers plus remediation. The only overlap is that the aggregate is a superset of the other three, so an agent must decide between run-all versus drill-down, but descriptions make that choice clear.
All names are snake_case verb_noun constructions, which is consistent and predictable. The verbs vary (inspect/detect/audit) rather than following one canonical verb, but each choice reads naturally for its action.
Four tools is a tight, focused surface for a trace-inspection server, and the aggregate-plus-three-analyzers structure is well scoped. It sits at the thin end of the ideal range, with the aggregate arguably duplicating the other three.
The core analysis domain (deadlocks, priority inversion, WCET, remediation) is covered, but there are notable gaps: no standalone remediation/patch tool despite patches being advertised, and no trace discovery/validation, report export, or trace comparison operations. Agents hitting a non-parseable or unsupported trace format have no fallback path.