[kupfer] plugin.top: add finding proper columns in top output - solve LP bug 500395
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] plugin.top: add finding proper columns in top output - solve LP bug 500395
- Date: Sun, 27 Dec 2009 19:45:56 +0000 (UTC)
commit 5e664c17e60de47ca847e45421b4afab8f1618ca
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date: Sat Dec 26 10:39:31 2009 +0100
plugin.top: add finding proper columns in top output - solve LP bug 500395
kupfer/plugin/top.py | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/plugin/top.py b/kupfer/plugin/top.py
index 0a54952..ac000dd 100644
--- a/kupfer/plugin/top.py
+++ b/kupfer/plugin/top.py
@@ -133,6 +133,8 @@ def get_processes():
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
out, _err = proc.communicate()
+ fields_map = None
+ fields_count = 0
header_read = False
for line in out.split('\n'):
line = line.strip()
@@ -143,11 +145,18 @@ def get_processes():
if not header_read:
continue
- (pid, user, pr, ni, virt, res, shr, s, cpu, mem, ptime, cmd) = \
- line.split(None, 11)
- if pid == 'PID':
+ if line.startswith('PID'): # assume pid is first col
+ fields_map = dict(((name, pos) for pos, name in enumerate(line.split())))
+ fields_count = len(fields_map)
continue # skip header
+ line_fields = line.split(None, fields_count-1)
+ pid = line_fields[0]
+ cpu = line_fields[fields_map['%CPU']]
+ mem = line_fields[fields_map['%MEM']]
+ ptime = line_fields[fields_map['TIME+']]
+ cmd = line_fields[-1]
+
# read command line
proc_file = '/proc/%s/cmdline' % pid
if os.path.isfile(proc_file): # also skip (finished) missing tasks
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]