[Sensors][proposed patch] sensors.py: Current implementation of bat_get_data very slow

Bug #292022 reported by peacey
2
Affects Status Importance Assigned to Milestone
Individual Screenlets
New
Undecided
Unassigned

Bug Description

Hello,

The current implementation of bat_get_data is extremely slow. It takes around 2 seconds to even 3 sometimes for the function to return. Consequently, this causes any screenlet that uses this function to stall for 2 or 3 seconds. It even causes the preferences window of the screenlet to stall whenever the battery information gets updated.
Instead, I propose we use dbus to obtain the battery information.

Here are the two functions:

def bat_get_battery_list_from_dbus():
 """Returns battery list"""
 """DBus version"""
 try:
  system_bus = dbus.SystemBus()
         hal_manager = system_bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')
  batteries = hal_manager.FindDeviceByCapability('battery', dbus_interface='org.freedesktop.Hal.Manager')
  return batteries
 except:
  return[]

def bat_get_data_from_dbus(udi):
 """Returns battery data"""
 """DBus version"""
 try:
  total = 0
  current = 0
  full = 0
  state = ''
  present = True
  system_bus = dbus.SystemBus()
  bat_obj = system_bus.get_object('org.freedesktop.Hal', udi)
  battery = dbus.Interface(bat_obj, dbus_interface='org.freedesktop.Hal.Device')
  present = battery.GetProperty('battery.present')
  total = battery.GetProperty('battery.reporting.design')
  full = battery.GetProperty('battery.reporting.last_full')
  current = battery.GetProperty('battery.reporting.current')
  if (battery.GetProperty('battery.rechargeable.is_charging') == True):
   state = "charging"
  else:
   state = "discharging"
  return total, current, full, state, present
 except:
  return 0, 0, 0, '', False

I have tested this on my machine and there are no more stalls or lags.
There are two proposed patches in the tar file attached: the first one is for sensors.py and the second one is for SysmonitorScreenlet.py for demonstration purposes.
The second patch modifies SysmonitorScreenlet.py to use the new dbus battery functions.
Note: In the SysmonitorScreenlet patch, the last modification was added because in my SysmonitorScreenlet, the Uptime text that is rendered is rendered on top of the processes/top command which makes it hard to read. So I just moved it down a little. Not sure if it happens to others.

Revision history for this message
peacey (peaceyall) wrote :
Papp Bence (sclegnrbs)
affects: screenlets → indiv-screenlets
summary: - [proposed patch] sensors.py: Current implementation of bat_get_data very
- slow
+ [Sensors][proposed patch] sensors.py: Current implementation of
+ bat_get_data very slow
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.