1
1
#!/usr/bin/env python3
3
Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4
Industrial Technology Research Institute
7
1. Use lshw command to gather memory information.
8
2. Testing prerequisites:
9
4 channels DDR3 registered memory interface on each processor 0
11
2 DDR3 slots per channel per processor. (total of 16 DIMMs
13
3. The program will output memory module, vendor, size and slot.
14
4. Criteria: Total of 16 DIMMs on the motherboard.
17
Nelson Chu <Nelson.Chu@itri.org.tw>
19
This program is free software: you can redistribute it and/or modify
20
it under the terms of the GNU General Public License version 3,
21
as published by the Free Software Foundation.
23
This program is distributed in the hope that it will be useful,
24
but WITHOUT ANY WARRANTY; without even the implied warranty of
25
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
GNU General Public License for more details.
28
You should have received a copy of the GNU General Public License
29
along with this program. If not, see <http://www.gnu.org/licenses/>.
34
import xml.etree.ElementTree as ET
35
from subprocess import Popen, PIPE
38
attribute = ['description', 'vendor', 'slot', 'size']
40
hwinfo_xml = Popen(command, stdout=PIPE, stderr=PIPE,
41
shell=True).communicate()[0]
42
root = ET.fromstring(hwinfo_xml)
44
memory_list = root.findall(".//clock/..[@class='memory']")
47
print("Fail: Cannot parse any memory information.")
51
for dimm in memory_list:
52
if dimm.find('slot') is None:
55
for attr in attribute:
56
if dimm.find(attr) is None:
57
print(("Fail: Cannot find memory %s") %attr, file=sys.stderr)
61
memory_size = int(dimm.find('size').text) / (1024**3)
62
for attr in attribute:
63
if attr == 'description':
64
print('%s' %(dimm.find(attr).text), end=" ")
67
print('%s=%dGB.' %(attr, memory_size))
69
print('%s=%s' %(attr, dimm.find(attr).text), end=" ")
71
print("Total number of DIMMs is %s." %(count))
73
print("Fail: Memory DIMM number is not meet the requirement.",
9
for line in open("/proc/meminfo").readlines():
10
match = re.match(r"(.*):\s+(.*)", line)
13
value = match.group(2)
20
meminfo = get_meminfo()
21
amount, units = meminfo["MemTotal"].split()
23
amount = float(amount)
24
next_units = {'kB': 'MB',
28
amount = amount / 1024
29
units = next_units[units]
31
print("%.1f %s" % (amount, units))
79
if __name__ == '__main__':
34
if __name__ == "__main__":
35
sys.exit(main(sys.argv[1:]))