9 class Optimize(object):
13 def bind_cpu(self, cpu_range, thread):
14 flag, num = commands.getstatusoutput('taskset -pc %s %s' % (cpu_range, thread))
17 def catch_thread_info(self):
18 thread_info = {'fwd_vhost': None, 'src_recv_irq': None, 'dst_send_irq': None}
19 # top -H get the usage info
20 flag, threads_usages = commands.getstatusoutput('top -bH -n1 -c -w 2000')
21 line_array = threads_usages.split('\n')
22 # get highest vhost line
23 for line in line_array:
24 if re.search('vhost-', line) and self._check_thread_usage(line):
25 thread_info['fwd_vhost'] = line.split()[0]
27 # get highest irq thread as src_recv_irq thread
28 for line in line_array:
29 if re.search('irq/', line) and self._check_thread_usage(line):
30 thread_info['src_recv_irq'] = line.split()[0]
31 line_array.remove(line)
33 # get the second highest irq thread as dst_send_irq
34 for line in line_array:
35 if re.search('irq/', line) and self._check_thread_usage(line):
36 thread_info['dst_send_irq'] = line.split()[0]
38 # check the data valid
40 for key in thread_info.keys():
41 if thread_info[key] is None:
42 return False, str(thread_info)
43 return True, str(thread_info)
45 def _check_thread_usage(self, line):
47 usage = line.split()[8]
48 if float(usage) >= 3.0:
51 print("[ERROR]The highest thread %s is less than 0.05" % usage)
54 print("[ERROR]The thread usage get failed.")