diff options
author | alfred <alfred@FreeBSD.org> | 2004-07-12 04:55:07 +0000 |
---|---|---|
committer | alfred <alfred@FreeBSD.org> | 2004-07-12 04:55:07 +0000 |
commit | 221d6a099a5664d5ce6f054052073470d06ffa2b (patch) | |
tree | 80317e040ec2f2eff46bdf1752e4a5cc469e04ee /usr.bin | |
parent | 7c44f05ec49eee3c9532f478443e6bf9bbfd011c (diff) | |
download | FreeBSD-src-221d6a099a5664d5ce6f054052073470d06ffa2b.zip FreeBSD-src-221d6a099a5664d5ce6f054052073470d06ffa2b.tar.gz |
Cache a pointer to the old proc (as well as negative cache) to make
computing the io statistics over and over not as expensive.
This is a bit of a cop out, as I should just allocate a struct with
the computed values, but this will do for now.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/top/machine.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 7db6fa8..6981727 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -413,6 +413,8 @@ get_system_info(struct system_info *si) } } +#define NOPROC ((void *)-1) + const struct kinfo_proc * get_old_proc(struct kinfo_proc *pp) { @@ -420,13 +422,22 @@ get_old_proc(struct kinfo_proc *pp) if (previous_proc_count == 0) return (NULL); + if (pp->ki_udata == NOPROC) + return (NULL); + if (pp->ki_udata != NULL) + return (pp->ki_udata); oldpp = bsearch(&pp, previous_pref, previous_proc_count, sizeof(*previous_pref), compare_pid); - if (oldpp == NULL) + if (oldpp == NULL) { + pp->ki_udata = NOPROC; return (NULL); + } oldp = *oldpp; - if (bcmp(&oldp->ki_start, &pp->ki_start, sizeof(pp->ki_start)) != 0) + if (bcmp(&oldp->ki_start, &pp->ki_start, sizeof(pp->ki_start)) != 0) { + pp->ki_udata = NOPROC; return (NULL); + } + pp->ki_udata = oldp; return (oldp); } |