1
0
Fork 0

functions: added cpulist_pack

Packs CPU list, i.e. 1, 2, 3 will be converted to 1-3. The cpulist_unpack is
used as a preprocessor, so it always returns optimal results. For details
about input syntax see cpulist_unpack.

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2016-06-16 16:54:58 +02:00
parent 099ae05b74
commit 7ab7be15d0
2 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,21 @@
import os
import tuned.logs
import base
from tuned.utils.commands import commands
log = tuned.logs.get()
class cpulist_pack(base.Function):
"""
Conversion function: packs CPU list in form 1,2,3,5 to 1-3,5.
The cpulist_unpack is used as a preprocessor, so it always returns
optimal results. For details about input syntax see cpulist_unpack.
"""
def __init__(self):
# arbitrary number of arguments
super(self.__class__, self).__init__("cpulist_pack", 0)
def execute(self, args):
if not super(self.__class__, self).execute(args):
return None
return ",".join(str(v) for v in self._cmd.cpulist_pack(",,".join(args)))

View file

@ -211,6 +211,30 @@ class commands:
return []
return sorted(list(set(rl)))
# Packs CPU list, i.e. 1, 2, 3 will be converted to 1-3. It unpacks the
# CPU list through cpulist_unpack first, so see its description about the
# details of the input syntax
def cpulist_pack(self, l):
if l is None or len(l) == 0:
return l
l = self.cpulist_unpack(l)
i = 0
j = i
rl = []
while i + 1 < len(l):
if l[i + 1] - l[i] != 1:
if j != i:
rl.append(str(l[j]) + "-" + str(l[i]))
else:
rl.append(str(l[i]))
j = i + 1
i += 1
if j + 1 < len(l):
rl.append(str(l[j]) + "-" + str(l[-1]))
else:
rl.append(str(l[-1]))
return rl
# Inverts CPU list (i.e. makes its complement)
def cpulist_invert(self, l):
cpus = self.cpulist_unpack(l)