Parse the battery report once instead of once per field - #9435
Open
VykosMolt wants to merge 1 commit into
Open
Conversation
omarchy-battery-status ran `upower -i` and then handed the same report to eight separate awk invocations, one per field, each one reading to its first match and exiting. The power panel re-runs the command every five seconds while it is open. One awk pass now reads all eight. Each field still takes the first line that matches it, which is what the separate `exit` in each pass was doing, and the two threshold fields still come back empty when the report does not carry them, so the sysfs fallback below them is unchanged. Finding the battery went from `upower -e | grep BAT | head -n 1` to one awk with an `exit`, for the same reason. On this machine, with `--shell`: quattro 22 processes 46.5 ms patched 14 processes 34.5 ms Output is byte-identical in both modes.
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.
omarchy-battery-statusrunsupower -iand then hands the same report to eight separateawkinvocations, one per field, each reading to its first match and exiting. The power panel re-runs the command every five seconds for as long as it is open.One
awkpass now reads all eight. Each field still takes the first line that matches it, which is what the separateexitin each pass was doing, and the two threshold fields still come back empty when the report does not carry them, so the sysfs fallback below them is unchanged.Finding the battery went from
upower -e | grep BAT | head -n 1to oneawkwith anexit, for the same reason.Testing
On this machine, with
--shell, counted withstrace -f -e trace=execve:Output is byte-identical in both modes:
battery-status-test.shgains two assertions on top of the ones already there. The first stubsawkwith a counting wrapper that execs the real one and requires at most six invocations; quattro runs eleven, so it fails there. The second feeds a report that carriescharge-start-thresholdandcharge-end-thresholdand states the time in minutes rather than hours, which covers the fields the single pass has to keep taking from the first matching line../test/shell— 217 of 221 files pass; the four failures (config-test,runtime-smoke-test,snapper-test,unowned-system-paths-test) fail identically on unmodified quattro on this machine.This comes out of https://github.com/VykosMolt/omarchy-desktop, where I have been running the Quattro shell as a plain Arch session and fixing what turned up.