def test_use_process_stats(): from mars import resource cpu_total = resource.cpu_count() mem_total = resource.virtual_memory().total try: os.environ["MARS_USE_PROCESS_STAT"] = "1" os.environ["MARS_CPU_TOTAL"] = str(cpu_total) os.environ["MARS_MEMORY_TOTAL"] = str(mem_total) resource = importlib.reload(resource) resource.cpu_percent() time.sleep(0.5) mem_stats = resource.virtual_memory() assert mem_stats.available >= 0 assert mem_stats.total >= 0 assert mem_stats.percent >= 0 assert mem_stats.used >= 0 assert mem_stats.free >= 0 cpu_usage = resource.cpu_percent() assert cpu_usage >= 0 cpu_usage = resource.cpu_percent() assert cpu_usage >= 0 finally: del os.environ["MARS_USE_PROCESS_STAT"] del os.environ["MARS_CPU_TOTAL"] del os.environ["MARS_MEMORY_TOTAL"] importlib.reload(resource)
def testUseProcessStats(self): from mars import resource cpu_total = resource.cpu_count() mem_total = resource.virtual_memory().total try: os.environ['MARS_USE_PROCESS_STAT'] = '1' os.environ['MARS_CPU_TOTAL'] = str(cpu_total) os.environ['MARS_MEMORY_TOTAL'] = str(mem_total) resource = importlib.reload(resource) resource.cpu_percent() time.sleep(0.5) mem_stats = resource.virtual_memory() self.assertGreaterEqual(mem_stats.available, 0) self.assertGreaterEqual(mem_stats.total, 0) self.assertGreaterEqual(mem_stats.percent, 0) self.assertGreaterEqual(mem_stats.used, 0) self.assertGreaterEqual(mem_stats.free, 0) cpu_usage = resource.cpu_percent() self.assertGreaterEqual(cpu_usage, 0) cpu_usage = resource.cpu_percent() self.assertGreaterEqual(cpu_usage, 0) finally: del os.environ['MARS_USE_PROCESS_STAT'] del os.environ['MARS_CPU_TOTAL'] del os.environ['MARS_MEMORY_TOTAL'] importlib.reload(resource)
def gather_node_info(): from .lib.mkl_interface import mkl_get_version mem_stats = resource.virtual_memory() node_info = dict() node_info['command_line'] = ' '.join(sys.argv) node_info['platform'] = platform.platform() node_info['host_name'] = socket.gethostname() node_info['sys_version'] = sys.version node_info['cpu_info'] = 'Used: %f\nTotal: %d' % ( resource.cpu_percent() / 100.0, resource.cpu_count()) node_info['memory_info'] = 'Used: %s\nTotal: %s' % (readable_size( mem_stats.used), readable_size(mem_stats.total)) for collector in _collectors.values(): node_info.update(collector()) if np is None: node_info['numpy_info'] = 'Not installed' else: sio = six.StringIO() sio.write('Version: %s\n' % np.__version__) if hasattr(np, '__mkl_version__') and mkl_get_version: mkl_version = mkl_get_version() sio.write( 'MKL Version: %d.%d.%d\n' % (mkl_version.major, mkl_version.minor, mkl_version.update)) node_info['numpy_info'] = sio.getvalue().strip() if scipy is None: node_info['scipy_info'] = 'Not installed' else: node_info['scipy_info'] = 'Version: %s' % scipy.__version__ git = git_info() if git: node_info['git_info'] = '%s %s' % (git[0], git[1]) else: node_info['git_info'] = 'Not available' return node_info