svartalf / rust-battery

Rust crate providing cross-platform information about the notebook batteries.
https://crates.io/crates/battery
Apache License 2.0
354 stars 40 forks source link

Populate battery data from uevent file #1

Closed svartalf closed 5 years ago

svartalf commented 5 years ago

Power supply folder might contain an uevent file, which can be used to load battery data with a fewer syscalls amount.

  1. uevent file by itself should be considered as optional, implementation should not check if it is exists on each refresh (confirm than kernel will not create it suddenly at some random point of time)
  2. Consider that any expected value might be missing in this file
  3. Find format specification if any exists (Let's help Dora dig the linux sources)
svartalf commented 5 years ago

After a short investigation I'm thinking that this is a bad idea: uevent file is updated rarely, only when udev thinks that it is time. As a quick experiment, I've tried the udevadm monitor --subsystem-match=power_supply shell command and did not received any event related to battery in twenty minutes.

udev allows to "refresh" uevent contents with change event, but this event will be propagated to all possible event listeners; considering that library users will want to refresh battery data roughly each couple of seconds this will spam the listeners.