def show_dict_mem_usage(dict_path=None, verbose=False): """ Show dictionary memory usage. """ initial_mem = get_mem_usage() initial_time = time.time() morph = pymorphy2.MorphAnalyzer(dict_path) end_time = time.time() mem_usage = get_mem_usage() logger.info( 'Memory usage: %0.1fM dictionary, %0.1fM total (load time %0.2fs)', (mem_usage - initial_mem) / (1024 * 1024), mem_usage / (1024 * 1024), end_time - initial_time) if verbose: try: from guppy import hpy hp = hpy() logger.debug(hp.heap()) except ImportError: logger.warn( 'guppy is not installed, detailed info is not available')
def show_dict_mem_usage(dict_path=None, verbose=False): """ Show dictionary memory usage. """ initial_mem = get_mem_usage() initial_time = time.time() morph = pymorphy2.MorphAnalyzer(dict_path) end_time = time.time() mem_usage = get_mem_usage() logger.info( "Memory usage: %0.1fM dictionary, %0.1fM total (load time %0.2fs)", (mem_usage - initial_mem) / (1024 * 1024), mem_usage / (1024 * 1024), end_time - initial_time, ) if verbose: try: from guppy import hpy hp = hpy() logger.debug(hp.heap()) except ImportError: logger.warn("guppy is not installed, detailed info is not available")
def show_dict_mem_usage(lang, dict_path=None, verbose=False): """ Show dictionary memory usage. """ initial_mem = get_mem_usage() initial_time = time.time() morph = pymorphy2.MorphAnalyzer(path=dict_path, lang=lang) end_time = time.time() mem_usage = get_mem_usage() logger.info( 'Memory usage: %0.1fM dictionary, %0.1fM total (load time %0.2fs)', (mem_usage-initial_mem)/(1024*1024), mem_usage/(1024*1024), end_time-initial_time )
def test_get_mem_usage(): pytest.importorskip("psutil") rss = get_mem_usage() assert 1000000 < rss < 1000000000 # 1MB to 1GB