mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-22 09:32:40 -06:00
scripts/kvm/kvm_stat: Cleanup cpu list retrieval
Reading /sys/devices/system/cpu/online makes opening the cpu directories unnecessary and works on more/older systems. Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com> Message-Id: <1452525484-32309-21-git-send-email-frankja@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
e06715a363
commit
357bc1e74f
1 changed files with 20 additions and 11 deletions
|
@ -280,18 +280,27 @@ def walkdir(path):
|
||||||
return next(os.walk(path))
|
return next(os.walk(path))
|
||||||
|
|
||||||
|
|
||||||
|
def parse_int_list(list_string):
|
||||||
|
"""Returns an int list from a string of comma separated integers and
|
||||||
|
integer ranges."""
|
||||||
|
integers = []
|
||||||
|
members = list_string.split(',')
|
||||||
|
|
||||||
|
for member in members:
|
||||||
|
if '-' not in member:
|
||||||
|
integers.append(int(member))
|
||||||
|
else:
|
||||||
|
int_range = member.split('-')
|
||||||
|
integers.extend(range(int(int_range[0]),
|
||||||
|
int(int_range[1]) + 1))
|
||||||
|
|
||||||
|
return integers
|
||||||
|
|
||||||
|
|
||||||
def get_online_cpus():
|
def get_online_cpus():
|
||||||
cpulist = []
|
with open('/sys/devices/system/cpu/online') as cpu_list:
|
||||||
pattern = r'cpu([0-9]+)'
|
cpu_string = cpu_list.readline()
|
||||||
basedir = '/sys/devices/system/cpu'
|
return parse_int_list(cpu_string)
|
||||||
for entry in os.listdir(basedir):
|
|
||||||
match = re.match(pattern, entry)
|
|
||||||
if not match:
|
|
||||||
continue
|
|
||||||
path = os.path.join(basedir, entry, 'online')
|
|
||||||
if os.path.isfile(path) and open(path).read().strip() == '1':
|
|
||||||
cpulist.append(int(match.group(1)))
|
|
||||||
return cpulist
|
|
||||||
|
|
||||||
filters = {}
|
filters = {}
|
||||||
filters['kvm_userspace_exit'] = ('reason', USERSPACE_EXIT_REASONS)
|
filters['kvm_userspace_exit'] = ('reason', USERSPACE_EXIT_REASONS)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue