summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/top/commands.c6
-rw-r--r--contrib/top/top.c13
-rw-r--r--usr.bin/top/machine.c80
3 files changed, 90 insertions, 9 deletions
diff --git a/contrib/top/commands.c b/contrib/top/commands.c
index 418dc16..acb8577 100644
--- a/contrib/top/commands.c
+++ b/contrib/top/commands.c
@@ -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\
diff --git a/contrib/top/top.c b/contrib/top/top.c
index 04a8775..9508e47 100644
--- a/contrib/top/top.c
+++ b/contrib/top/top.c
@@ -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 @@ restart:
/* 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 =
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 063fa38..7db6fa8 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -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.
OpenPOWER on IntegriCloud