Merged some stuff from `stub_suid'.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
@@ -19,84 +19,28 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/cpu.h>
|
||||
|
||||
#include <nlist.h>
|
||||
#include <kvm.h>
|
||||
#include <sys/dkstat.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu =
|
||||
(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) +
|
||||
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
|
||||
(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
|
||||
static const unsigned long _glibtop_sysdeps_cpu = 0;
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_cpu_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||
}
|
||||
|
||||
/* Provides information about cpu usage. */
|
||||
|
||||
void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
/* kvm_* vars */
|
||||
kvm_t *kd;
|
||||
static const int nlst_length=2;
|
||||
long cpts[CPUSTATES];
|
||||
/* sysctl vars*/
|
||||
static const int mib_length=2;
|
||||
int mib[mib_length];
|
||||
struct clockinfo ci;
|
||||
size_t length;
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
struct nlist nlst[nlst_length] = {
|
||||
{ "_cp_time" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/* MIB array for sysctl(3) use */
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_CLOCKRATE;
|
||||
|
||||
glibtop_init_r (& server);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
/* Get the value out of the kernel */
|
||||
if (kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open") == NULL) {
|
||||
/* If we can't get at the kernel, return the null values we just
|
||||
gave the array. */
|
||||
return;
|
||||
}
|
||||
kvm_nlist(kd, &nlst);
|
||||
kvm_read(kd, nlst[0].n_value, &cpts, sizeof(cpts));
|
||||
kvm_close(kd);
|
||||
|
||||
/* Get the clockrate data */
|
||||
length = sizeof(clockinfo);
|
||||
sysctl(mib, mib_length, &ci, &len, NULL, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
/* set user time */
|
||||
buf->user = cpts[CP_USER];
|
||||
/* set nice time */
|
||||
buf->nice = cpts[CP_NICE];
|
||||
/* set sys time */
|
||||
buf->sys = cpts[CP_SYS];
|
||||
/* set idle time */
|
||||
buf->idle = cpts[CP_IDLE];
|
||||
/* set frequency */
|
||||
/*
|
||||
FIXME -- is hz, tick, profhz or stathz wanted?
|
||||
buf->frequency = sysctl("kern.clockrate", ...);
|
||||
|
||||
struct clockinfo
|
||||
*/
|
||||
buf->frequency = ci.hz;
|
||||
/* set total */
|
||||
buf->total = cpts[CP_USER] + cpts[CP_NICE]
|
||||
+ cpts[CP_SYS] + cpts[CP_IDLE];
|
||||
|
||||
glibtop_init_p (server, GLIBTOP_SYSDEPS_CPU, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
}
|
||||
|
Reference in New Issue
Block a user