aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred Perlstein <alfred@FreeBSD.org>2004-07-12 04:55:07 +0000
committerAlfred Perlstein <alfred@FreeBSD.org>2004-07-12 04:55:07 +0000
commit98c151d6d952b5bc9e0142eb5d08b9e18d661b99 (patch)
tree80317e040ec2f2eff46bdf1752e4a5cc469e04ee
parent8a3f1adf3b144f7ec53402518198785d2f6e24e2 (diff)
downloadsrc-98c151d6d952b5bc9e0142eb5d08b9e18d661b99.tar.gz
src-98c151d6d952b5bc9e0142eb5d08b9e18d661b99.zip
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.
Notes
Notes: svn path=/head/; revision=132015
-rw-r--r--usr.bin/top/machine.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 7db6fa81c4ee..698172731c70 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);
}