Make 'sysctl vm.vmtotal' work properly using updated patch from Hiten.

(the patch in the PR was stale).

PR:             kern/5689
Submitted by:   Hiten Pandya <hiten@unixdaemons.com>
This commit is contained in:
Matthew Dillon 2003-01-11 07:29:47 +00:00
parent 42cf585a69
commit f7550ecf3f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109097
5 changed files with 31 additions and 5 deletions

View File

@ -54,6 +54,7 @@ static const char rcsid[] =
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/vmmeter.h>
#include <ctype.h>
#include <err.h>
@ -322,6 +323,29 @@ S_timeval(int l2, void *p)
return (0);
}
static int
S_vmtotal(int l2, void *p)
{
struct vmtotal *v = (struct vmtotal *)p;
if (l2 != sizeof(*v)) {
warnx("S_vmtotal %d != %d", l2, sizeof(*v));
return (0);
}
printf("\nSystem wide totals computed every five seconds:\n");
printf("===============================================\n");
printf("Processes: (RUNQ:\t %hu Disk Wait: %hu Page Wait: %hu Sleep: %hu)\n",
v->t_rq, v->t_dw, v->t_pw, v->t_sl);
printf("Virtual Memory:\t\t (Total: %hu Active %hu)\n", v->t_vm, v->t_avm);
printf("Real Memory:\t\t (Total: %hu Active %hu)\n", v->t_rm, v->t_arm);
printf("Shared Virtual Memory:\t (Total: %hu Active: %hu)\n", v->t_vmshr, v->t_avmshr);
printf("Shared Real Memory:\t (Total: %hu Active: %hu)\n", v->t_rmshr, v->t_armshr);
printf("Free Memory Pages:\t %hu\n", v->t_free);
return (0);
}
static int
T_dev_t(int l2, void *p)
{
@ -587,6 +611,8 @@ show_var(int *oid, int nlen)
func = S_timeval;
else if (strcmp(fmt, "S,loadavg") == 0)
func = S_loadavg;
else if (strcmp(fmt, "S,vmtotal") == 0)
func = S_vmtotal;
else if (strcmp(fmt, "T,dev_t") == 0)
func = T_dev_t;
else

View File

@ -237,7 +237,7 @@ vcnt(SYSCTL_HANDLER_ARGS)
return(error);
}
SYSCTL_PROC(_vm, VM_METER, vmmeter, CTLTYPE_OPAQUE|CTLFLAG_RD,
SYSCTL_PROC(_vm, VM_TOTAL, vmtotal, CTLTYPE_OPAQUE|CTLFLAG_RD,
0, sizeof(struct vmtotal), vmtotal, "S,vmtotal",
"System virtual memory statistics");
SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats");

View File

@ -76,7 +76,7 @@
/*
* CTL_VM identifiers
*/
#define VM_METER 1 /* struct vmmeter */
#define VM_TOTAL 1 /* struct vmtotal */
#define VM_LOADAVG 2 /* struct loadavg */
#define VM_V_FREE_MIN 3 /* cnt.v_free_min */
#define VM_V_FREE_TARGET 4 /* cnt.v_free_target */
@ -91,7 +91,7 @@
#define CTL_VM_NAMES { \
{ 0, 0 }, \
{ "vmmeter", CTLTYPE_STRUCT }, \
{ "vmtotal", CTLTYPE_STRUCT }, \
{ "loadavg", CTLTYPE_STRUCT }, \
{ "v_free_min", CTLTYPE_INT }, \
{ "v_free_target", CTLTYPE_INT }, \

View File

@ -784,7 +784,7 @@ getinfo(ls)
size = sizeof(ls->Total);
mib[0] = CTL_VM;
mib[1] = VM_METER;
mib[1] = VM_TOTAL;
if (sysctl(mib, 2, &ls->Total, &size, NULL, 0) < 0) {
error("Can't get kernel info: %s\n", strerror(errno));
bzero(&ls->Total, sizeof(ls->Total));

View File

@ -472,7 +472,7 @@ dovmstat(interval, reps)
kread(X_SUM, &sum, sizeof(sum));
size = sizeof(total);
mib[0] = CTL_VM;
mib[1] = VM_METER;
mib[1] = VM_TOTAL;
if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
(void)printf("Can't get kerninfo: %s\n",
strerror(errno));