1#
   2#   mem.py
   3#
   4#   Get instantaneous memory statistics (installed, total, free, available)
   5#
   6import re
   8from ..formatting import *
  10from .. import config
  11import logging
  13logger = logging.getLogger(__name__)
  14def parse_log():
  16    logger.debug("Starting memory section")
  18    section = Section("memory")
  19    
  20    table = Table()
  21    ram_b = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
  23    table.add_row(Row([Column("Installed"), Column(parsesize(ram_b))]))
  24    raw_mem = util.readlog(config.prefs['logs']['meminfo'])
  26    line_regex = re.compile("^Mem(\w+):\s*(\d*)\s*kB$")
  27    for line in raw_mem.splitlines():
  29        matches = line_regex.findall(line)
  31        if len(matches) > 0:
  33            logger.debug("Detected {0} memory of {1} kB".format(matches[0][0].lower(), matches[0][1]))
  34            table.add_row(Row([Column(matches[0][0]), Column(parsesize(float(matches[0][1])*1000))]))
  35    table.align_column(0, "right")
  37    section.append_table(table)
  38    logger.info("Finished memory section")
  40    return section