# hans-kramer/qcstats architecture

> Architecture diagram of the GitHub repository hans-kramer/qcstats, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hans-kramer/qcstats
- Repository: https://github.com/hans-kramer/qcstats

## Overview

qcstats is a board-specific telemetry sampler for the Arduino Ventuno Q. Its principal workflow parses sampling and output options, opens independent samplers, collects readings into a shared sample, and emits plain, NDJSON, or CSV output on a timed loop. Telemetry spans CPU, memory, GPU, thermal, power, fan, throttling, and optional NPU and GPU-busy metrics; run-level kernel and image provenance is also reported. The excerpts show the shared sampler and platform-I/O layers. Several sensor implementations were not excerpted, so their dispatch links rely on the documented sampler interface and main’s sampler list.

Main entry points: [`src/main.c`](https://github.com/hans-kramer/qcstats/blob/main/src/main.c) (CLI and loop), [`src/io.c`](https://github.com/hans-kramer/qcstats/blob/main/src/io.c) (Platform I/O), [`src/qcstats.h`](https://github.com/hans-kramer/qcstats/blob/main/src/qcstats.h) (Sample model), [`src/emit.c`](https://github.com/hans-kramer/qcstats/blob/main/src/emit.c) (Output formats)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Sampling runtime"]
  node_main["CLI and loop<br/>[main.c]"]
end

subgraph group_telemetry["Telemetry sources"]
  node_cpu["CPU metrics<br/>[cpu.c]"]
  node_memory["Memory metrics<br/>[mem.c]"]
  node_gpu["GPU frequency<br/>[gpu.c]"]
  node_thermal["Thermal zones<br/>[thermal.c]"]
  node_power["Power metrics<br/>[power.c]"]
  node_fan["Fan metrics<br/>[fan.c]"]
  node_throttle["Throttle events<br/>[throttle.c]"]
  node_npu["NPU metrics<br/>[npu.c]"]
  node_gpu_busy["GPU busy trace<br/>[gputrace.c]"]
end

subgraph group_platform["Platform access"]
  node_io["Platform I/O<br/>[io.c]"]
  node_envid["Run provenance<br/>[envid.c]"]
end

subgraph group_reporting["Sample and output"]
  node_sample["Sample model<br/>[qcstats.h]"]
  node_emit["Output formats<br/>[emit.c]"]
end

node_operator(("Operator"))
node_proc_sysfs[("Linux procfs/sysfs")]
node_tracefs[("Linux tracefs")]
node_fastrpc["FastRPC service"]
node_consumer(("Output consumer"))

node_operator -->|"sets options"| node_main
node_main -->|"dispatches sampler"| node_cpu
node_main -->|"dispatches sampler"| node_memory
node_main -->|"dispatches sampler"| node_gpu
node_main -->|"dispatches sampler"| node_thermal
node_main -->|"dispatches sampler"| node_power
node_main -->|"dispatches sampler"| node_fan
node_main -->|"dispatches sampler"| node_throttle
node_main -->|"dispatches sampler"| node_npu
node_main -->|"dispatches sampler"| node_gpu_busy
node_cpu -->|"reads sources"| node_io
node_memory -->|"reads sources"| node_io
node_gpu -->|"reads sources"| node_io
node_thermal -->|"resolves and reads"| node_io
node_power -->|"reads sources"| node_io
node_fan -->|"reads sources"| node_io
node_throttle -->|"reads sources"| node_io
node_io -->|"reads"| node_proc_sysfs
node_npu -.->|"queries optionally"| node_fastrpc
node_gpu_busy -->|"enables and reads"| node_tracefs
node_main -->|"reads once"| node_envid
node_envid -->|"reads files"| node_io
node_main -.->|"collects readings"| node_sample
node_cpu -->|"fills metrics"| node_sample
node_thermal -->|"fills metrics"| node_sample
node_npu -.->|"fills metrics"| node_sample
node_gpu_busy -->|"fills metrics"| node_sample
node_main -.->|"emits selected format"| node_emit
node_sample -->|"formats sample"| node_emit
node_envid -->|"adds provenance"| node_emit
node_emit -->|"writes output"| node_consumer

click node_main "https://github.com/hans-kramer/qcstats/blob/main/src/main.c"
click node_cpu "https://github.com/hans-kramer/qcstats/blob/main/src/cpu.c"
click node_memory "https://github.com/hans-kramer/qcstats/blob/main/src/mem.c"
click node_gpu "https://github.com/hans-kramer/qcstats/blob/main/src/gpu.c"
click node_thermal "https://github.com/hans-kramer/qcstats/blob/main/src/thermal.c"
click node_power "https://github.com/hans-kramer/qcstats/blob/main/src/power.c"
click node_fan "https://github.com/hans-kramer/qcstats/blob/main/src/fan.c"
click node_throttle "https://github.com/hans-kramer/qcstats/blob/main/src/throttle.c"
click node_npu "https://github.com/hans-kramer/qcstats/blob/main/src/npu.c"
click node_gpu_busy "https://github.com/hans-kramer/qcstats/blob/main/src/gputrace.c"
click node_io "https://github.com/hans-kramer/qcstats/blob/main/src/io.c"
click node_envid "https://github.com/hans-kramer/qcstats/blob/main/src/envid.c"
click node_sample "https://github.com/hans-kramer/qcstats/blob/main/src/qcstats.h"
click node_emit "https://github.com/hans-kramer/qcstats/blob/main/src/emit.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main toneBlue
class node_cpu,node_memory,node_gpu,node_thermal,node_power,node_fan,node_throttle,node_npu,node_gpu_busy,node_proc_sysfs,node_tracefs toneAmber
class node_io,node_envid toneMint
class node_sample,node_emit toneRose
class node_operator,node_fastrpc,node_consumer toneIndigo
```

## Components

### Sampling runtime

- [CLI and loop](https://github.com/hans-kramer/qcstats/blob/main/src/main.c): `src/main.c`

### Telemetry sources

- [CPU metrics](https://github.com/hans-kramer/qcstats/blob/main/src/cpu.c): `src/cpu.c`
- [Memory metrics](https://github.com/hans-kramer/qcstats/blob/main/src/mem.c): `src/mem.c`
- [GPU frequency](https://github.com/hans-kramer/qcstats/blob/main/src/gpu.c): `src/gpu.c`
- [Thermal zones](https://github.com/hans-kramer/qcstats/blob/main/src/thermal.c): `src/thermal.c`
- [Power metrics](https://github.com/hans-kramer/qcstats/blob/main/src/power.c): `src/power.c`
- [Fan metrics](https://github.com/hans-kramer/qcstats/blob/main/src/fan.c): `src/fan.c`
- [Throttle events](https://github.com/hans-kramer/qcstats/blob/main/src/throttle.c): `src/throttle.c`
- [NPU metrics](https://github.com/hans-kramer/qcstats/blob/main/src/npu.c): `src/npu.c`
- [GPU busy trace](https://github.com/hans-kramer/qcstats/blob/main/src/gputrace.c): `src/gputrace.c`

### Platform access

- [Platform I/O](https://github.com/hans-kramer/qcstats/blob/main/src/io.c): `src/io.c`
- [Run provenance](https://github.com/hans-kramer/qcstats/blob/main/src/envid.c): `src/envid.c`

### Sample and output

- [Sample model](https://github.com/hans-kramer/qcstats/blob/main/src/qcstats.h): `src/qcstats.h`
- [Output formats](https://github.com/hans-kramer/qcstats/blob/main/src/emit.c): `src/emit.c`

### Other components

- **Operator**
- **Linux procfs/sysfs**
- **Linux tracefs**
- **FastRPC service**
- **Output consumer**

## Connections

- Operator → CLI and loop: sets options (evidence: `README.md`)
- CLI and loop → CPU metrics: dispatches sampler (evidence: `src/main.c`)
- CLI and loop → Memory metrics: dispatches sampler (evidence: `src/main.c`)
- CLI and loop → GPU frequency: dispatches sampler (evidence: `src/main.c`)
- CLI and loop → Thermal zones: dispatches sampler (evidence: `src/main.c`)
- CLI and loop → Power metrics: dispatches sampler (evidence: `src/main.c`)
- CLI and loop → Fan metrics: dispatches sampler (evidence: `src/main.c`)
- CLI and loop → Throttle events: dispatches sampler (evidence: `src/main.c`)
- CLI and loop → NPU metrics: dispatches sampler (evidence: `src/main.c`)
- CLI and loop → GPU busy trace: dispatches sampler (evidence: `src/main.c`)
- CPU metrics → Platform I/O: reads sources (evidence: `src/cpu.c`)
- Memory metrics → Platform I/O: reads sources (evidence: `src/mem.c`)
- GPU frequency → Platform I/O: reads sources (evidence: `src/gpu.c`)
- Thermal zones → Platform I/O: resolves and reads (evidence: `src/thermal.c`)
- Power metrics → Platform I/O: reads sources (evidence: `src/power.c`)
- Fan metrics → Platform I/O: reads sources (evidence: `src/fan.c`)
- Throttle events → Platform I/O: reads sources (evidence: `src/throttle.c`)
- Platform I/O → Linux procfs/sysfs: reads (evidence: `src/io.c`)
- NPU metrics → FastRPC service: queries optionally (evidence: `README.md`)
- GPU busy trace → Linux tracefs: enables and reads (evidence: `src/gputrace.c`)
- CLI and loop → Run provenance: reads once (evidence: `src/main.c`)
- Run provenance → Platform I/O: reads files (evidence: `src/envid.c`)
- CLI and loop → Sample model: collects readings (evidence: `src/main.c`)
- CPU metrics → Sample model: fills metrics (evidence: `src/cpu.c`)
- Thermal zones → Sample model: fills metrics (evidence: `src/thermal.c`)
- NPU metrics → Sample model: fills metrics
- GPU busy trace → Sample model: fills metrics (evidence: `src/gputrace.c`)
- CLI and loop → Output formats: emits selected format (evidence: `README.md`)
- Sample model → Output formats: formats sample (evidence: `src/emit.c`)
- Run provenance → Output formats: adds provenance
- Output formats → Output consumer: writes output (evidence: `src/emit.c`)
