From c1bc25756337bd6477744fcdce97096b46f47607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Mon, 28 May 2018 15:37:44 +0200 Subject: [PATCH] scheduler: Replace get_process with _get_cmdline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_scheduler.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tuned/plugins/plugin_scheduler.py b/tuned/plugins/plugin_scheduler.py index 3c11e97..32612f9 100644 --- a/tuned/plugins/plugin_scheduler.py +++ b/tuned/plugins/plugin_scheduler.py @@ -106,17 +106,6 @@ class SchedulerPlugin(base.Plugin): "ps_blacklist": None, } - def get_process(self, pid): - cmd = self._cmd.read_file("/proc/" + str(pid) + "/comm", no_error = True) - if cmd == "": - return "" - cmd = cmd.strip() - cmdline = self._cmd.read_file("/proc/" + str(pid) + "/cmdline", no_error = True) - if cmdline == "": - return "[" + cmd + "]" - else: - return cmdline.replace("\0", " ").strip() - # Raises OSError, IOError def _get_cmdline(self, process): if not isinstance(process, procfs.process): @@ -414,9 +403,16 @@ class SchedulerPlugin(base.Plugin): self._restore_ps_affinity() def _add_pid(self, instance, pid, r): - cmd = self.get_process(pid) - # check to filter short living process - if cmd == "": + try: + cmd = self._get_cmdline(pid) + except (OSError, IOError) as e: + if e.errno == errno.ENOENT \ + or e.errno == errno.ESRCH: + log.debug("Failed to get cmdline of PID %d, the task vanished." + % pid) + else: + log.error("Failed to get cmdline of PID %d: %s" + % (pid, e)) return v = self._cmd.re_lookup(instance._sched_lookup, cmd, r) if v is not None and not pid in self._scheduler_original: