Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Condense 4 calls of popen(lscpu|grep) into one single call of popen(lscpu) #87

Open
wants to merge 1 commit into
base: v1.x.x
Choose a base branch
from
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])