[kupfer: 12/24] plugin.top: Fix sorting by memory, use command name



commit f49557785ba646a0c4c0e62278056c44c3a92fe2
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Nov 23 21:27:13 2009 +0100

    plugin.top: Fix sorting by memory, use command name
    
    Read cpu and memory as floats so that they sort as numbers (not "2",
    "32.0", "4.2" but (2, 4.2, 32.0).
    
    Since command lines or command names are cut off when they are too
    long, use only commmand names from top for now (still not optimal).

 kupfer/plugin/top.py |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
---
diff --git a/kupfer/plugin/top.py b/kupfer/plugin/top.py
index 9c01005..7bd4592 100644
--- a/kupfer/plugin/top.py
+++ b/kupfer/plugin/top.py
@@ -109,10 +109,9 @@ class TaskSource(Source, PicklingHelperMixin):
 			processes = sorted(processes, key=operator.itemgetter(4))
 		# default: by cpu
 
+		fields = _("pid: %(pid)s  cpu: %(cpu)g%%  mem: %(mem)g%%  time: %(time)s")
 		for pid, cpu, mem, ptime, cmd in processes:
-			description = (
-					_("pid: %(pid)s  cpu: %(cpu)s%%   mem: %(mem)s   time: %(time)s") \
-					% dict(pid=pid, cpu=cpu, mem=mem, time=ptime))
+			description = fields % dict(pid=pid, cpu=cpu, mem=mem, time=ptime)
 			yield Task(pid, cmd, description)
 
 
@@ -128,7 +127,7 @@ class TaskSource(Source, PicklingHelperMixin):
 
 def get_processes():
 	uid = os.getuid()
-	command = 'top -b -n 1 -u %d -c' % uid
+	command = 'top -b -n 1 -u %d' % uid
 	proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
 	out, _err = proc.communicate()
 
@@ -147,5 +146,5 @@ def get_processes():
 		if pid == 'PID':
 			continue	# skip header
 
-		yield (int(pid), cpu, mem, ptime, cmd)
+		yield (int(pid), float(cpu), float(mem), ptime, cmd)
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]