From: Christian Trautman Date: Thu, 1 Sep 2016 06:44:35 +0000 (-0400) Subject: vhost_affin_fixup: Change vhost thread from regex to pgrep usage X-Git-Tag: danube.1.RC1~95^2 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F07%2F20107%2F1;p=vswitchperf.git vhost_affin_fixup: Change vhost thread from regex to pgrep usage Change vhost affinity process lookup to use pgrep instead of ugly error prone regex method as suggested. Change-Id: I8cac00a7f2d26ba1ce1815535a198f578159222c Signed-off-by: Christian Trautman --- diff --git a/vnfs/qemu/qemu.py b/vnfs/qemu/qemu.py index dd9ad818..2093cb3b 100644 --- a/vnfs/qemu/qemu.py +++ b/vnfs/qemu/qemu.py @@ -247,14 +247,13 @@ class IVnfQemu(IVnf): :return: None """ self._logger.info('Affinitizing VHOST Net threads.') - args1 = ['ps', 'ax'] + args1 = ['pgrep', 'vhost-'] process1 = subprocess.Popen(args1, stdout=subprocess.PIPE, shell=False) out = process1.communicate()[0] - processes = list() - for line in out.decode(locale.getdefaultlocale()[1]).split('\n'): - if re.search('\[vhost-(\d+)', line): - processes.append(re.match('\s*(\d+)', line).group(1)) + processes = out.decode(locale.getdefaultlocale()[1]).split('\n') + if processes[-1] == '': + processes.pop() # pgrep may return an extra line with no data self._logger.info('Found %s vhost net threads...', len(processes)) cpumap = S.getValue('VSWITCH_VHOST_CPU_MAP')