cgroups: add support list tasks in a specified CGroup
Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com>
diff --git a/devlib/bin/scripts/shutils.in b/devlib/bin/scripts/shutils.in
index 849f6b4..f961aed 100755
--- a/devlib/bin/scripts/shutils.in
+++ b/devlib/bin/scripts/shutils.in
@@ -152,6 +152,17 @@
done
}
+cgroups_tasks_in() {
+ GRP=${1}
+ for TID in $($CAT $GRP/tasks); do
+ COMM=`$CAT /proc/$TID/comm 2>/dev/null`
+ [ "$COMM" != "" ] && CMDL=`$CAT /proc/$TID/cmdline 2>/dev/null`
+ [ "$COMM" != "" ] && echo "$TID,$COMM,$CMDL"
+ done
+ exit 0
+}
+
+
################################################################################
# Main Function Dispatcher
################################################################################
@@ -181,6 +192,9 @@
cgroups_tasks_move)
cgroups_tasks_move $*
;;
+cgroups_tasks_in)
+ cgroups_tasks_in $*
+ ;;
ftrace_get_function_stats)
ftrace_get_function_stats
;;
diff --git a/devlib/module/cgroups.py b/devlib/module/cgroups.py
index c754914..5fd00ce 100644
--- a/devlib/module/cgroups.py
+++ b/devlib/module/cgroups.py
@@ -136,6 +136,28 @@
if cgroup != dest:
self.move_tasks(cgroup, dest)
+ def tasks(self, cgroup):
+ try:
+ cg = self._cgroups[cgroup]
+ except KeyError as e:
+ raise ValueError('Unkown group: {}'.format(e))
+ output = self.target._execute_util(
+ 'cgroups_tasks_in {}'.format(cg.directory),
+ as_root=True)
+ entries = output.splitlines()
+ tasks = {}
+ for task in entries:
+ tid = task.split(',')[0]
+ try:
+ tname = task.split(',')[1]
+ except: continue
+ try:
+ tcmdline = task.split(',')[2]
+ except:
+ tcmdline = ''
+ tasks[int(tid)] = (tname, tcmdline)
+ return tasks
+
class CGroup(object):
def __init__(self, controller, name, create=True):