Skip to content

fix(settings): real CPU/RAM numbers in the sidebar, plus GPU and VRAM - #10

Open
Ewerton wants to merge 3 commits into
KS0Code:mainfrom
Ewerton:fix/engine-resource-stats
Open

Ewerton wants to merge 3 commits into
KS0Code:mainfrom
Ewerton:fix/engine-resource-stats

Conversation

@Ewerton

@Ewerton Ewerton commented Nov 16, 2026

Copy link
Copy Markdown

Stacked on #2. This branch is built on fix/personalisation-stat-cards, so until #2 merges the diff also shows its two commits. The change in this PR is the last commit, 278eec7.

Problem

The CPU and RAM rows at the bottom of the sidebar stayed at 0% / 0.0 GB, even while the model was generating. There were two bugs in EngineProbe:

  • RAM was never read, for any process. sampleRam() looped on while (!f.atEnd()) over /proc/<pid>/status. procfs files report size 0, so QFile treats them as already at EOF and the loop body never ran.
  • It sampled the wrong process. The probe took the first process whose comm is ollama, which is ollama serve. That process uses about 40 MB and almost no CPU. Ollama loads the model in a child process, llama-server (or ollama runner on older versions), which was never counted. With a 4B model loaded, serve used 40 MB and llama-server used about 920 MB.

Fix

CPU/RAM (engine_probe.cpp):

  • /proc/<pid>/status is read with readAll(), as the CPU sampler already did.
  • The probe sums CPU and RSS over every ollama process and all of its descendants (engineProcessTree()).
  • CPU deltas are tracked per PID. When a model loads or unloads and the runner appears or exits, it gets a baseline instead of producing a spike.
  • CPU % is now a share of the whole machine. Before, it was % of one core clamped at 100, which a multi-threaded runner pins whenever it's busy on CPU.

