Update top(1) for new UVM/UBC counters.

bin/16020, Tomas Svensson <tsn@gbdev.net>
This commit is contained in:
thorpej 2002-03-23 01:28:10 +00:00
parent 714618fb98
commit b9145634cd
7 changed files with 91 additions and 21 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: display.c,v 1.5 2001/06/19 13:42:22 wiz Exp $ */
/* $NetBSD: display.c,v 1.6 2002/03/23 01:28:10 thorpej Exp $ */
/*
* Top users/processes display for Unix
@ -68,14 +68,17 @@ char *screenbuf = NULL;
static char **procstate_names;
static char **cpustate_names;
static char **memory_names;
static char **swap_names;
static int num_procstates;
static int num_cpustates;
static int num_memory;
static int num_swap;
static int *lprocstates;
static int *lcpustates;
static int *lmemory;
static int *lswap;
static int *cpustate_columns;
static int cpustate_total_length;
@ -153,6 +156,10 @@ struct statics *statics;
num_memory = string_count(memory_names);
lmemory = (int *)malloc(num_memory * sizeof(int));
swap_names = statics->swap_names;
num_swap = string_count(swap_names);
lswap = (int *)malloc(num_swap * sizeof(int));
/* calculate starting columns where needed */
cpustate_total_length = 0;
pp = cpustate_names;
@ -546,6 +553,42 @@ int *stats;
line_update(memory_buffer, new, x_mem, y_mem);
}
/*
* *_swap(stats) - print "Swap: " followed by the memory summary string
*
* Assumptions: cursor is on "lastline"
* for i_memory ONLY: cursor is on the previous line
*/
char swap_buffer[MAX_COLS];
void
i_swap(stats)
int *stats;
{
fputs("\nSwap: ", stdout);
lastline++;
/* format and print the swap summary */
summary_format(swap_buffer, stats, swap_names);
fputs(swap_buffer, stdout);
}
void
u_swap(stats)
int *stats;
{
static char new[MAX_COLS];
/* format the new line */
summary_format(new, stats, swap_names);
line_update(swap_buffer, new, x_swap, y_swap);
}
/*
* *_message() - print the next pending message line, or erase the one
* that is there.

View File

@ -1,4 +1,4 @@
/* $NetBSD: display.h,v 1.4 2000/10/11 14:46:19 is Exp $ */
/* $NetBSD: display.h,v 1.5 2002/03/23 01:28:10 thorpej Exp $ */
/* constants needed for display.c */
@ -21,6 +21,8 @@ void u_cpustates __P((int *));
void z_cpustates __P((void));
void i_memory __P((int *));
void u_memory __P((int *));
void i_swap __P((int *));
void u_swap __P((int *));
void i_message __P((void));
void u_message __P((void));
void i_header __P((char *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: layout.h,v 1.2 1999/04/12 06:02:26 ross Exp $ */
/* $NetBSD: layout.h,v 1.3 2002/03/23 01:28:10 thorpej Exp $ */
/*
* Top - a top users display for Berkeley Unix
@ -19,11 +19,13 @@
#define y_brkdn 1
#define x_mem 8
#define y_mem 3
#define y_message 4
#define x_swap 6
#define y_swap 4
#define y_message 5
#define x_header 0
#define y_header 5
#define y_header 6
#define x_idlecursor 0
#define y_idlecursor 4
#define y_procs 6
#define y_idlecursor 5
#define y_procs 7
#define y_cpustates 2

View File

@ -1,4 +1,4 @@
/* $NetBSD: machine.h,v 1.5 2001/05/22 15:38:22 christos Exp $ */
/* $NetBSD: machine.h,v 1.6 2002/03/23 01:28:10 thorpej Exp $ */
/*
* This file defines the interface between top and the machine-dependent
@ -14,6 +14,7 @@ struct statics
char **procstate_names;
char **cpustate_names;
char **memory_names;
char **swap_names;
#ifdef ORDER
char **order_names;
#endif
@ -38,6 +39,7 @@ struct system_info
int *procstates;
int *cpustates;
int *memory;
int *swap;
};
/* cpu_states is an array of percentages * 10. For example,

View File

@ -1,4 +1,4 @@
/* $NetBSD: m_netbsd15.c,v 1.15 2001/07/03 01:36:07 christos Exp $ */
/* $NetBSD: m_netbsd15.c,v 1.16 2002/03/23 01:28:11 thorpej Exp $ */
/*
* top - a top users display for Unix
@ -12,12 +12,13 @@
* NetBSD-1.3 port by Luke Mewburn, based on code by Matthew Green.
* NetBSD-1.4/UVM port by matthew green.
* NetBSD-1.5 port by Simon Burge.
* NetBSD-1.6/UBC port by Tomas Svensson.
* -
* This is the machine-dependent module for NetBSD-1.5 and later
* works for:
* NetBSD-1.4Z
* NetBSD-1.5ZC
* and should work for:
* NetBSD-1.5 (when released)
* NetBSD-1.6 (when released)
* -
* top does not need to be installed setuid or setgid with this module.
*
@ -32,9 +33,10 @@
* Luke Mewburn <lukem@netbsd.org>
* matthew green <mrg@eterna.com.au>
* Simon Burge <simonb@netbsd.org>
* Tomas Svensson <ts@unix1.net>
*
*
* $Id: m_netbsd15.c,v 1.15 2001/07/03 01:36:07 christos Exp $
* $Id: m_netbsd15.c,v 1.16 2002/03/23 01:28:11 thorpej Exp $
*/
#include <sys/param.h>
@ -135,8 +137,14 @@ char *cpustatenames[] = {
int memory_stats[7];
char *memorynames[] = {
"K Act, ", "K Inact, ", "K Wired, ", "K Free, ",
"K Swp, ", "K Swp free, ",
"K Act, ", "K Inact, ", "K Wired, ", "K Exec, ", "K File, ",
"K Free, ",
NULL
};
int swap_stats[4];
char *swapnames[] = {
"K Total, ", "K Used, ", "K Free, ",
NULL
};
@ -240,6 +248,7 @@ machine_init(statics)
statics->procstate_names = procstatenames;
statics->cpustate_names = cpustatenames;
statics->memory_names = memorynames;
statics->swap_names = swapnames;
statics->order_names = ordernames;
/* all done! */
@ -305,8 +314,11 @@ get_system_info(si)
memory_stats[0] = pagetok(uvmexp.active);
memory_stats[1] = pagetok(uvmexp.inactive);
memory_stats[2] = pagetok(uvmexp.wired);
memory_stats[3] = pagetok(uvmexp.free);
memory_stats[4] = memory_stats[5] = 0;
memory_stats[3] = pagetok(uvmexp.execpages);
memory_stats[4] = pagetok(uvmexp.filepages);
memory_stats[5] = pagetok(uvmexp.free);
swap_stats[0] = swap_stats[1] = swap_stats[2] = 0;
seporig = NULL;
do {
@ -332,8 +344,9 @@ get_system_info(si)
totalsize += size;
totalinuse += inuse;
}
memory_stats[4] = dbtob(totalinuse) / 1024;
memory_stats[5] = dbtob(totalsize) / 1024 - memory_stats[4];
swap_stats[0] = dbtob(totalsize) / 1024;
swap_stats[1] = dbtob(totalinuse) / 1024;
swap_stats[2] = dbtob(totalsize) / 1024 - swap_stats[1];
/* Free here, before we malloc again in the next
* iteration of this loop.
*/
@ -349,10 +362,12 @@ get_system_info(si)
free(seporig);
memory_stats[6] = -1;
swap_stats[3] = -1;
/* set arrays and strings */
si->cpustates = cpu_states;
si->memory = memory_stats;
si->swap = swap_stats;
si->last_pid = -1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: top.c,v 1.10 2001/06/21 21:27:51 wiz Exp $ */
/* $NetBSD: top.c,v 1.11 2002/03/23 01:28:10 thorpej Exp $ */
char *copyright =
"Copyright (c) 1984 through 1996, William LeFebvre";
@ -78,6 +78,7 @@ void (*d_loadave) __P((int, double *)) = i_loadave;
void (*d_procstates) __P((int, int *)) = i_procstates;
void (*d_cpustates) __P((int *)) = i_cpustates;
void (*d_memory) __P((int *)) = i_memory;
void (*d_swap) __P((int *)) = i_swap;
void (*d_message) __P((void)) = i_message;
void (*d_header) __P((char *)) = i_header;
void (*d_process) __P((int, char *)) = i_process;
@ -534,6 +535,9 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n",
/* display memory stats */
(*d_memory)(system_info.memory);
/* display swap stats */
(*d_swap)(system_info.swap);
/* handle message area */
(*d_message)();
@ -594,6 +598,7 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n",
d_procstates = u_procstates;
d_cpustates = u_cpustates;
d_memory = u_memory;
d_swap = u_swap;
d_message = u_message;
d_header = u_header;
d_process = u_process;
@ -903,6 +908,7 @@ reset_display()
d_procstates = i_procstates;
d_cpustates = i_cpustates;
d_memory = i_memory;
d_swap = i_swap;
d_message = i_message;
d_header = i_header;
d_process = i_process;

View File

@ -1,4 +1,4 @@
/* $NetBSD: top.h,v 1.3 1999/04/12 06:02:26 ross Exp $ */
/* $NetBSD: top.h,v 1.4 2002/03/23 01:28:11 thorpej Exp $ */
/*
* Top - a top users display for Berkeley Unix
@ -10,7 +10,7 @@
#define VERSION 3
/* Number of lines of header information on the standard screen */
#define Header_lines 6
#define Header_lines 7
/* Maximum number of columns allowed for display */
#define MAX_COLS 128