How to use read_from_meminfo method in avocado

Best Python code snippet using avocado_python

utils_memory.py

Source:utils_memory.py Github

copy

Full Screen

...5import os6from autotest.client import utils7from autotest.client.shared import error8# Returns total memory in kb9def read_from_meminfo(key):10 cmd_result = utils.run('grep %s /proc/meminfo' % key, verbose=False)11 meminfo = cmd_result.stdout12 return int(re.search(r'\d+', meminfo).group(0))13def memtotal():14 return read_from_meminfo('MemTotal')15def freememtotal():16 return read_from_meminfo('MemFree')17def rounded_memtotal():18 # Get total of all physical mem, in kbytes19 usable_kbytes = memtotal()20 # usable_kbytes is system's usable DRAM in kbytes,21 # as reported by memtotal() from device /proc/meminfo memtotal22 # after Linux deducts 1.5% to 5.1% for system table overhead23 # Undo the unknown actual deduction by rounding up24 # to next small multiple of a big power-of-two25 # eg 12GB - 5.1% gets rounded back up to 12GB26 mindeduct = 0.015 # 1.5 percent27 maxdeduct = 0.055 # 5.5 percent28 # deduction range 1.5% .. 5.5% supports physical mem sizes29 # 6GB .. 12GB in steps of .5GB30 # 12GB .. 24GB in steps of 1 GB31 # 24GB .. 48GB in steps of 2 GB ...32 # Finer granularity in physical mem sizes would require33 # tighter spread between min and max possible deductions34 # increase mem size by at least min deduction, without rounding35 min_kbytes = int(usable_kbytes / (1.0 - mindeduct))36 # increase mem size further by 2**n rounding, by 0..roundKb or more37 round_kbytes = int(usable_kbytes / (1.0 - maxdeduct)) - min_kbytes38 # find least binary roundup 2**n that covers worst-cast roundKb39 mod2n = 1 << int(math.ceil(math.log(round_kbytes, 2)))40 # have round_kbytes <= mod2n < round_kbytes*241 # round min_kbytes up to next multiple of mod2n42 phys_kbytes = min_kbytes + mod2n - 143 phys_kbytes = phys_kbytes - (phys_kbytes % mod2n) # clear low bits44 return phys_kbytes45def numa_nodes():46 node_paths = glob.glob('/sys/devices/system/node/node*')47 nodes = [int(re.sub(r'.*node(\d+)', r'\1', x)) for x in node_paths]48 return (sorted(nodes))49def node_size():50 nodes = max(len(numa_nodes()), 1)51 return ((memtotal() * 1024) / nodes)52def get_huge_page_size():53 return read_from_meminfo('Hugepagesize')54def get_num_huge_pages():55 return read_from_meminfo('HugePages_Total')56def get_num_huge_pages_free():57 return read_from_meminfo('HugePages_Free')58def get_num_huge_pages_rsvd():59 return read_from_meminfo('HugePages_Rsvd')60def get_num_anon_huge_pages(pid=0):61 if int(pid) > 1:62 # get AnonHugePages usage of specified process63 return read_from_smaps(pid, 'AnonHugePages')64 else:65 # invalid pid, so return AnonHugePages of the host66 return read_from_meminfo('AnonHugePages')67def get_transparent_hugepage():68 UPSTREAM_THP_PATH = "/sys/kernel/mm/transparent_hugepage"69 RH_THP_PATH = "/sys/kernel/mm/redhat_transparent_hugepage"70 if os.path.isdir(UPSTREAM_THP_PATH):71 thp_path = UPSTREAM_THP_PATH72 elif os.path.isdir(RH_THP_PATH):73 thp_path = RH_THP_PATH74 else:75 raise error.TestFail("transparent hugepage Not supported")76 out = utils.system_output('cat %s/enabled' % thp_path)77 if out[0] == "[always]":78 return 'always'79 elif out[1] == "[madvise]":80 return 'madvise'...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful