Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions sysmontask/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,31 @@ def cpuInit(self):
self.cpuCoreLabelValue.set_text(str(ps.cpu_count(logical=False)))
self.cpuLogicalLabelValue.set_text(str(self.cpu_logical_cores))

# Virtualisation Info
# Get the cache sizes and virtualisation information from `lscpu`
try:
p=popen('lscpu|grep -i -E "(vt-x)|(amd-v)"')
temp=p.read()
if temp:
temptext="Enabled"
else:
temptext="Disabled"
self.cpuVirtualisationLabelValue.set_text(temptext)
p.close()
except:
print("Failed to get Virtualisation information")

# CPU Caches
try:
p=popen('lscpu|grep -i -m1 "L1d"')
self.cpuL1LabelValue.set_text(sub("[\s]","",p.read().split(':')[1]))
p.close()

p=popen('lscpu|grep -i -m1 "L2"')
self.cpuL2LabelValue.set_text(sub('[\s]','',p.read().split(':')[1]))
p.close()

p=popen('lscpu|grep -i "L3"')
self.cpuL3LabelValue.set_text(sub('[\s]','',p.read().split(':')[1]))
p.close()
virtualisation = "N/A"
cache_l1 = "N/A"
cache_l2 = "N/A"
cache_l3 = "N/A"

lscpu = popen('lscpu').readlines()
for line in lscpu:
line = line.strip()
if line.startswith('L1d cache:'):
cache_l1 = line.split(':')[1].strip()
elif line.startswith('L2 cache:'):
cache_l2 = line.split(':')[1].strip()
elif line.startswith('L3 cache:'):
cache_l3 = line.split(':')[1].strip()
elif line.startswith('Virtualization:'):
virtualisation = line.split(':')[1].strip()

self.cpuVirtualisationLabelValue.set_text(virtualisation)
self.cpuL1LabelValue.set_text(cache_l1)
self.cpuL2LabelValue.set_text(cache_l2)
self.cpuL3LabelValue.set_text(cache_l3)
except:
print("Failed to get Cache information")
print("Failed to get Virtualisation and CPU cache information from `lscpu` shell command")

# CPU Frequency
self.speed=ps.cpu_freq()
Expand Down Expand Up @@ -226,4 +223,4 @@ def cpuUpdate(self):
self.cpuUtilArray.insert(0,self.cpuUtil)
for i in range(self.cpu_logical_cores):
self.cpu_logical_cores_util_arrays[i].pop()
self.cpu_logical_cores_util_arrays[i].insert(0,temp[i])
self.cpu_logical_cores_util_arrays[i].insert(0,temp[i])