b6f8f8dbef8e0b2ce1281cd5e0da69395b198b08
   1#
   2#   mem.py
   3#
   4#   Get instantaneous memory statistics (installed, total, free, available)
   5#
   6
   7import re
   8
   9from ..formatting import *
  10from .. import config
  11
  12import logging
  13logger = logging.getLogger(__name__)
  14
  15def parse_log():
  16
  17    logger.debug("Starting memory section")
  18    section = Section("memory")
  19    
  20    table = Table()
  21
  22    ram_b = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
  23    table.add_row(Row([Column("Installed"), Column(parsesize(ram_b))]))
  24
  25    raw_mem = util.readlog(config.prefs['logs']['meminfo'])
  26    total_regex = re.compile("(MemTotal:\s*| kB)+")
  27    free_regex = re.compile("MemFree:\s*")
  28
  29    for line in raw_mem.splitlines():
  30        matches = re.findall("^Mem(\w+):\s*(\d*)\s*kB$", line)
  31        if len(matches) > 0:
  32            logger.debug("Detected {0} memory of {1} kB".format(matches[0][0].lower(), matches[0][1]))
  33            table.add_row(Row([Column(matches[0][0]), Column(parsesize(float(matches[0][1])*1000))]))
  34#        if "Mem" in line:
  35#            total = line_regex.sub("", line, 1)
  36#            processor = proc_regex.sub("", processor)
  37#            if not processor in proc_data.items:
  38#                proc_data.items.append(processor)
  39#            else:
  40#                logger.debug("Found duplicate entry (perhaps multiple cores?) for {0}".format(processor))
  41#    if len(proc_data.items) > 0:
  42#        section.append_data(proc_data)
  43#    else:
  44#        logger.warning("Failed to find processor data")
  45
  46    table.align_column(0, "right")
  47    section.append_table(table)
  48
  49    logger.info("Finished memory section")
  50    return section