Skip to content

Parse the battery report once instead of once per field - #9435

Open
VykosMolt wants to merge 1 commit into
omacom:quattrofrom
VykosMolt:perf/battery-status-forks
Open

Parse the battery report once instead of once per field#9435
VykosMolt wants to merge 1 commit into
omacom:quattrofrom
VykosMolt:perf/battery-status-forks

Conversation

@VykosMolt

Copy link
Copy Markdown

omarchy-battery-status runs upower -i and then hands the same report to eight separate awk invocations, 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 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.

Testing

On this machine, with --shell, counted with strace -f -e trace=execve:

          processes    10 runs
quattro          22     46.5 ms
patched          14     34.5 ms

Output is byte-identical in both modes:

$ diff <(quattro --shell) <(patched --shell) && echo identical
identical
$ diff <(quattro) <(patched) && echo identical
identical

battery-status-test.sh gains two assertions on top of the ones already there. The first stubs awk with 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 carries charge-start-threshold and charge-end-threshold and 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.

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.
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