Build upon the nice work of Alfred and add sorting capabilities to
the -m "io" mode of top. Approved by: alfred
This commit is contained in:
parent
72767e9575
commit
26b2243ae7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=131829
@ -76,8 +76,12 @@ I - same as 'i'\n\
|
||||
k - kill processes; send a signal to a list of processes\n\
|
||||
n or # - change number of processes to display\n", stdout);
|
||||
#ifdef ORDER
|
||||
fputs("\
|
||||
if (displaymode == DISP_CPU)
|
||||
fputs("\
|
||||
o - specify sort order (pri, size, res, cpu, time)\n", stdout);
|
||||
else
|
||||
fputs("\
|
||||
o - specify sort order (read, write, fault, total)\n", stdout);
|
||||
#endif
|
||||
fputs("\
|
||||
r - renice a process\n\
|
||||
|
@ -96,10 +96,11 @@ char *renice_procs();
|
||||
|
||||
#ifdef ORDER
|
||||
extern int (*proc_compares[])();
|
||||
extern int (*io_compares[])();
|
||||
#else
|
||||
extern int proc_compare();
|
||||
#endif
|
||||
extern int io_compare();
|
||||
#endif
|
||||
time_t time();
|
||||
|
||||
caddr_t get_process_info();
|
||||
@ -567,15 +568,17 @@ Usage: %s [-HISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
|
||||
/* get the current stats */
|
||||
get_system_info(&system_info);
|
||||
|
||||
if (displaymode == DISP_CPU) {
|
||||
#ifdef ORDER
|
||||
if (displaymode == DISP_CPU)
|
||||
compare = proc_compares[order_index];
|
||||
else
|
||||
compare = io_compares[order_index];
|
||||
#else
|
||||
if (displaymode == DISP_CPU)
|
||||
compare = proc_compare;
|
||||
#endif
|
||||
} else {
|
||||
else
|
||||
compare = io_compare;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* get the current set of processes */
|
||||
processes =
|
||||
|
@ -205,10 +205,16 @@ static int pageshift; /* log base 2 of the pagesize */
|
||||
long percentages();
|
||||
|
||||
#ifdef ORDER
|
||||
/* sorting orders. first is default */
|
||||
char *ordernames[] = {
|
||||
/*
|
||||
* Sorting orders. One vector per display mode.
|
||||
* The first element is the default for each mode.
|
||||
*/
|
||||
char *proc_ordernames[] = {
|
||||
"cpu", "size", "res", "time", "pri", NULL
|
||||
};
|
||||
char *io_ordernames[] = {
|
||||
"total", "read", "write", "fault", NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
int
|
||||
@ -265,7 +271,15 @@ machine_init(struct statics *statics)
|
||||
statics->memory_names = memorynames;
|
||||
statics->swap_names = swapnames;
|
||||
#ifdef ORDER
|
||||
statics->order_names = ordernames;
|
||||
switch (displaymode) {
|
||||
case DISP_IO:
|
||||
statics->order_names = io_ordernames;
|
||||
break;
|
||||
case DISP_CPU:
|
||||
default:
|
||||
statics->order_names = proc_ordernames;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* all done! */
|
||||
@ -917,14 +931,74 @@ compare_prio(void *arg1, void *arg2)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* compare_io - the comparison function for sorting by total io */
|
||||
|
||||
int
|
||||
#ifdef ORDER
|
||||
compare_iototal(void *arg1, void *arg2)
|
||||
#else
|
||||
io_compare(void *arg1, void *arg2)
|
||||
#endif
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
|
||||
return (get_io_total(p2) - get_io_total(p1));
|
||||
}
|
||||
|
||||
#ifdef ORDER
|
||||
/* io compare routines */
|
||||
int compare_ioread(), compare_iowrite(), compare_iofault();
|
||||
|
||||
int (*io_compares[])() = {
|
||||
compare_iototal,
|
||||
compare_ioread,
|
||||
compare_iowrite,
|
||||
compare_iofault,
|
||||
NULL
|
||||
};
|
||||
|
||||
int
|
||||
compare_ioread(void *arg1, void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
long dummy, inp1, inp2;
|
||||
|
||||
(void) get_io_stats(p1, &inp1, &dummy, &dummy);
|
||||
(void) get_io_stats(p2, &inp2, &dummy, &dummy);
|
||||
|
||||
return (inp2 - inp1);
|
||||
}
|
||||
|
||||
int
|
||||
compare_iowrite(void *arg1, void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
long dummy, oup1, oup2;
|
||||
|
||||
(void) get_io_stats(p1, &dummy, &oup1, &dummy);
|
||||
(void) get_io_stats(p2, &dummy, &oup2, &dummy);
|
||||
|
||||
return (oup2 - oup1);
|
||||
}
|
||||
|
||||
int
|
||||
compare_iofault(void *arg1, void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
long dummy, flp1, flp2;
|
||||
|
||||
(void) get_io_stats(p1, &dummy, &dummy, &flp1);
|
||||
(void) get_io_stats(p2, &dummy, &dummy, &flp2);
|
||||
|
||||
return (flp2 - flp1);
|
||||
}
|
||||
|
||||
#endif /* ORDER */
|
||||
|
||||
/*
|
||||
* proc_owner(pid) - returns the uid that owns process "pid", or -1 if
|
||||
* the process does not exist.
|
||||
|
Loading…
Reference in New Issue
Block a user