summaryrefslogtreecommitdiffstats
path: root/usr.bin/time
diff options
context:
space:
mode:
authorjdp <jdp@FreeBSD.org>1996-07-30 19:00:12 +0000
committerjdp <jdp@FreeBSD.org>1996-07-30 19:00:12 +0000
commitf05fb79839f2c2e939d63287e153b80b22336408 (patch)
tree8ae09bed7d1a97aebf3cc5dd147ea212f47dbed1 /usr.bin/time
parentd7ae9a48c39f0c431f5a50171195f24f87637bdc (diff)
downloadFreeBSD-src-f05fb79839f2c2e939d63287e153b80b22336408.zip
FreeBSD-src-f05fb79839f2c2e939d63287e153b80b22336408.tar.gz
Fix a bug under time's "-l" option. The values reported for average
shared memory size, average unshared data size, and average unshared stack size were too high by a factor of 128/100, because the program used a hard-coded hz value of 100. The correct value is the frequency of the statistics clock, currently 128. The program now uses sysctl to get the stathz value from the kernel. Discussed with: bde@freebsd.org (Bruce Evans)
Diffstat (limited to 'usr.bin/time')
-rw-r--r--usr.bin/time/time.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c
index ebb4a4f..e911d8c 100644
--- a/usr.bin/time/time.c
+++ b/usr.bin/time/time.c
@@ -45,8 +45,13 @@ static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93";
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/signal.h>
+#include <sys/sysctl.h>
+
+#include <err.h>
#include <stdio.h>
+static int getstathz __P((void));
+
main(argc, argv)
int argc;
char **argv;
@@ -102,7 +107,7 @@ main(argc, argv)
fprintf(stderr, "%9ld.%02ld sys\n",
ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000);
if (lflag) {
- int hz = 100; /* XXX */
+ int hz = getstathz();
u_long ticks;
ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) +
@@ -146,3 +151,21 @@ main(argc, argv)
}
exit (status>>8);
}
+
+/*
+ * Return the frequency of the kernel's statistics clock.
+ */
+static int
+getstathz()
+{
+ struct clockinfo clockrate;
+ int mib[2];
+ size_t size;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_CLOCKRATE;
+ size = sizeof clockrate;
+ if (sysctl(mib, 2, &clockrate, &size, NULL, 0) == -1)
+ err(1, "sysctl kern.clockrate");
+ return clockrate.stathz;
+}
OpenPOWER on IntegriCloud