android: fall back to /proc/cpuinfo when /proc/stat is unreadable - #1715
Merged
Conversation
Added a function to build CPU list from /proc/cpuinfo for Android when /proc/stat is unreadable.
| @@ -63,6 +63,11 @@ impl CpusWrapper { | |||
| Ok(f) => f, | |||
| Err(_e) => { | |||
| sysinfo_debug!("failed to retrieve CPU information: {:?}", _e); | |||
Owner
There was a problem hiding this comment.
Maybe only move/modify this sysinfo_debug if on android since the information is still kinda computed.
Added logging for CPU usage information retrieval failure on Android.
Contributor
Author
|
Thanks, good point. I updated this so the non-Android path keeps the existing I also rechecked the behavior on the Android/Termux device:
So the fallback only recovers the static CPU information and frequency; CPU usage remains unavailable on this Android path. |
GuillaumeGomez
approved these changes
Aug 17, 2026
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.
Problem
On Android,
/proc/statis typically unreadable by regular apps (includingTermux) — it's blocked by SELinux policy since Android 8. When this happens,
CpusWrapper::refresh()currently returns early with an emptycpuslist,so no CPU information (name, vendor, brand, frequency) is ever populated,
even though
/proc/cpuinfo— which is readable — has all of it.Fix
Add an Android-only fallback,
build_cpus_from_cpuinfo, that builds the CPUlist from
/proc/cpuinfo(via the existingget_vendor_id_and_brand) whenopening
/proc/statfails. It's only triggered on the first refresh (first),matching the existing pattern used elsewhere in this function. CPU frequency
is optionally populated via the existing
get_cpu_frequency, which reads/sys/devices/system/cpu/cpuN/cpufreq/scaling_cur_freqand doesn't depend on/proc/stat.Note that
cpu_usage()will remain0.0for CPUs built this way — usagepercentages require successive
/proc/statsnapshots, and there's no publicAndroid API providing equivalent per-CPU tick counters. This is documented on
the new function.
Testing
Verified on a physical Android device (Termux):
System::new_all()→cpus()returns 0 CPUscpus()returns 8 CPUs, each with correct name (cpu0..cpu7),vendor (
ARM), brand (e.g.Cortex-A725), and frequencyThis was originally surfaced while building
otreeon Termux viacargo install,where
vergen'ssifeature emittedVERGEN_SYSINFO_CPU_VENDOR/_CPU_BRAND/_CPU_FREQUENCYwarnings becausesysinfocouldn't resolveCPU info on this platform.
Companion PR for the same root cause, affecting
Users: #1714