mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-10-31 07:04:17 +00:00 
			
		
		
		
	fw/target_info: Prevent multiple parses of the target_info_cache
Instead of parsing the target_info_cache multiple times,allow for it to be read it once and passed as a paramter to the coresponding methods.
This commit is contained in:
		| @@ -292,8 +292,9 @@ def write_target_info_cache(cache): | ||||
|         write_pod(cache, settings.target_info_cache_file) | ||||
|  | ||||
|  | ||||
| def get_target_info_from_cache(system_id): | ||||
|     cache = read_target_info_cache() | ||||
| def get_target_info_from_cache(system_id, cache=None): | ||||
|     if cache is None: | ||||
|         cache = read_target_info_cache() | ||||
|     pod = cache.get(system_id, None) | ||||
|  | ||||
|     if not pod: | ||||
| @@ -307,8 +308,9 @@ def get_target_info_from_cache(system_id): | ||||
|     return TargetInfo.from_pod(pod) | ||||
|  | ||||
|  | ||||
| def cache_target_info(target_info, overwrite=False): | ||||
|     cache = read_target_info_cache() | ||||
| def cache_target_info(target_info, overwrite=False, cache=None): | ||||
|     if cache is None: | ||||
|         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() | ||||
|   | ||||
| @@ -24,7 +24,8 @@ 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, get_target_info_from_cache, cache_target_info | ||||
| from wa.framework.target.info import (get_target_info, get_target_info_from_cache, | ||||
|                                       cache_target_info, read_target_info_cache) | ||||
| from wa.framework.target.runtime_parameter_manager import RuntimeParameterManager | ||||
| from wa.utils.types import module_name_set | ||||
|  | ||||
| @@ -92,18 +93,19 @@ class TargetManager(object): | ||||
|  | ||||
|     @memoized | ||||
|     def get_target_info(self): | ||||
|         info = get_target_info_from_cache(self.target.system_id) | ||||
|         cache = read_target_info_cache() | ||||
|         info = get_target_info_from_cache(self.target.system_id, cache=cache) | ||||
|  | ||||
|         if info is None: | ||||
|             info = get_target_info(self.target) | ||||
|             cache_target_info(info) | ||||
|             cache_target_info(info, cache=cache) | ||||
|         else: | ||||
|             # If module configuration has changed form when the target info | ||||
|             # was previously cached, it is possible additional info will be | ||||
|             # available, so should re-generate the cache. | ||||
|             if module_name_set(info.modules) != module_name_set(self.target.modules): | ||||
|                 info = get_target_info(self.target) | ||||
|                 cache_target_info(info, overwrite=True) | ||||
|                 cache_target_info(info, overwrite=True, cache=cache) | ||||
|  | ||||
|         return info | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user