GPU/VRAM, on machines with an NVIDIA GPU:

  • The sidebar gets GPU and VRAM rows, and the Model page gets VRAM and GPU stat tiles.
  • VRAM is the memory used by the engine's own processes (nvidia-smi --query-compute-apps), so other programs on the card aren't counted. The bar is scaled to that card's total.
  • GPU is the utilisation of the card holding the model, or 0% when the model isn't on a GPU. nvidia-smi only gives load per card, so other programs using the same card raise it too.
  • nvidia-smi runs asynchronously (QProcess::finished), so the UI never blocks on it. A hung call is killed after about 6 s.
  • The query is skipped while every NVIDIA GPU is runtime-suspended (/sys/bus/pci/devices/*/power/runtime_status), so hybrid laptops aren't woken up by the settings app.
  • With no NVIDIA PCI device or no nvidia-smi, Engine.gpuAvailable is false and the rows and tiles stay hidden.

Sidebar layout (XSidebar.qml): the four rows share one StatRow component with fixed caption and value widths, so the bars line up.

Testing

  • Unit tests: 7 new tests in tests/test_stats.cpp, all passing:
    • engineProcessTree: finds the runner under ollama, ignores an unrelated llama-server, and returns nothing when Ollama isn't running.
    • A regression test that the probe reads a non-zero RSS from procfs.
    • summarizeGpu: counts only the engine's VRAM and its card's load, reports 0% when the model is off the GPU, and tolerates [N/A] fields and empty output.
  • Live check on a GTX 1660 Ti (6 GB) with qwen3:4b-instruct-2507-q4_K_M fully offloaded, sampled every 1.5 s through one generation:
    cpu=0%  ram=0.92GB  gpu=0%   vram=3.05/6.00GB   ← model loaded, idle
    cpu=29% ram=0.99GB  gpu=58%  vram=3.05/6.00GB   ← generating
    cpu=16% ram=0.99GB  gpu=95%  vram=3.05/6.00GB
    cpu=0%  ram=0.99GB  gpu=0%   vram=3.05/6.00GB   ← done
    
    Before this change the same run showed 0% / 0.0 GB throughout. I also checked the sidebar in the running app (CPU 29%, RAM 1.0 GB while generating), before the GPU rows were added.
  • Not tested: a machine without an NVIDIA GPU, and a hybrid laptop with runtime D3 enabled.

🤖 Generated with Claude Code

Ewerton and others added 3 commits October 14, 2026 18:23
The three cards at the top of Personalisation never showed real data:

- "Accept rate · 7d" and "Time saved · 7d" were hard-coded "0%" / "0 s".
- "Words learned" shelled out to `xtype-corpus stats --json`, but nothing
  installs xtype-corpus and the script doesn't accept --json (argparse
  exits 2), so the count was always 0. It was also read only once at
  startup, and its bars were fixed placeholder values.

CorpusStats now counts the corpus itself (corpus.txt plus rotated
corpus.txt.N, skipping the engine's transient .tmp), follows the
configured corpus_path, and recounts every 3 s only when a file's size
or mtime changed. The 7 bars are real words-per-day for the last week,
taken from corpus_timestamps.txt (one timestamp per corpus line).

EngineProbe already polled metrics.json for latency; it now also
exposes suggestions generated/accepted and chars accepted (parsed with
QJsonDocument instead of a regex). Those counters live in the fcitx5
process and reset when it restarts, so the cards are relabelled
"· this session" and drop the per-day bars. Time saved is an estimate:
accepted characters at 40 WPM.

Adds Catch2 tests for the corpus counting and metrics parsing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Wipe button in the "Reset profile" dialog only called
Qt.openUrlExternally("xtype-corpus://wipe") — a no-op placeholder — then
showed a "Corpus wiped" toast. Nothing was deleted, and the dialog
promised a backup that was never made.

CorpusStats::wipe() now deletes corpus.txt, its rotated copies, the
timestamp file, the engine's pruning scratch files and
style_profile.json, then recounts. The toast reports failures, the
dialog text says what really happens, and the dialog sizes to its text.

The running engine keeps its in-memory style profile until its next
5-minute refresh, which the dialog now states.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The sidebar's CPU/RAM rows sat at 0% / 0.0 GB no matter what the model
was doing. Two bugs:

- RAM was read by looping on QFile::atEnd() over /proc/<pid>/status.
  procfs files report size 0, so QFile treats them as already at EOF
  and the loop never ran. RAM was never reported for any process.
  It now uses readAll(), as the CPU sampler already did.
- Only the first process named "ollama" was sampled, i.e. `ollama
  serve`, which is nearly idle. Ollama loads the model in a child
  process (`llama-server`, or `ollama runner` on older versions). The
  probe now sums CPU and RSS over every ollama process and all of
  their descendants. CPU deltas are tracked per PID, so the runner
  coming and going on model load/unload doesn't cause spikes, and the
  percentage is now a share of the whole machine instead of one core
  clamped at 100 (the runner is multi-threaded).

The sidebar also gets GPU and VRAM rows, and the Model page gets VRAM
and GPU stat tiles, on machines with an NVIDIA GPU:

- VRAM is the memory used by the engine's own processes (from
  `nvidia-smi --query-compute-apps`), with the bar scaled to that
  card's total. GPU is the utilisation of the card holding the model,
  or 0% when the model isn't on a GPU.
- nvidia-smi runs asynchronously so the UI never blocks on it, and a
  hung call is killed after a few ticks.
- The query is skipped while the NVIDIA GPU is runtime-suspended, so
  hybrid laptops aren't kept awake by the settings app.
- Without an NVIDIA device or nvidia-smi the rows stay hidden.

The four sidebar rows share one StatRow component with fixed caption
and value widths, so the bars line up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ewerton added a commit to Ewerton/XType that referenced this pull request Nov 16, 2026
Points readers at the upstream project, says which repo to clone for
this version, and lists the fixes and features with links to their
upstream pull requests (KS0Code#1-KS0Code#10).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant