summaryrefslogtreecommitdiffstats
path: root/testsuites/vstf/vstf_scripts/vstf/agent/equalizer
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/vstf/vstf_scripts/vstf/agent/equalizer')
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/agent/equalizer/__init__.py8
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/agent/equalizer/equalizer.py78
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/agent/equalizer/get_info.py179
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/agent/equalizer/optimize.py69
4 files changed, 0 insertions, 334 deletions
diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/__init__.py b/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/__init__.py
deleted file mode 100644
index 83b8d15d..00000000
--- a/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/__init__.py
+++ /dev/null
@@ -1,8 +0,0 @@
-##############################################################################
-# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/equalizer.py b/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/equalizer.py
deleted file mode 100644
index 2fd20db1..00000000
--- a/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/equalizer.py
+++ /dev/null
@@ -1,78 +0,0 @@
-##############################################################################
-# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import os
-import re
-import subprocess
-import logging
-
-log = logging.getLogger(__name__)
-
-
-def run_cmd(cmd, shell=True):
- try:
- ret = subprocess.check_output(cmd, shell=shell)
- except subprocess.CalledProcessError as e:
- raise e
- return ret
-
-
-class Resource(object):
-
- def __init__(self):
- super(Resource, self).__init__()
- self.sysfs = "/sys/devices/system/node"
- self.mapping = {}
- for node in self._init_numa():
- self.mapping[node] = {}
-
- process_mapping = self._get_process_mapping(node)
- for process_index in xrange(0, len(bin(process_mapping)) - 2):
- if process_mapping & 1 << process_index != 0:
- core = self._get_core_id(node, process_index)
- if core not in self.mapping[node]:
- self.mapping[node][core] = []
- self.mapping[node][core].append(process_index)
-
- def _get_process_mapping(self, numa_node):
- ret = run_cmd("cat " + self.sysfs + '/' + numa_node +
- '/cpumap').replace(',', '').lstrip('0')
- return int(ret, 16)
-
- def _get_core_id(self, numa_node, process_index):
- cmd = "cat " + self.sysfs + '/' + numa_node + \
- '/cpu' + str(process_index) + '/topology/core_id'
- return run_cmd(cmd).strip('\n')
-
- def _init_numa(self):
- """the node name is node0, node1......"""
- try:
- node_list = os.listdir(self.sysfs)
- except Exception as e:
- raise e
- ret = []
- partten = re.compile("^node[0-9]{,}$")
- for node in node_list:
- if partten.match(node) is None:
- continue
- ret.append(node)
- return ret
-
-
-class Equalizer(Resource):
-
- def __init__(self):
- super(Equalizer, self).__init__()
-
- def topology(self):
- print self.mapping
-
-
-e = Equalizer()
-e.topology()
diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/get_info.py b/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/get_info.py
deleted file mode 100644
index 8a01dfc6..00000000
--- a/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/get_info.py
+++ /dev/null
@@ -1,179 +0,0 @@
-##############################################################################
-# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import commands
-
-try:
- import xml.etree.cElementTree as ET
-except ImportError:
- import xml.etree.ElementTree as ET
-
-
-class GetPhyInfo(object):
-
- def __init__(self):
- pass
-
- def _get_range(self, temp):
- topo = {}
- phy_core_flag = True
- for sub in temp.split(','):
- r_list = []
- _start = sub.split('-')[0]
- _end = sub.split('-')[1]
- r_list.extend(range(int(_start), int(_end) + 1))
- if phy_core_flag:
- topo['phy_cores'] = r_list
- else:
- topo['virt_cores'] = r_list
- phy_core_flag = False
- return topo
-
- def _get_numa_num(self):
- flag, num = commands.getstatusoutput('lscpu | grep "NUMA node(s):"')
- try:
- num = num.split(':')[1]
- except:
- print('get numa %s value failed.' % (num))
- return num
-
- def get_numa_core(self):
- numa = {}
- num = self._get_numa_num()
- for numa_id in range(0, int(num)):
- flag, temp = commands.getstatusoutput(
- 'lscpu | grep "NUMA node%s"' %
- (str(numa_id)))
- try:
- temp = temp.split(':')[1].split()[0]
- except:
- print('get numa %s range %s failed.' % (str(numa_id), range))
- topo = self._get_range(temp)
- numa['node' + str(numa_id)] = topo
- return str(numa)
-
- def get_nic_numa(self, nic):
- result = {}
- try:
- flag, id = commands.getstatusoutput(
- 'cat /sys/class/net/%s/device/numa_node' %
- (nic))
- except:
- print('get nic numa id failed.')
- return id
-
- def _get_main_pid(self, xml_file):
- try:
- tree = ET.ElementTree(file=xml_file)
- root = tree.getroot()
- _main_pid = root.attrib['pid']
- except:
- print('[ERROR]Parse xml file failed, could not get qemu main pid')
- return _main_pid
-
- def _get_qemu_threads(self, xml_file):
- # import pdb
- # pdb.set_trace()
- _qemu_threads = []
- try:
- tree = ET.ElementTree(file=xml_file)
- root = tree.getroot()
- for element in tree.iterfind('vcpus/vcpu'):
- _qemu_threads.append(element.attrib['pid'])
- except:
- print('[ERROR]Parse xml file failed, could not get qemu threads.')
-
- return _qemu_threads
-
- def _get_mem_numa(self, xml_file):
- try:
- _mem_numa = None
- tree = ET.ElementTree(file=xml_file)
- root = tree.getroot()
- for element in tree.iterfind('domain/numatune/memory'):
- _mem_numa = element.attrib['nodeset']
- finally:
- return _mem_numa
-
- def _get_vhost_threads(self, xml_file):
- _vhost = []
- _main_pid = self._get_main_pid(xml_file)
-
- # get vhost info
- proc_name = 'vhost-' + _main_pid
- flag, temp = commands.getstatusoutput(
- 'ps -ef | grep %s | grep -v grep' %
- (proc_name))
- for line in temp.split('\n'):
- try:
- vhost = line.split()[1]
- _vhost.append(vhost)
- except:
- print('get vhost %s proc id failed' % (line))
-
- return _vhost
-
- def get_vm_info(self, vm_name):
- vm = {}
- src_path = '/var/run/libvirt/qemu/'
- xml_file = src_path + vm_name + '.xml'
-
- # get vm main pid from file
- _main_pid = self._get_main_pid(xml_file)
- # get vm vcpu thread from the libvirt file
- _qemu_threads = self._get_qemu_threads(xml_file)
- # get vm bind mem numa id
- _mem_numa = self._get_mem_numa(xml_file)
- # get vhost thread
- _vhosts = self._get_vhost_threads(xml_file)
-
- vm['main_pid'] = _main_pid
- vm['qemu_thread'] = _qemu_threads
- vm['mem_numa'] = _mem_numa
- vm['vhost_thread'] = _vhosts
- return vm
-
- def _get_proc_by_irq(self, irq):
- try:
- flag, info = commands.getstatusoutput(
- 'ps -ef | grep irq/%s | grep -v grep ' % (irq))
- proc_id = info.split('\n')[0].split()[1]
- except:
- print("[ERROR]grep process id failed.")
- return proc_id
-
- def get_nic_interrupt_proc(self, nic):
- _phy_nic_thread = []
- flag, info = commands.getstatusoutput(
- 'cat /proc/interrupts | grep %s' % (nic))
- for line in info.split('\n'):
- try:
- irq_num = line.split(':')[0].split()[0]
- proc_id = self._get_proc_by_irq(irq_num)
- _phy_nic_thread.append([irq_num, proc_id])
- except:
- print("[ERROR]get irq num failed.")
- return _phy_nic_thread
-
- def get_libvirt_vms(self):
- vm_list = []
- flag, info = commands.getstatusoutput('virsh list')
- list = info.split('\n')
- if list[-1] == '':
- list.pop()
- del list[0]
- del list[0]
-
- for line in list:
- try:
- vm_temp = line.split()[1]
- vm_list.append(vm_temp)
- except:
- print("Get vm name failed from %s" % (line))
- return vm_list
diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/optimize.py b/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/optimize.py
deleted file mode 100644
index 4579c506..00000000
--- a/testsuites/vstf/vstf_scripts/vstf/agent/equalizer/optimize.py
+++ /dev/null
@@ -1,69 +0,0 @@
-##############################################################################
-# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import commands
-import re
-
-
-# import pdb
-# pdb.set_trace()
-
-class Optimize(object):
-
- def __init__(self):
- pass
-
- def bind_cpu(self, cpu_range, thread):
- flag, num = commands.getstatusoutput(
- 'taskset -pc %s %s' %
- (cpu_range, thread))
- return flag
-
- def catch_thread_info(self):
- thread_info = {
- 'fwd_vhost': None,
- 'src_recv_irq': None,
- 'dst_send_irq': None}
- # top -H get the usage info
- flag, threads_usages = commands.getstatusoutput(
- 'top -bH -n1 -c -w 2000')
- line_array = threads_usages.split('\n')
- # get highest vhost line
- for line in line_array:
- if re.search('vhost-', line) and self._check_thread_usage(line):
- thread_info['fwd_vhost'] = line.split()[0]
- break
- # get highest irq thread as src_recv_irq thread
- for line in line_array:
- if re.search('irq/', line) and self._check_thread_usage(line):
- thread_info['src_recv_irq'] = line.split()[0]
- line_array.remove(line)
- break
- # get the second highest irq thread as dst_send_irq
- for line in line_array:
- if re.search('irq/', line) and self._check_thread_usage(line):
- thread_info['dst_send_irq'] = line.split()[0]
- break
- # check the data valid
-
- for key in thread_info.keys():
- if thread_info[key] is None:
- return False, str(thread_info)
- return True, str(thread_info)
-
- def _check_thread_usage(self, line):
- try:
- usage = line.split()[8]
- if float(usage) >= 3.0:
- return True
- else:
- print("[ERROR]The highest thread %s is less than 0.05" % usage)
- return False
- except:
- print("[ERROR]The thread usage get failed.")