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.
This commit is contained in:
parent
73ebb889da
commit
225be8c1f0
50
procps/top.c
50
procps/top.c
@ -17,6 +17,26 @@
|
|||||||
* Rewritten by Vladimir Oleynik (C) 2002 <dzo@simtreas.ru>
|
* Rewritten by Vladimir Oleynik (C) 2002 <dzo@simtreas.ru>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Original code Copyrights */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1992 Branko Lankester
|
||||||
|
* Copyright (c) 1992 Roger Binns
|
||||||
|
* Copyright (C) 1994-1996 Charles L. Blake.
|
||||||
|
* Copyright (C) 1992-1998 Michael K. Johnson
|
||||||
|
* May
|
||||||
|
* This reads the PIDs of all processes and their status and shows
|
||||||
|
* the status of processes (first ones that fit to screen) at given
|
||||||
|
* intervals.
|
||||||
|
*
|
||||||
|
* NOTES:
|
||||||
|
* - At startup this changes to /proc, all the reads are then
|
||||||
|
* relative to that.
|
||||||
|
*
|
||||||
|
* (C) Eero Tamminen <oak at welho dot com>
|
||||||
|
*
|
||||||
|
* Rewritten by Vladimir Oleynik (C) 2002 <dzo@simtreas.ru>
|
||||||
|
*/
|
||||||
|
|
||||||
/* Original code Copyrights */
|
/* Original code Copyrights */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1992 Branko Lankester
|
* Copyright (c) 1992 Branko Lankester
|
||||||
@ -55,22 +75,12 @@ static int ntop;
|
|||||||
|
|
||||||
static int pid_sort (procps_status_t *P, procps_status_t *Q)
|
static int pid_sort (procps_status_t *P, procps_status_t *Q)
|
||||||
{
|
{
|
||||||
int p = P->pid;
|
return (Q->pid - P->pid);
|
||||||
int q = Q->pid;
|
|
||||||
|
|
||||||
if( p < q ) return -1;
|
|
||||||
if( p > q ) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mem_sort (procps_status_t *P, procps_status_t *Q)
|
static int mem_sort (procps_status_t *P, procps_status_t *Q)
|
||||||
{
|
{
|
||||||
long p = P->rss;
|
return (int)(Q->rss - P->rss);
|
||||||
long q = Q->rss;
|
|
||||||
|
|
||||||
if( p > q ) return -1;
|
|
||||||
if( p < q ) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
|
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
|
||||||
@ -80,24 +90,12 @@ static cmp_t sort_function[sort_depth];
|
|||||||
|
|
||||||
static int pcpu_sort (procps_status_t *P, procps_status_t *Q)
|
static int pcpu_sort (procps_status_t *P, procps_status_t *Q)
|
||||||
{
|
{
|
||||||
int p = P->pcpu;
|
return (Q->pcpu - P->pcpu);
|
||||||
int q = Q->pcpu;
|
|
||||||
|
|
||||||
if( p > q ) return -1;
|
|
||||||
if( p < q ) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int time_sort (procps_status_t *P, procps_status_t *Q)
|
static int time_sort (procps_status_t *P, procps_status_t *Q)
|
||||||
{
|
{
|
||||||
long p = P->stime;
|
return (int)((Q->stime + Q->utime) - (P->stime + P->utime));
|
||||||
long q = Q->stime;
|
|
||||||
|
|
||||||
p += P->utime;
|
|
||||||
q += Q->utime;
|
|
||||||
if( p > q ) return -1;
|
|
||||||
if( p < q ) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mult_lvl_cmp(void* a, void* b) {
|
int mult_lvl_cmp(void* a, void* b) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user