def low_swap_free(self): """Returns true if free swap is low.""" meminfo = utils.get_meminfo() if meminfo.SwapFree < meminfo.SwapTotal * _LOW_SWAP_THRESHOLD: logging.info("Swap is low, swap free: %d, swap total: %d", meminfo.SwapFree, meminfo.SwapTotal) return True return False
def test_get_meminfo(self): self.fake_file_text = ('MemTotal: 2048000 kB\n' 'MemFree: 307200 kB\n' 'Buffers: 102400 kB\n' 'Cached: 204800 kB\n' 'Active(anon): 409600 kB') meminfo = utils.get_meminfo() self.assertEqual(meminfo.MemTotal, 2048000) self.assertEqual(meminfo.Active_anon, 409600)
def sample(self, fps_info): """Gets a fps sample with system state.""" vmstat = self.get_vmstat() vmstat_diff = self.VMStat( *[(end - start) for start, end in zip(self._prev_vmstat, vmstat)]) self._prev_vmstat = vmstat cpustat = utils.get_cpu_usage() cpuload = utils.compute_active_cpu_time(self._prev_cpustat, cpustat) self._prev_cpustat = cpustat mem_info_in_kb = utils.get_meminfo() # Converts mem_info from KB to MB. mem_info = collections.namedtuple( 'MemInfo', mem_info_in_kb._fields)(*[v / float(1024) for v in mem_info_in_kb]) consumer_pids = self._get_consumer_pid_func() logging.info('Consumers %s', consumer_pids) consumer_rss, consumer_swap = self.get_consumer_meminfo(consumer_pids) # fps_info = (frame_info, frame_times) fps_count = len([f for f in fps_info[0] if f != ' ']) sample = self.Sample( pswpin=vmstat_diff.pswpin, pswpout=vmstat_diff.pswpout, free_mem=mem_info.MemFree, buff_mem=mem_info.Buffers, cached_mem=mem_info.Cached, anon_mem=mem_info.Active_anon + mem_info.Inactive_anon, file_mem=mem_info.Active_file + mem_info.Inactive_file, swap_free=mem_info.SwapFree, swap_used=mem_info.SwapTotal - mem_info.SwapFree, consumer_num=len(consumer_pids), consumer_rss=consumer_rss, consumer_swap=consumer_swap, cpuload=cpuload, fps=fps_count) logging.info(sample) with self._samples_lock: self._samples.append(sample)
def run_once(self, switches_per_suspend=15, total_suspend_duration=2400, suspend_seconds=10, additional_sleep=10): """Runs the test once.""" username, password = arc_util.get_test_account_info() with chrome.Chrome(gaia_login=True, username=username, password=password) as cr: tabs = self.create_tabs(cr) suspend_count = self.cycling_suspend(cr, tabs, switches_per_suspend, total_suspend_duration, suspend_seconds, additional_sleep) tabs_after_suspending = len(cr.browser.tabs) meminfo = utils.get_meminfo() ending_swap_free = meminfo.SwapFree swap_total = meminfo.SwapTotal perf_results = {} perf_results['number_of_tabs'] = len(tabs) perf_results['number_of_suspending'] = suspend_count perf_results['tabs_after_suspending'] = tabs_after_suspending perf_results['ending_swap_free'] = ending_swap_free perf_results['swap_total'] = swap_total self.write_perf_keyval(perf_results) self.output_perf_value(description='number_of_tabs', value=len(tabs)) self.output_perf_value(description='number_of_suspending', value=suspend_count) self.output_perf_value(description='tabs_after_suspending', value=tabs_after_suspending) self.output_perf_value(description='ending_swap_free', value=ending_swap_free, units='KB') self.output_perf_value(description='swap_total', value=swap_total, units='KB')