Skip to content

Commit

Permalink
Merge pull request #3757 from dzhengfy/new_func_numa_node_mem
Browse files Browse the repository at this point in the history
utils_memory: support to seach new meminfo file
  • Loading branch information
chunfuwen authored Dec 4, 2023
2 parents 71382b8 + d0de720 commit fb4cab6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions virttest/staging/utils_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,34 @@


# Returns total memory in kb
def read_from_meminfo(key, session=None):
def read_from_meminfo(key, session=None, node_id=''):
"""
wrapper to return value from /proc/meminfo using key
:param key: filter based on the key
:param session: ShellSession Object of remote host / guest
:param node_id: str, numa node id
:return: value mapped to the key of type int
"""
func = process.getoutput
if session:
func = session.cmd_output
meminfo = func('grep %s /proc/meminfo' % key)
return int(re.search(r'\d+', meminfo).group(0))
search_file = '/sys/devices/system/node/node%s/meminfo' % node_id \
if node_id else '/proc/meminfo'

meminfo = func('grep %s %s' % (key, search_file))
return int(re.findall(r'%s:\s+(\d+)' % key, meminfo)[0])

def memtotal(session=None):

def memtotal(session=None, node_id=''):
"""
Method to get the memtotal from /proc/meminfo
Method to get the memtotal from /proc/meminfo or
/sys/devices/system/node/nodexx/meminfo
:param session: ShellSession Object of remote host / guest
:param node_id: str, numa node id
"""
return read_from_meminfo('MemTotal', session=session)
return read_from_meminfo('MemTotal', session=session, node_id=node_id)


def freememtotal(session=None):
Expand Down

0 comments on commit fb4cab6

Please sign in to comment.