Skip to content

Commit 76fae91

Browse files
committed
Adding CPU parser info to the inspector tool for command line retrival.
Signed-off-by: Rob Dobson <rob.dobson@citrix.com>
1 parent 1108d15 commit 76fae91

4 files changed

Lines changed: 135 additions & 7 deletions

File tree

hwinfo/host/cpuinfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class CPUInfoParser(CommandParser):
88

9+
ITEM_SEPERATOR = "\n\n"
910

1011
ITEM_REGEXS = [
1112
REGEX_TEMPLATE % ('processor', 'processor'),

hwinfo/host/tests/data/cpuinfo

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
processor : 0
2+
vendor_id : GenuineIntel
3+
cpu family : 6
4+
model : 30
5+
model name : Intel(R) Xeon(R) CPU X3430 @ 2.40GHz
6+
stepping : 5
7+
microcode : 0x3
8+
cpu MHz : 2394.052
9+
cache size : 8192 KB
10+
fpu : yes
11+
fpu_exception : yes
12+
cpuid level : 11
13+
wp : yes
14+
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc pni monitor vmx est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm dtherm tpr_shadow vnmi flexpriority ept vpid
15+
bogomips : 4788.10
16+
clflush size : 64
17+
cache_alignment : 64
18+
address sizes : 36 bits physical, 48 bits virtual
19+
power management:
20+
21+
processor : 1
22+
vendor_id : GenuineIntel
23+
cpu family : 6
24+
model : 30
25+
model name : Intel(R) Xeon(R) CPU X3430 @ 2.40GHz
26+
stepping : 5
27+
microcode : 0x3
28+
cpu MHz : 2394.052
29+
cache size : 8192 KB
30+
fpu : yes
31+
fpu_exception : yes
32+
cpuid level : 11
33+
wp : yes
34+
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc pni monitor vmx est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm dtherm tpr_shadow vnmi flexpriority ept vpid
35+
bogomips : 4788.10
36+
clflush size : 64
37+
cache_alignment : 64
38+
address sizes : 36 bits physical, 48 bits virtual
39+
power management:
40+
41+
processor : 2
42+
vendor_id : GenuineIntel
43+
cpu family : 6
44+
model : 30
45+
model name : Intel(R) Xeon(R) CPU X3430 @ 2.40GHz
46+
stepping : 5
47+
microcode : 0x3
48+
cpu MHz : 2394.052
49+
cache size : 8192 KB
50+
fpu : yes
51+
fpu_exception : yes
52+
cpuid level : 11
53+
wp : yes
54+
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc pni monitor vmx est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm dtherm tpr_shadow vnmi flexpriority ept vpid
55+
bogomips : 4788.10
56+
clflush size : 64
57+
cache_alignment : 64
58+
address sizes : 36 bits physical, 48 bits virtual
59+
power management:
60+
61+
processor : 3
62+
vendor_id : GenuineIntel
63+
cpu family : 6
64+
model : 30
65+
model name : Intel(R) Xeon(R) CPU X3430 @ 2.40GHz
66+
stepping : 5
67+
microcode : 0x3
68+
cpu MHz : 2394.052
69+
cache size : 8192 KB
70+
fpu : yes
71+
fpu_exception : yes
72+
cpuid level : 11
73+
wp : yes
74+
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc pni monitor vmx est ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm dtherm tpr_shadow vnmi flexpriority ept vpid
75+
bogomips : 4788.10
76+
clflush size : 64
77+
cache_alignment : 64
78+
address sizes : 36 bits physical, 48 bits virtual
79+
power management:
80+

hwinfo/host/tests/test_cpuinfo.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def setUp(self):
5656
self.parser = CPUInfoParser(self.DATA.strip())
5757

5858
def _assert_equal(self, key):
59-
rec = self.parser.parse()
59+
rec = self.parser.parse_items()[0]
6060
return self.assertEqual(rec[key], self.DATA_REC[key])
6161

6262
def test_cpuinfo_processor(self):
@@ -112,3 +112,17 @@ def test_cache_alignment(self):
112112

113113
def test_address_sizes(self):
114114
return self._assert_equal('address_sizes')
115+
116+
class CPUInfoMultipleParseTest(unittest.TestCase):
117+
118+
DATA_FILE = "%s/cpuinfo" % DATA_DIR
119+
120+
def setUp(self):
121+
fh = open(self.DATA_FILE)
122+
data = fh.read()
123+
fh.close()
124+
self.parser = CPUInfoParser(data)
125+
126+
def test_number_of_processors(self):
127+
recs = self.parser.parse_items()
128+
self.assertEqual(len(recs), 4)

hwinfo/tools/inspector.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from hwinfo.pci.lspci import *
1111

1212
from hwinfo.host import dmidecode
13+
from hwinfo.host import cpuinfo
1314

1415
def remote_command(host, username, password, cmd):
1516
client = paramiko.SSHClient()
@@ -54,6 +55,9 @@ def get_lspci_data(self):
5455
def get_dmidecode_data(self):
5556
return self.exec_command(['dmidecode'])
5657

58+
def get_cpuinfo_data(self):
59+
return self.exec_command(['cat /proc/cpuinfo'])
60+
5761
def get_pci_devices(self):
5862
data = self.get_lspci_data()
5963
parser = LspciNNMMParser(data)
@@ -66,6 +70,11 @@ def get_info(self):
6670
rec = parser.parse()
6771
return rec
6872

73+
def get_cpu_info(self):
74+
data = self.get_cpuinfo_data()
75+
parser = cpuinfo.CPUInfoParser(data)
76+
return parser.parse_items()
77+
6978
def search_for_file(dirname, filename):
7079
for root, _, files in os.walk(dirname):
7180
if filename in files:
@@ -93,6 +102,9 @@ def get_lspci_data(self):
93102
def get_dmidecode_data(self):
94103
return self._load_from_file('dmidecode.out')
95104

105+
def get_cpuinfo_data(self):
106+
return self._load_from_file('cpuinfo')
107+
96108
def pci_filter(devices, types):
97109
res = []
98110
for device in devices:
@@ -122,6 +134,13 @@ def rec_to_table(rec):
122134
table.add_row([k, v])
123135
return table
124136

137+
def tabulate_recs(recs, header):
138+
table = PrettyTable(header)
139+
for rec in recs:
140+
vls = [rec[k] for k in header]
141+
table.add_row(vls)
142+
return table
143+
125144
def tabulate_pci_recs(recs):
126145
header = [
127146
'vendor_name',
@@ -133,18 +152,26 @@ def tabulate_pci_recs(recs):
133152
'subdevice_name',
134153
'subdevice_id',
135154
]
136-
table = PrettyTable(header)
137-
for rec in recs:
138-
vls = [rec[k] for k in header]
139-
table.add_row(vls)
140-
return table
155+
return tabulate_recs(recs, header)
156+
157+
def tabulate_cpu_recs(recs):
158+
header = [
159+
'processor',
160+
'vendor_id',
161+
'cpu_family',
162+
'model',
163+
'stepping',
164+
'model_name',
165+
'cpu_mhz',
166+
]
167+
return tabulate_recs(recs, header)
141168

142169
def main():
143170
"""Entry Point"""
144171

145172
parser = ArgumentParser(prog="hwinfo")
146173

147-
filter_choices = ['bios', 'nic', 'storage', 'gpu']
174+
filter_choices = ['bios', 'nic', 'storage', 'gpu', 'cpu']
148175
parser.add_argument("-f", "--filter", choices=filter_choices, help="Query a specific class.")
149176
parser.add_argument("-m", "--machine", default='localhost', help="Remote host address.")
150177
parser.add_argument("-u", "--username", help="Username for remote host.")
@@ -173,6 +200,12 @@ def main():
173200
print rec_to_table(host.get_info())
174201
print ""
175202

203+
if 'cpu' in options:
204+
print "CPU Info:"
205+
print ""
206+
print tabulate_cpu_recs(host.get_cpu_info())
207+
print ""
208+
176209
if 'nic' in options:
177210
devices = pci_filter_for_nics(host.get_pci_devices())
178211
print "Ethernet Controller Info:"

0 commit comments

Comments
 (0)