1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
17 class Optimize(object):
22 def bind_cpu(self, cpu_range, thread):
23 flag, num = commands.getstatusoutput(
28 def catch_thread_info(self):
33 # top -H get the usage info
34 flag, threads_usages = commands.getstatusoutput(
35 'top -bH -n1 -c -w 2000')
36 line_array = threads_usages.split('\n')
37 # get highest vhost line
38 for line in line_array:
39 if re.search('vhost-', line) and self._check_thread_usage(line):
40 thread_info['fwd_vhost'] = line.split()[0]
42 # get highest irq thread as src_recv_irq thread
43 for line in line_array:
44 if re.search('irq/', line) and self._check_thread_usage(line):
45 thread_info['src_recv_irq'] = line.split()[0]
46 line_array.remove(line)
48 # get the second highest irq thread as dst_send_irq
49 for line in line_array:
50 if re.search('irq/', line) and self._check_thread_usage(line):
51 thread_info['dst_send_irq'] = line.split()[0]
53 # check the data valid
55 for key in thread_info.keys():
56 if thread_info[key] is None:
57 return False, str(thread_info)
58 return True, str(thread_info)
60 def _check_thread_usage(self, line):
62 usage = line.split()[8]
63 if float(usage) >= 3.0:
66 print("[ERROR]The highest thread %s is less than 0.05" % usage)
69 print("[ERROR]The thread usage get failed.")