summaryrefslogtreecommitdiffstats
path: root/runtime/probes/bench/ttest.c
diff options
context:
space:
mode:
authorhunt <hunt>2005-07-13 06:34:00 +0000
committerhunt <hunt>2005-07-13 06:34:00 +0000
commitfa60355b7aacd1f4b10f1497792787288c0632ff (patch)
tree5ab2cee9aae848540ba784848b8ecc494bc3c021 /runtime/probes/bench/ttest.c
parentf8220a7b945a3be7975fb2610ca1c79119594534 (diff)
downloadsystemtap-steved-fa60355b7aacd1f4b10f1497792787288c0632ff.tar.gz
systemtap-steved-fa60355b7aacd1f4b10f1497792787288c0632ff.tar.xz
systemtap-steved-fa60355b7aacd1f4b10f1497792787288c0632ff.zip
2005-07-12 Martin Hunt <hunt@redhat.com>
* bench/run_bench (do_time): Use ttest instead of "time". Fix processor computation. * bench/ttest.c: Like "time.c" except takes an argument to adjust loop size. Also computes system time + user time instead of real time. Added a warmup loop to get consistent results from cpus which adjust speed based on load. * bench/time.c: Replaced by ttest.c
Diffstat (limited to 'runtime/probes/bench/ttest.c')
-rw-r--r--runtime/probes/bench/ttest.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/runtime/probes/bench/ttest.c b/runtime/probes/bench/ttest.c
new file mode 100644
index 00000000..eed641da
--- /dev/null
+++ b/runtime/probes/bench/ttest.c
@@ -0,0 +1,82 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+typedef unsigned long long uint64;
+struct rusage rstart;
+
+void start()
+{
+ getrusage (RUSAGE_SELF, &rstart);
+}
+
+uint64 usecs (struct timeval *tv)
+{
+ return tv->tv_sec * 1000000 + tv->tv_usec;
+}
+
+uint64 stop()
+{
+ struct rusage rend;
+ getrusage (RUSAGE_SELF, &rend);
+ uint64 utime = usecs(&rend.ru_utime) - usecs(&rstart.ru_utime);
+ uint64 stime = usecs(&rend.ru_stime) - usecs(&rstart.ru_stime);
+ return utime + stime;
+}
+
+void usage(char *name)
+{
+ printf ("Usage %s [time]\nWhere \"time\" is millions of times to loop.\n", name);
+ exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+ int fd, i, n = 1;
+ char buf[1024];
+ uint64 nsecs;
+
+ if (argc > 2)
+ usage(argv[0]);
+
+ if (argc == 2) {
+ n = strtol(argv[1], NULL, 10);
+ if (n == 0)
+ usage(argv[0]);
+ }
+
+ fd = open ("foo", O_CREAT | O_RDWR);
+
+ /* large warmup time */
+ for (i = 0; i < n * 1000000; i++) {
+ if (write (fd, buf, 0) < 0)
+ perror("write");
+ }
+
+ start();
+ for (i = 0; i < n * 1000000; i++) {
+ if (read (fd, buf, 0) < 0)
+ perror("read");
+ }
+ nsecs = stop() / (n * 1000);
+
+ printf("%lld ", nsecs);
+
+ start();
+ for (i = 0; i < n * 1000000; i++) {
+ if (write (fd, buf, 0) < 0)
+ perror("write");
+ }
+ nsecs = stop() / (n * 1000);
+ close (fd);
+
+ printf("%lld\n", nsecs);
+ unlink("foo");
+
+ return 0;
+}