diff options
author | rwatson <rwatson@FreeBSD.org> | 2000-11-25 03:49:42 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2000-11-25 03:49:42 +0000 |
commit | 589fdc551b2d1548b5da9472ba3609d8144fb94e (patch) | |
tree | f9287a4e22c9aacb6e94535061ad744b646d49dc /usr.bin/systat | |
parent | 9e4c4b43a58f03a2ad88b212861b6ff974f7e02d (diff) | |
download | FreeBSD-src-589fdc551b2d1548b5da9472ba3609d8144fb94e.zip FreeBSD-src-589fdc551b2d1548b5da9472ba3609d8144fb94e.tar.gz |
o make systat/pigs.c use syctl() to retrieve cp_time, fscale, and ccpu
instead of using kmem.
Diffstat (limited to 'usr.bin/systat')
-rw-r--r-- | usr.bin/systat/pigs.c | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/usr.bin/systat/pigs.c b/usr.bin/systat/pigs.c index ba9b60a..9126a59 100644 --- a/usr.bin/systat/pigs.c +++ b/usr.bin/systat/pigs.c @@ -29,6 +29,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ */ #ifndef lint @@ -134,36 +136,34 @@ showpigs() wmove(wnd, y, 0); wclrtobot(wnd); } -static struct nlist namelist[] = { -#define X_FIRST 0 -#define X_CPTIME 0 - { "_cp_time" }, -#define X_CCPU 1 - { "_ccpu" }, -#define X_FSCALE 2 - { "_fscale" }, - - { "" } -}; - int initpigs() { fixpt_t ccpu; + size_t len; + int err; + + len = sizeof(stime); + err = sysctlbyname("kern.cp_time", &stime, &len, NULL, 0); + if (err || len != sizeof(stime)) { + perror("kern.cp_time"); + return (0); + } - if (namelist[X_FIRST].n_type == 0) { - if (kvm_nlist(kd, namelist)) { - nlisterr(namelist); - return(0); - } - if (namelist[X_FIRST].n_type == 0) { - error("namelist failed"); - return(0); - } + len = sizeof(ccpu); + err = sysctlbyname("kern.ccpu", &ccpu, &len, NULL, 0); + if (err || len != sizeof(ccpu)) { + perror("kern.ccpu"); + return (0); } - KREAD(NPTR(X_CPTIME), stime, sizeof (stime)); - NREAD(X_CCPU, &ccpu, sizeof(ccpu)); - NREAD(X_FSCALE, &fscale, LONG); + + len = sizeof(fscale); + err = sysctlbyname("kern.fscale", &fscale, &len, NULL, 0); + if (err || len != sizeof(fscale)) { + perror("kern.fscale"); + return (0); + } + lccpu = log((double) ccpu / fscale); return(1); @@ -180,9 +180,9 @@ fetchpigs() long ctime[CPUSTATES]; double t; static int lastnproc = 0; + size_t len; + int err; - if (namelist[X_FIRST].n_type == 0) - return; if ((kpp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nproc)) == NULL) { error("%s", kvm_geterr(kd)); if (pt) @@ -215,7 +215,12 @@ fetchpigs() /* * and for the imaginary "idle" process */ - KREAD(NPTR(X_CPTIME), ctime, sizeof (ctime)); + len = sizeof(ctime); + err = sysctlbyname("kern.cp_time", &ctime, &len, NULL, 0); + if (err || len != sizeof(ctime)) { + perror("kern.cp_time"); + return; + } t = 0; for (i = 0; i < CPUSTATES; i++) t += ctime[i] - stime[i]; |