summaryrefslogtreecommitdiffstats
path: root/runtime/probes/bench/time.c
diff options
context:
space:
mode:
authorhunt <hunt>2005-06-28 18:04:07 +0000
committerhunt <hunt>2005-06-28 18:04:07 +0000
commit4d9dc675488169e9605222f969a32108df8f29b8 (patch)
tree69d6c2b71dffca6290ab6715d9290a4c901e191f /runtime/probes/bench/time.c
parent8a32c18d30dcd9dd664df74cd0c647ddfc060171 (diff)
downloadsystemtap-steved-4d9dc675488169e9605222f969a32108df8f29b8.tar.gz
systemtap-steved-4d9dc675488169e9605222f969a32108df8f29b8.tar.xz
systemtap-steved-4d9dc675488169e9605222f969a32108df8f29b8.zip
2005-06-28 Martin Hunt <hunt@redhat.com>
* bench: New probe to do benchmarks.
Diffstat (limited to 'runtime/probes/bench/time.c')
-rw-r--r--runtime/probes/bench/time.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/runtime/probes/bench/time.c b/runtime/probes/bench/time.c
new file mode 100644
index 00000000..fb423276
--- /dev/null
+++ b/runtime/probes/bench/time.c
@@ -0,0 +1,68 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+typedef unsigned long long uint64;
+
+struct timeval t1;
+
+void start(struct timeval *tv)
+{
+ gettimeofday (tv, NULL);
+}
+
+uint64 time_delta(struct timeval *start, struct timeval *stop)
+{
+ uint64 secs, usecs;
+
+ secs = stop->tv_sec - start->tv_sec;
+ usecs = stop->tv_usec - start->tv_usec;
+ if (usecs < 0) {
+ secs--;
+ usecs += 1000000;
+ }
+ return secs * 1000000 + usecs;
+}
+
+uint64 stop(struct timeval *begin)
+{
+ struct timeval end;
+ gettimeofday (&end, NULL);
+ return time_delta (begin, &end);
+}
+
+
+int main()
+{
+ int fd, i;
+ char buf[1024];
+ uint64 nsecs;
+
+ system ("touch foo");
+ fd = open ("foo", O_RDWR);
+
+ start(&t1);
+ for (i = 0; i < 1000000; i++) {
+ if (read (fd, buf, 0) < 0)
+ perror("read");
+ }
+ nsecs = stop(&t1) / 1000;
+
+ printf("%lld ", nsecs);
+
+ start(&t1);
+ for (i = 0; i < 1000000; i++) {
+ if (write (fd, buf, 0) < 0)
+ perror("write");
+ }
+ nsecs = stop(&t1) / 1000;
+ close (fd);
+
+ printf("%lld\n", nsecs);
+
+ return 0;
+}