From: Satheesh Rajendran <[email protected]> This function would provide a support for resolving a cgroup path for a specific controller and a given task id.
Signed-off-by: Satheesh Rajendran <[email protected]> --- client/base_utils.py | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diff --git a/client/base_utils.py b/client/base_utils.py index 5e45efd..8485142 100644 --- a/client/base_utils.py +++ b/client/base_utils.py @@ -825,3 +825,39 @@ def suspend_to_disk(): Suspend the system to disk (S4) """ set_power_state('disk') + + +def resolve_task_cgroup_path(pid, controller): + """ + Resolving cgroup mount path of a particular task + + @params: pid : process id of a task for which the cgroup path required + @params: controller: takes one of the controller names in controller list + + @return: resolved path for cgroup controllers of a given pid + """ + + # Initialise cgroup controller list + controller_list = [ 'cpuacct', 'cpu', 'memory', 'cpuset', + 'devices', 'freezer', 'blkio', 'netcls' ] + + if controller not in controller_list: + raise error.TestError("Doesn't support controller <%s>" % controller) + + root_path = get_cgroup_mountpoint(controller) + + proc_cgroup = "/proc/%d/cgroup" % pid + if not os.path.isfile(proc_cgroup): + raise NameError('File %s does not exist\n Check whether cgroup \ + installed in the system' % proc_cgroup) + + f = open(proc_cgroup, 'r') + proc_cgroup_txt = f.read() + f.close + + mount_path = re.findall(r":%s:(\S*)\n" % controller, proc_cgroup_txt) + logging.info(mount_path[0]) + + path = root_path + mount_path[0] + logging.info(path) + return path -- 1.7.1 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
