1fb4b92c01f4cbc3268fc24507b8b1dfa7d1c6b9
[bottlenecks.git] / vstf / vstf / agent / perf / utils.py
1 """
2 Created on 2015-8-6
3
4 @author: y00228926
5 """
6 import logging
7 import subprocess
8 from vstf.common.utils import check_call, check_output
9
10 LOG = logging.getLogger(__name__)
11
12
13 def get_pid_by_name(process_name):
14     out = check_output(['ps', '-A'])
15     pids = []
16     for line in out.splitlines():
17         values = line.split()
18         pid, name = values[0], values[3]
19         if process_name == name:
20             pids.append(int(pid))
21     return pids
22
23
24 def get_cpu_num():
25     cpu_num = check_output('cat /proc/cpuinfo  | grep processor | wc -l', shell=True).strip()
26     cpu_num = int(cpu_num)
27     return cpu_num
28
29
30 def get_default_threads():
31     cpu_num = get_cpu_num()
32     return 2 if cpu_num > 3 * 3 else 1
33
34
35 def modprobe_pktgen():
36     check_call('modprobe pktgen', shell=True)
37     return True
38
39
40 def iface_up(device):
41     check_call("ifconfig %s up" % device, shell=True)
42     return True