Repository navigation
fix(obs-util): CPU usage is at most all of the machine (#3367) - #3435
Merged
Merged
Conversation
os_cpu_usage_info_query() reports the process's share of the machine: process time over wall time over the core count, in percent. On Linux both times come from times(), in 10 ms ticks, so over a short interval the quotient is coarse: with one tick of wall time the busy threads can be charged one tick more than the cores could run, 5 ticks on 4 cores reads as 125 %. test_ws_cpu_usage (8 threads polling GetStats on one session under ASan) saw such values (#3367); C and the Rust port agree. obs_util::cpu_usage::percent() is the formula, and a Tier 1 test asks for at most 100 % from a coarse sample. The known-list entry of test_ws_cpu_usage goes. Fails: a_coarse_sample_is_at_most_all_of_the_machine (125.0, want 100.0). Co-Authored-By: Claude Opus 5.5 <[email protected]>
os_cpu_usage_info_query() caps its value at 100 on every platform: obs_util::cpu_usage::cap() in the Rust ports (nix through percent(), cocoa's cpu_percent(), Windows' cpu_query()), and the same `percent > 100.0 ? 100.0 : percent` in the C of platform-nix, platform-cocoa and platform-windows, so the ports and C stay equal; a NaN from an empty interval passes through as before. This differs from upstream OBS on purpose: the share of the machine cannot pass 100 %, a reading above it is only the counters' resolution. The cocoa characterization of a zero core count now reads 100 instead of infinity. obs-util cpu/platform tests: 52 passed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=0f4aa3c6bab0aa485bd50b3ee5da5423c29426b9 secs=269 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a Ci-Attestation: {"at":1793547776,"gate":"rust/all/fmt","host":"linux-x86_64","key":"683bae16d841f02c81d2ab0f69552bea99dedf9e365aa3c1a3960a3519c93fd9","lane":"lint","parents":["aa55c0461d4655d5b813a1e502192fc306a62592"],"secs":78,"stamp":"db7996236145e49bd4ce58677cd8539e","tree":"0f4aa3c6bab0aa485bd50b3ee5da5423c29426b9","v":1,"via":"run"} Ci-Attestation: {"at":1793547776,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"683bae16d841f02c81d2ab0f69552bea99dedf9e365aa3c1a3960a3519c93fd9","lane":"lint","parents":["aa55c0461d4655d5b813a1e502192fc306a62592"],"secs":78,"stamp":"204b342c6c702a7d5293423252a37a7c","tree":"0f4aa3c6bab0aa485bd50b3ee5da5423c29426b9","v":1,"via":"run"} Ci-Attestation: {"at":1793547776,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"53e955bd937e0505c8858af4f3dc45d61b87131a8a2a913dfbb5ada1378539aa","lane":"rust-test","parents":["aa55c0461d4655d5b813a1e502192fc306a62592"],"secs":85,"stamp":"2a8f1b6cbbe208c0a62d4de325e0d414","tree":"0f4aa3c6bab0aa485bd50b3ee5da5423c29426b9","v":1,"via":"run"} Ci-Attestation: {"at":1793547776,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"96091aef01e00685659c4f7d8b5729a7294d9452d81ab0b6b7c226469c7dce05","lane":"cross","parents":["aa55c0461d4655d5b813a1e502192fc306a62592"],"secs":56,"stamp":"a1a6b068b17b9511c886294ed87fd753","tree":"0f4aa3c6bab0aa485bd50b3ee5da5423c29426b9","v":1,"via":"run"} Ci-Attestation: {"at":1793547776,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"96091aef01e00685659c4f7d8b5729a7294d9452d81ab0b6b7c226469c7dce05","lane":"cross","parents":["aa55c0461d4655d5b813a1e502192fc306a62592"],"secs":56,"stamp":"3380a6591110793c757fd7ec828481e3","tree":"0f4aa3c6bab0aa485bd50b3ee5da5423c29426b9","v":1,"via":"run"} Ci-Attestation: {"at":1793547776,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"96091aef01e00685659c4f7d8b5729a7294d9452d81ab0b6b7c226469c7dce05","lane":"cross","parents":["aa55c0461d4655d5b813a1e502192fc306a62592"],"secs":56,"stamp":"7a086220cbcd9f2709c49d4f5b86bb39","tree":"0f4aa3c6bab0aa485bd50b3ee5da5423c29426b9","v":1,"via":"run"} Ci-Attestation: {"at":1793547776,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"96091aef01e00685659c4f7d8b5729a7294d9452d81ab0b6b7c226469c7dce05","lane":"cross","parents":["aa55c0461d4655d5b813a1e502192fc306a62592"],"secs":56,"stamp":"5dde757c9419ccc4286d5871eb2fcb9d","tree":"0f4aa3c6bab0aa485bd50b3ee5da5423c29426b9","v":1,"via":"run"} Ci-Attestation: {"at":1793547776,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"f7cf923a4e96d155c0017b46b245c1db28d6f3ca7d9579d52f0160fc9a0a4703","lane":"tier2-linux","parents":["aa55c0461d4655d5b813a1e502192fc306a62592"],"secs":268,"stamp":"915bbc0ae844d9304f6b8db31bc0e18b","tree":"0f4aa3c6bab0aa485bd50b3ee5da5423c29426b9","v":1,"via":"run"}
vpacher
enabled auto-merge
November 1, 2026 15:44
zackees
approved these changes
Nov 1, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Coordinator review: LGTM. Capping at 100 hides a tick-quantization artifact, not real data. The cap is applied the same way in the C reference and in every Rust platform port, so the differential tests stay equal, and a NaN still passes through unchanged in both. The features ledger line is there, which matters because this deliberately differs from upstream. obs-websocket clients see a cpuUsage that is now bounded, which is still within what the v5 protocol allows.
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.
Fixes #3367. Refs #3238, #1346.
Why
test_ws_cpu_usage(8 threads pollingGetStatson one session, under ASan) now and then got acpuUsageabove 100. The formula is not wrong:os_cpu_usage_info_query()reports the process's share of the machine, process time over wall time over the core count, in percent, the same in C and in the Rust port. But on Linux both times come fromtimes(), in 10 ms ticks. Since #1346 each session keeps its own sample, so 8 threads on one session query it every tick or two, and over one tick of wall time the busy threads can be charged one tick more than the cores could run: 5 ticks on 4 cores reads as 125 %. Upstream OBS does the same.What changes
os_cpu_usage_info_query()caps its value at 100 on every platform:obs_util::cpu_usage::cap()in the Rust ports (nix, cocoa, Windows) andpercent > 100.0 ? 100.0 : percentin the C ofplatform-nix,platform-cocoaandplatform-windows, so the ports and C stay equal. A NaN from an empty interval passes through as before.flakyentry oftest_ws_cpu_usageleaves the sanitizer known list.This is an intentional difference from upstream OBS: a share of the machine cannot pass 100 %, and a reading above it is only the counters' resolution. Below 100 nothing changes.
Commits
obs_util::cpu_usage::percent()with the formula, and Tier 1 tests that a coarse sample (5 busy ticks in 1 wall tick on 4 cores) reads at most 100. Failsa_coarse_sample_is_at_most_all_of_the_machine(125.0, want 100.0).Tests
obs-utilCPU usage and platform tests (Tier 1 and the Tier 3 parity against the C): 52 passed; clippy clean.Checklist
masterdocs/features.md(CPU usage at most 100 %)🤖 Generated with Claude Code