Repository navigation
feat(local): show live CPU, RAM and GPU usage above Studio - #2092
Merged
Merged
Conversation
A Resources panel at the top of the right column shows the machine's CPU, RAM, VRAM and GPU load, each split into SurfSense's share and other apps, with a per-engine breakdown for llama.cpp, stable-diffusion.cpp, audio.cpp, the backend and the interface. The API samples it at GET /system/usage. Electron passes its pid as SURFSENSE_LOCAL_SHELL_PID, and every process under it counts as the app, named by the child of the shell that started its branch. Graphics come from the OS: GPU performance counters and DXGI on Windows, NVML and amdgpu sysfs with DRM fdinfo on Linux, ioreg on macOS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: MODSetter/SurfSense/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (62)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A Resources panel at the top of the desktop app's right column, above Studio, showing live:
chart-1), other apps and free. The machine figure turns amber at 90% or more for RAM and VRAM.How it works:
GET /system/usage(modules/resource_usage/). Electron passes its own pid asSURFSENSE_LOCAL_SHELL_PID. Every process under it counts as the app, labelled by the child of the shell that started its branch, so llama-server's per-model workers count as llama.cpp.ioreg, read as unified memory, so there is no VRAM row.features/resources/polls every 2 s, only while the right panel is open and the window is visible. A response it can't read shows "Usage unavailable" instead of breaking the dashboard.docs/architecture/resource-usage.md, overview updated. 25 strings in all 10 catalogs.Why
llama.cpp, stable-diffusion.cpp and audio.cpp all compete for the same RAM and VRAM. When generation slows or a model spills, users can't tell whether SurfSense or something else is holding the memory. This panel shows it at a glance.
Fixes # (no issue)
Process note: CONTRIBUTING asks for a proposal PR before a new feature. This one went straight to code with its architecture doc, so accepting it means accepting the design here.
How to test
Automated:
Manual (
cd surfsense_local/electron && pnpm dev):/system/usagestop.Verified on Windows 11 with an RTX 3080, against a running dev app. llama-server held 5.5 GB of the 7.2 GB in use, and the interface 0.05 GB. A sample takes about 40 ms, most of it psutil's process snapshot.
Known gaps, also in the doc:
electron/src/main/secret.test.tsfails on Windows before and after this change: it checks a POSIX file mode.🤖 Generated with Claude Code
High-level PR Summary
This PR adds a live resource usage panel to the desktop app, showing CPU, RAM, VRAM and GPU utilization for both the machine and SurfSense's share. The panel sits above Studio and displays a per-engine breakdown (llama.cpp, stable-diffusion.cpp, audio.cpp, backend, interface) to help users identify which runtime is holding memory when generation slows. The feature uses platform-specific readers: DXGI and GPU performance counters on Windows, NVML and amdgpu sysfs on Linux, and
ioregon macOS.⏱️ Estimated Review Time: 30-90 minutes
💡 Review Order Suggestion
docs/architecture/resource-usage.mddocs/architecture/overview.mdsurfsense_local/backend/api/config.pysurfsense_local/electron/src/main/sidecars/python.tssurfsense_local/electron/src/main/sidecars/python.test.tssurfsense_local/backend/modules/resource_usage/engines.pysurfsense_local/backend/modules/resource_usage/parent_map.pysurfsense_local/backend/modules/resource_usage/app_tree.pysurfsense_local/backend/modules/resource_usage/gpu/carve_out.pysurfsense_local/backend/modules/resource_usage/gpu/reading.pysurfsense_local/backend/modules/resource_usage/gpu/__init__.pysurfsense_local/backend/modules/resource_usage/gpu/windows/adapters.pysurfsense_local/backend/modules/resource_usage/gpu/windows/pdh.pysurfsense_local/backend/modules/resource_usage/gpu/windows/counters.pysurfsense_local/backend/modules/resource_usage/gpu/windows/reader.pysurfsense_local/backend/modules/resource_usage/gpu/linux/nvml.pysurfsense_local/backend/modules/resource_usage/gpu/linux/amdgpu.pysurfsense_local/backend/modules/resource_usage/gpu/linux/reader.pysurfsense_local/backend/modules/resource_usage/gpu/darwin/ioreg.pysurfsense_local/backend/modules/resource_usage/gpu/darwin/reader.pysurfsense_local/backend/modules/resource_usage/snapshot.pysurfsense_local/backend/modules/resource_usage/sampler.pysurfsense_local/backend/modules/resource_usage/dependencies.pysurfsense_local/backend/modules/resource_usage/schemas.pysurfsense_local/backend/modules/resource_usage/router.pysurfsense_local/backend/api/main.pysurfsense_local/frontend/src/features/resources/api.tssurfsense_local/frontend/src/features/resources/breakdown-pref.tssurfsense_local/frontend/src/features/resources/format-usage.tssurfsense_local/frontend/src/features/resources/usage-rows.tssurfsense_local/frontend/src/features/resources/usage-meter.tsxsurfsense_local/frontend/src/features/resources/engine-breakdown.tsxsurfsense_local/frontend/src/features/resources/use-resource-usage.tssurfsense_local/frontend/src/features/resources/resource-usage-panel.tsxsurfsense_local/frontend/src/features/resources/live-resource-usage.tsxsurfsense_local/frontend/src/features/dashboard/right-panel.tsxsurfsense_local/frontend/src/features/dashboard/dashboard-page.tsxsurfsense_local/backend/tests/unit/resource_usage/test_app_tree.pysurfsense_local/backend/tests/unit/resource_usage/test_parent_map.pysurfsense_local/backend/tests/unit/resource_usage/test_snapshot.pysurfsense_local/backend/tests/unit/resource_usage/test_darwin_ioreg.pysurfsense_local/backend/tests/unit/resource_usage/test_linux_amdgpu.pysurfsense_local/backend/tests/unit/resource_usage/test_windows_counters.pysurfsense_local/backend/tests/integration/resource_usage/test_routes.pysurfsense_local/frontend/src/features/resources/live-resource-usage.test.tsxsurfsense_local/frontend/src/features/resources/resource-usage-panel.test.tsxsurfsense_local/frontend/translations/de.jsonsurfsense_local/frontend/translations/en.jsonsurfsense_local/frontend/translations/es.jsonsurfsense_local/frontend/translations/fr.jsonsurfsense_local/frontend/translations/hi.jsonsurfsense_local/frontend/translations/ja.jsonsurfsense_local/frontend/translations/ko.jsonsurfsense_local/frontend/translations/pt-BR.jsonsurfsense_local/frontend/translations/ru.jsonsurfsense_local/frontend/translations/zh-CN.json