1# Copyright 2015 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5"""An adapter to remotely access the system facade on DUT.""" 6 7 8class SystemFacadeRemoteAdapter(object): 9 """SystemFacadeRemoteAdapter is an adapter to remotely control DUT system. 10 11 The Autotest host object representing the remote DUT, passed to this 12 class on initialization, can be accessed from its _client property. 13 14 """ 15 def __init__(self, host, remote_facade_proxy): 16 """Construct an SystemFacadeRemoteAdapter. 17 18 @param host: Host object representing a remote host. 19 @param remote_facade_proxy: RemoteFacadeProxy object. 20 21 """ 22 self._client = host 23 self._proxy = remote_facade_proxy 24 25 26 @property 27 def _system_proxy(self): 28 """Gets the proxy to DUT system facade. 29 30 @return XML RPC proxy to DUT system facade. 31 32 """ 33 return self._proxy.system 34 35 36 def set_scaling_governor_mode(self, index, mode): 37 """Set mode of CPU scaling governor on one CPU of DUT. 38 39 @param index: CPU index starting from 0. 40 41 @param mode: Mode of scaling governor, accept 'interactive' or 42 'performance'. 43 44 @returns: The original mode. 45 46 """ 47 return self._system_proxy.set_scaling_governor_mode(index, mode) 48 49 50 def get_cpu_usage(self): 51 """Returns machine's CPU usage. 52 53 Returns: 54 A dictionary with 'user', 'nice', 'system' and 'idle' values. 55 Sample dictionary: 56 { 57 'user': 254544, 58 'nice': 9, 59 'system': 254768, 60 'idle': 2859878, 61 } 62 """ 63 return self._system_proxy.get_cpu_usage() 64 65 66 def compute_active_cpu_time(self, cpu_usage_start, cpu_usage_end): 67 """Computes the fraction of CPU time spent non-idling. 68 69 This function should be invoked using before/after values from calls to 70 get_cpu_usage(). 71 """ 72 return self._system_proxy.compute_active_cpu_time(cpu_usage_start, 73 cpu_usage_end) 74 75 76 def get_mem_total(self): 77 """Returns the total memory available in the system in MBytes.""" 78 return self._system_proxy.get_mem_total() 79 80 81 def get_mem_free(self): 82 """Returns the currently free memory in the system in MBytes.""" 83 return self._system_proxy.get_mem_free() 84 85 def get_mem_free_plus_buffers_and_cached(self): 86 """ 87 Returns the free memory in MBytes, counting buffers and cached as free. 88 89 This is most often the most interesting number since buffers and cached 90 memory can be reclaimed on demand. Note however, that there are cases 91 where this as misleading as well, for example used tmpfs space 92 count as Cached but can not be reclaimed on demand. 93 See https://www.kernel.org/doc/Documentation/filesystems/tmpfs.txt. 94 """ 95 return self._system_proxy.get_mem_free_plus_buffers_and_cached() 96 97 def get_ec_temperatures(self): 98 """Uses ectool to return a list of all sensor temperatures in Celsius. 99 """ 100 return self._system_proxy.get_ec_temperatures() 101 102 def get_current_temperature_max(self): 103 """ 104 Returns the highest reported board temperature (all sensors) in Celsius. 105 """ 106 return self._system_proxy.get_current_temperature_max() 107 108 def get_current_board(self): 109 """Returns the current device board name.""" 110 return self._system_proxy.get_current_board() 111 112 113 def get_chromeos_release_version(self): 114 """Returns chromeos version in device under test as string. None on 115 fail. 116 """ 117 return self._system_proxy.get_chromeos_release_version() 118 119 def get_num_allocated_file_handles(self): 120 """ 121 Returns the number of currently allocated file handles. 122 """ 123 return self._system_proxy.get_num_allocated_file_handles() 124 125 def get_storage_statistics(self, device=None): 126 """ 127 Fetches statistics for a storage device. 128 """ 129 return self._system_proxy.get_storage_statistics(device) 130