mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 10:10:46 +00:00
module/hwmon: optimize initialization.
Optimize hwmon module initialization by using the new Target.grep_values call to get information about all HWMON devices in a single call to the target.
This commit is contained in:
parent
181bc180c4
commit
5a599f91db
@ -12,6 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
@ -78,16 +79,15 @@ class HwmonDevice(object):
|
|||||||
all_sensors.extend(sensors_of_kind.values())
|
all_sensors.extend(sensors_of_kind.values())
|
||||||
return all_sensors
|
return all_sensors
|
||||||
|
|
||||||
def __init__(self, target, path):
|
def __init__(self, target, path, name, fields):
|
||||||
self.target = target
|
self.target = target
|
||||||
self.path = path
|
self.path = path
|
||||||
self.name = self.target.read_value(self.target.path.join(self.path, 'name'))
|
self.name = name
|
||||||
self._sensors = defaultdict(dict)
|
self._sensors = defaultdict(dict)
|
||||||
path = self.path
|
path = self.path
|
||||||
if not path.endswith(self.target.path.sep):
|
if not path.endswith(self.target.path.sep):
|
||||||
path += self.target.path.sep
|
path += self.target.path.sep
|
||||||
for entry in self.target.list_directory(path,
|
for entry in fields:
|
||||||
as_root=self.target.is_rooted):
|
|
||||||
match = HWMON_FILE_REGEX.search(entry)
|
match = HWMON_FILE_REGEX.search(entry)
|
||||||
if match:
|
if match:
|
||||||
kind = match.group('kind')
|
kind = match.group('kind')
|
||||||
@ -117,14 +117,11 @@ class HwmonModule(Module):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def probe(target):
|
def probe(target):
|
||||||
if not target.file_exists(HWMON_ROOT):
|
|
||||||
return False
|
|
||||||
try:
|
try:
|
||||||
target.list_directory(HWMON_ROOT, as_root=target.is_rooted)
|
target.list_directory(HWMON_ROOT, as_root=target.is_rooted)
|
||||||
except TargetError:
|
except TargetError:
|
||||||
# Probably no permissions
|
# Doesn't exist or no permissions
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -141,11 +138,13 @@ class HwmonModule(Module):
|
|||||||
self.scan()
|
self.scan()
|
||||||
|
|
||||||
def scan(self):
|
def scan(self):
|
||||||
for entry in self.target.list_directory(self.root,
|
values_tree = self.target.read_tree_values(self.root, depth=3)
|
||||||
as_root=self.target.is_rooted):
|
for entry_id, fields in values_tree.iteritems():
|
||||||
if entry.startswith('hwmon'):
|
path = self.target.path.join(self.root, entry_id)
|
||||||
entry_path = self.target.path.join(self.root, entry)
|
name = fields.pop('name', None)
|
||||||
if self.target.file_exists(self.target.path.join(entry_path, 'name')):
|
if name is None:
|
||||||
device = HwmonDevice(self.target, entry_path)
|
continue
|
||||||
self.devices.append(device)
|
self.logger.debug('Adding device {}'.format(name))
|
||||||
|
device = HwmonDevice(self.target, path, name, fields)
|
||||||
|
self.devices.append(device)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user