diff options
author | mostang.com!davidm <mostang.com!davidm> | 2003-09-24 05:02:14 +0000 |
---|---|---|
committer | mostang.com!davidm <mostang.com!davidm> | 2003-09-24 05:02:14 +0000 |
commit | 12876ef7815e26325a187fd5dbc0fda417011d7b (patch) | |
tree | 6bc1fb707be4a6954a7d81bb5ea54fa9ae241bf7 /tests/Gperf-simple.c | |
parent | ee803e7accc3ee551cee1e16f7654f7e8f64d72e (diff) | |
download | libunwind-12876ef7815e26325a187fd5dbc0fda417011d7b.tar.gz |
(Logical change 1.98)
Diffstat (limited to 'tests/Gperf-simple.c')
-rw-r--r-- | tests/Gperf-simple.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/Gperf-simple.c b/tests/Gperf-simple.c index e69de29b..45a48373 100644 --- a/tests/Gperf-simple.c +++ b/tests/Gperf-simple.c @@ -0,0 +1,76 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <sys/time.h> + +#include <libunwind.h> + +#define panic(args...) \ + do { fprintf (stderr, args); exit (-1); } while (0) + +static inline double +gettime (void) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + return tv.tv_sec + 1e-6*tv.tv_usec; +} + +static int +measure_unwind (int maxlevel) +{ + double stop, mid, start; + unw_cursor_t cursor; + unw_context_t uc; + int ret, level = 0; + + start = gettime (); + + unw_getcontext (&uc); + if (unw_init_local (&cursor, &uc) < 0) + panic ("unw_init_local() failed\n"); + + mid = gettime (); + + do + { + ret = unw_step (&cursor); + if (ret < 0) + panic ("unw_step() failed\n"); + ++level; + } + while (ret > 0); + + stop = gettime (); + + if (level <= maxlevel) + panic ("Unwound only %d levels, expected at least %d levels", + level, maxlevel); + + printf ("initialization time = %gnsec, time per unwind-step = %gnsec\n", + 1e9*(mid - start), 1e9*(stop - mid)/level); +} + +static int +f1 (int level, int maxlevel) +{ + if (level == maxlevel) + return measure_unwind (maxlevel); + else + /* defeat last-call/sibcall optimization */ + return f1 (level + 1, maxlevel) + level; +} + +int +main (int argc, char **argv) +{ + int i, maxlevel = 100; + + if (argc > 1) + maxlevel = atol (argv[1]); + + for (i = 0; i < 10; ++i) + f1 (0, maxlevel); + return 0; +} |