aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-09-14 18:56:52 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-09-14 18:56:52 +0000
commit225be8c1f06397b6f4d378f6eb00b6ddb7cfd024 (patch)
tree310a7d51d819194c26ec974901c14de7694ffcbc
parent73ebb889daf30980bddc3d3065ff10844c4624dc (diff)
downloadbusybox-w32-225be8c1f06397b6f4d378f6eb00b6ddb7cfd024.tar.gz
busybox-w32-225be8c1f06397b6f4d378f6eb00b6ddb7cfd024.tar.bz2
busybox-w32-225be8c1f06397b6f4d378f6eb00b6ddb7cfd024.zip
Apply patch from Felipe Kellermann to simlify logic of sort functions.
I reversed the result of the sort functions to make the big numbers go to the top.
-rw-r--r--procps/top.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/procps/top.c b/procps/top.c
index 2bef38dd4..972c484f4 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -23,6 +23,26 @@
23 * Copyright (c) 1992 Roger Binns 23 * Copyright (c) 1992 Roger Binns
24 * Copyright (C) 1994-1996 Charles L. Blake. 24 * Copyright (C) 1994-1996 Charles L. Blake.
25 * Copyright (C) 1992-1998 Michael K. Johnson 25 * Copyright (C) 1992-1998 Michael K. Johnson
26 * May
27 * This reads the PIDs of all processes and their status and shows
28 * the status of processes (first ones that fit to screen) at given
29 * intervals.
30 *
31 * NOTES:
32 * - At startup this changes to /proc, all the reads are then
33 * relative to that.
34 *
35 * (C) Eero Tamminen <oak at welho dot com>
36 *
37 * Rewritten by Vladimir Oleynik (C) 2002 <dzo@simtreas.ru>
38 */
39
40/* Original code Copyrights */
41/*
42 * Copyright (c) 1992 Branko Lankester
43 * Copyright (c) 1992 Roger Binns
44 * Copyright (C) 1994-1996 Charles L. Blake.
45 * Copyright (C) 1992-1998 Michael K. Johnson
26 * May be distributed under the conditions of the 46 * May be distributed under the conditions of the
27 * GNU Library General Public License 47 * GNU Library General Public License
28 */ 48 */
@@ -55,22 +75,12 @@ static int ntop;
55 75
56static int pid_sort (procps_status_t *P, procps_status_t *Q) 76static int pid_sort (procps_status_t *P, procps_status_t *Q)
57{ 77{
58 int p = P->pid; 78 return (Q->pid - P->pid);
59 int q = Q->pid;
60
61 if( p < q ) return -1;
62 if( p > q ) return 1;
63 return 0;
64} 79}
65 80
66static int mem_sort (procps_status_t *P, procps_status_t *Q) 81static int mem_sort (procps_status_t *P, procps_status_t *Q)
67{ 82{
68 long p = P->rss; 83 return (int)(Q->rss - P->rss);
69 long q = Q->rss;
70
71 if( p > q ) return -1;
72 if( p < q ) return 1;
73 return 0;
74} 84}
75 85
76#ifdef FEATURE_CPU_USAGE_PERCENTAGE 86#ifdef FEATURE_CPU_USAGE_PERCENTAGE
@@ -80,24 +90,12 @@ static cmp_t sort_function[sort_depth];
80 90
81static int pcpu_sort (procps_status_t *P, procps_status_t *Q) 91static int pcpu_sort (procps_status_t *P, procps_status_t *Q)
82{ 92{
83 int p = P->pcpu; 93 return (Q->pcpu - P->pcpu);
84 int q = Q->pcpu;
85
86 if( p > q ) return -1;
87 if( p < q ) return 1;
88 return 0;
89} 94}
90 95
91static int time_sort (procps_status_t *P, procps_status_t *Q) 96static int time_sort (procps_status_t *P, procps_status_t *Q)
92{ 97{
93 long p = P->stime; 98 return (int)((Q->stime + Q->utime) - (P->stime + P->utime));
94 long q = Q->stime;
95
96 p += P->utime;
97 q += Q->utime;
98 if( p > q ) return -1;
99 if( p < q ) return 1;
100 return 0;
101} 99}
102 100
103int mult_lvl_cmp(void* a, void* b) { 101int mult_lvl_cmp(void* a, void* b) {