X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FCpuUtils.py;fp=resources%2Flibraries%2Fpython%2FCpuUtils.py;h=85c2e843e4053c565890bbb865fd37e80d701096;hp=a8698dfd547eae6b5118ab093d274cc268058d7b;hb=72be8262ea5dc0136a21032402b7f4ffa5ff4576;hpb=b2841cae8eb34a0a0c5b26cf344d6a0d39a1af3e diff --git a/resources/libraries/python/CpuUtils.py b/resources/libraries/python/CpuUtils.py index a8698dfd54..85c2e843e4 100644 --- a/resources/libraries/python/CpuUtils.py +++ b/resources/libraries/python/CpuUtils.py @@ -98,3 +98,36 @@ class CpuUtils(object): raise RuntimeError("Node cpuinfo not available.") return cpulist + + @staticmethod + def cpu_list_per_node_str(node, cpu_node, skip_cnt=0, + cpu_cnt=0, sep=","): + """Return string of node related list of CPU numbers. + + :param node: Node dictionary with cpuinfo. + :param cpu_node: Numa node number. + :param skip_cnt: Skip first "skip_cnt" CPUs. + :param cpu_cnt: Count of cpus to return, if 0 then return all. + :param sep: Separator, default: 1,2,3,4,.... + :type node: dict + :type cpu_node: int + :type skip_cnt: int + :type cpu_cnt: int + :type sep: str + :return: Cpu numbers related to numa from argument. + :rtype: str + """ + + cpu_list = CpuUtils.cpu_list_per_node(node, cpu_node) + cpu_list_len = len(cpu_list) + cpu_flist = "" + if cpu_cnt == 0: + cpu_cnt = cpu_list_len - skip_cnt + + if cpu_cnt + skip_cnt > cpu_list_len: + raise RuntimeError("cpu_cnt + skip_cnt > length(cpu list).") + + cpu_flist = sep.join(str(a) for a in + cpu_list[skip_cnt:skip_cnt+cpu_cnt]) + + return cpu_flist