From a65ff136178035bd50bbe6b77381bab06d9aaf48 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Tue, 23 Feb 2016 12:11:06 +0000 Subject: [PATCH 1/2] cgroups: fix attributes reporting for controller with only one attribute The current code used to read the attributes values for a controller uses a "grep '' CONTROLLER.*" under the assumption that the output is a list of file:value However, if there is a single controller attribute, grep does not report the file name in output thus returning an empty list at the python side. This patch fix that issue by also switching to the usage of a shutil implementation of the attributes parsing code. Signed-off-by: Patrick Bellasi --- devlib/bin/scripts/shutils.in | 17 +++++++++++++++++ devlib/module/cgroups.py | 12 ++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/devlib/bin/scripts/shutils.in b/devlib/bin/scripts/shutils.in index 9200b70..bc47719 100755 --- a/devlib/bin/scripts/shutils.in +++ b/devlib/bin/scripts/shutils.in @@ -55,6 +55,20 @@ ftrace_get_function_stats() { done } + +################################################################################ +# CGroups Utility Functions +################################################################################ + +cgroups_get_attributes() { + [[ $# -eq 2 ]] || exit -1 + CGROUP="$1" + CONTROLLER="$2" + $GREP '' $CGROUP/* | \ + $GREP "$CONTROLLER\." | \ + $SED -e "s|$CONTROLLER\.||" -e "s|$CGROUP/||" +} + ################################################################################ # Main Function Dispatcher ################################################################################ @@ -75,6 +89,9 @@ cpufreq_get_all_governors) cpufreq_trace_all_frequencies) cpufreq_trace_all_frequencies $* ;; +cgroups_get_attributes) + cgroups_get_attributes $* + ;; ftrace_get_function_stats) ftrace_get_function_stats ;; diff --git a/devlib/module/cgroups.py b/devlib/module/cgroups.py index c55e135..aa9ff33 100644 --- a/devlib/module/cgroups.py +++ b/devlib/module/cgroups.py @@ -166,14 +166,10 @@ class CGroup(object): self.controller.kind) logging.debug(' %s', self.directory) - output = self.target.execute('{} grep \'\' {}/{}.*'.format( - self.target.busybox, - self.directory, - self.controller.kind)) - for res in output.split('\n'): - if res.find(self.controller.kind) < 0: - continue - res = res.split('.')[1] + output = self.target._execute_util( + 'cgroups_get_attributes {} {}'.format( + self.directory, self.controller.kind)) + for res in output.splitlines(): attr = res.split(':')[0] value = res.split(':')[1] conf[attr] = value From e2e5e687e91c7c9166ff4e9159fb98bf5af5ede3 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Tue, 23 Feb 2016 12:12:28 +0000 Subject: [PATCH 2/2] cgroups: use splitlines instead of split('\n') Signed-off-by: Patrick Bellasi --- devlib/module/cgroups.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devlib/module/cgroups.py b/devlib/module/cgroups.py index aa9ff33..ce10d01 100644 --- a/devlib/module/cgroups.py +++ b/devlib/module/cgroups.py @@ -98,7 +98,7 @@ class Controller(object): output = self.target.execute('{} find {} -type d'\ .format(self.target.busybox, self.mount_point)) cgroups = [] - for cg in output.split('\n'): + for cg in output.splitlines(): cg = cg.replace(self.mount_point + '/', '/') cg = cg.replace(self.mount_point, '/') cg = cg.strip() @@ -257,7 +257,7 @@ class CgroupsModule(Module): def list_subsystems(self): subsystems = [] for line in self.target.execute('{} cat /proc/cgroups'\ - .format(self.target.busybox)).split('\n')[1:]: + .format(self.target.busybox)).splitlines()[1:]: line = line.strip() if not line or line.startswith('#'): continue