mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-18 12:06:08 +00:00
fw: cache target info
Cache target info after pulling it from the device. Attempt to retrieve from cache before querying target.
This commit is contained in:
parent
770d2b2f0e
commit
e8f545861d
@ -498,6 +498,10 @@ class MetaConfiguration(Configuration):
|
||||
def additional_packages_file(self):
|
||||
return os.path.join(self.user_directory, 'packages')
|
||||
|
||||
@property
|
||||
def target_info_cache_file(self):
|
||||
return os.path.join(self.cache_directory, 'targets.json')
|
||||
|
||||
def __init__(self, environ=None):
|
||||
super(MetaConfiguration, self).__init__()
|
||||
if environ is None:
|
||||
|
@ -14,12 +14,16 @@
|
||||
#
|
||||
# pylint: disable=protected-access
|
||||
|
||||
import os
|
||||
from copy import copy
|
||||
|
||||
from devlib import AndroidTarget, TargetError
|
||||
from devlib.target import KernelConfig, KernelVersion, Cpuinfo
|
||||
from devlib.utils.android import AndroidProperties
|
||||
|
||||
from wa.framework.configuration.core import settings
|
||||
from wa.utils.serializer import read_pod, write_pod
|
||||
|
||||
|
||||
def cpuinfo_from_pod(pod):
|
||||
cpuinfo = Cpuinfo('')
|
||||
@ -226,6 +230,36 @@ def get_target_info(target):
|
||||
return info
|
||||
|
||||
|
||||
def read_target_info_cache():
|
||||
if not os.path.exists(settings.cache_directory):
|
||||
os.makedirs(settings.cache_directory)
|
||||
if not os.path.isfile(settings.target_info_cache_file):
|
||||
return {}
|
||||
return read_pod(settings.target_info_cache_file)
|
||||
|
||||
|
||||
def write_target_info_cache(cache):
|
||||
if not os.path.exists(settings.cache_directory):
|
||||
os.makedirs(settings.cache_directory)
|
||||
write_pod(cache, settings.target_info_cache_file)
|
||||
|
||||
|
||||
def get_target_info_from_cache(system_id):
|
||||
cache = read_target_info_cache()
|
||||
pod = cache.get(system_id, None)
|
||||
if not pod:
|
||||
return None
|
||||
return TargetInfo.from_pod(pod)
|
||||
|
||||
|
||||
def cache_target_info(target_info, overwrite=False):
|
||||
cache = read_target_info_cache()
|
||||
if target_info.system_id in cache and not overwrite:
|
||||
raise ValueError('TargetInfo for {} is already in cache.'.format(target_info.system_id))
|
||||
cache[target_info.system_id] = target_info.to_pod()
|
||||
write_target_info_cache(cache)
|
||||
|
||||
|
||||
class TargetInfo(object):
|
||||
|
||||
@staticmethod
|
||||
|
@ -24,7 +24,7 @@ from wa.framework.plugin import Parameter
|
||||
from wa.framework.target.descriptor import (get_target_description,
|
||||
instantiate_target,
|
||||
instantiate_assistant)
|
||||
from wa.framework.target.info import get_target_info
|
||||
from wa.framework.target.info import get_target_info, get_target_info_from_cache, cache_target_info
|
||||
from wa.framework.target.runtime_parameter_manager import RuntimeParameterManager
|
||||
|
||||
|
||||
@ -89,7 +89,11 @@ class TargetManager(object):
|
||||
|
||||
@memoized
|
||||
def get_target_info(self):
|
||||
return get_target_info(self.target)
|
||||
info = get_target_info_from_cache(self.target.system_id)
|
||||
if info is None:
|
||||
info = get_target_info(self.target)
|
||||
cache_target_info(info)
|
||||
return info
|
||||
|
||||
def reboot(self, context, hard=False):
|
||||
with signal.wrap('REBOOT', self, context):
|
||||
|
Loading…
x
Reference in New Issue
Block a user