Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / agent / perf / utils.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10 import logging
11 import subprocess
12 from vstf.common.utils import check_call, check_output
13
14 LOG = logging.getLogger(__name__)
15
16
17 def get_pid_by_name(process_name):
18     out = check_output(['ps', '-A'])
19     pids = []
20     for line in out.splitlines():
21         values = line.split()
22         pid, name = values[0], values[3]
23         if process_name == name:
24             pids.append(int(pid))
25     return pids
26
27
28 def get_cpu_num():
29     cpu_num = check_output(
30         'cat /proc/cpuinfo  | grep processor | wc -l',
31         shell=True).strip()
32     cpu_num = int(cpu_num)
33     return cpu_num
34
35
36 def get_default_threads():
37     cpu_num = get_cpu_num()
38     return 2 if cpu_num > 3 * 3 else 1
39
40
41 def modprobe_pktgen():
42     check_call('modprobe pktgen', shell=True)
43     return True
44
45
46 def iface_up(device):
47     check_call("ifconfig %s up" % device, shell=True)
48     return True