From dbc31f20d30615404c2994f2d0bb9876cd75585a Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Mon, 2 Oct 2017 13:56:25 +0200 Subject: [PATCH] libbacktrace: Conditionalize test timing on clock_gettime availability libbacktrace/ PR other/67165 * configure.ac: Check for clock_gettime. * config.h.in: Regenerate. * configure: Likewise. * ztest.c (average_time, test_large): Conditionalize test timing on clock_gettime availability. From-SVN: r253344 --- libbacktrace/ChangeLog | 9 +++++++++ libbacktrace/config.h.in | 3 +++ libbacktrace/configure | 13 +++++++++++++ libbacktrace/configure.ac | 3 +++ libbacktrace/ztest.c | 12 +++++++++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index 9597a687581..0e4cfd24cd3 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,12 @@ +2017-10-02 Thomas Schwinge + + PR other/67165 + * configure.ac: Check for clock_gettime. + * config.h.in: Regenerate. + * configure: Likewise. + * ztest.c (average_time, test_large): Conditionalize test timing + on clock_gettime availability. + 2017-09-29 Tony Reix * xcoff.c: Initial support for DWARF debug sections in XCOFF. diff --git a/libbacktrace/config.h.in b/libbacktrace/config.h.in index a9f70da85f2..c19b6e430cb 100644 --- a/libbacktrace/config.h.in +++ b/libbacktrace/config.h.in @@ -9,6 +9,9 @@ /* Define to 1 if you have the __atomic functions */ #undef HAVE_ATOMIC_FUNCTIONS +/* Define to 1 if you have the `clock_gettime' function. */ +#undef HAVE_CLOCK_GETTIME + /* Define to 1 if you have the declaration of `strnlen', and to 0 if you don't. */ #undef HAVE_DECL_STRNLEN diff --git a/libbacktrace/configure b/libbacktrace/configure index ece4151a0c6..062dc77c9b2 100755 --- a/libbacktrace/configure +++ b/libbacktrace/configure @@ -12747,6 +12747,19 @@ $as_echo "#define HAVE_GETEXECNAME 1" >>confdefs.h fi +# Check for the clock_gettime function. +for ac_func in clock_gettime +do : + ac_fn_c_check_func "$LINENO" "clock_gettime" "ac_cv_func_clock_gettime" +if test "x$ac_cv_func_clock_gettime" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_CLOCK_GETTIME 1 +_ACEOF + +fi +done + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -pthread is supported" >&5 $as_echo_n "checking whether -pthread is supported... " >&6; } if test "${libgo_cv_lib_pthread+set}" = set; then : diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac index f389c72f9fd..75ec9f503a2 100644 --- a/libbacktrace/configure.ac +++ b/libbacktrace/configure.ac @@ -388,6 +388,9 @@ if test "$have_getexecname" = "yes"; then AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.]) fi +# Check for the clock_gettime function. +AC_CHECK_FUNCS(clock_gettime) + dnl Test whether the compiler supports the -pthread option. AC_CACHE_CHECK([whether -pthread is supported], [libgo_cv_lib_pthread], diff --git a/libbacktrace/ztest.c b/libbacktrace/ztest.c index 103ad655066..0b1cbc35f0c 100644 --- a/libbacktrace/ztest.c +++ b/libbacktrace/ztest.c @@ -43,6 +43,10 @@ POSSIBILITY OF SUCH DAMAGE. */ #include #endif +#ifdef HAVE_CLOCK_GETTIME +# define TEST_TIMING +#endif + #include "backtrace.h" #include "backtrace-supported.h" @@ -157,7 +161,7 @@ test_samples (struct backtrace_state *state) } } -#ifdef HAVE_ZLIB +#if defined HAVE_ZLIB && defined TEST_TIMING /* Given a set of TRIALS timings, discard the lowest and highest values and return the mean average of the rest. */ @@ -216,6 +220,7 @@ test_large (struct backtrace_state *state) unsigned char *uncompressed_buf; size_t uncompressed_bufsize; int r; +# ifdef TEST_TIMING clockid_t cid; struct timespec ts1; struct timespec ts2; @@ -224,6 +229,7 @@ test_large (struct backtrace_state *state) const size_t trials = 16; size_t ctimes[16]; size_t ztimes[16]; +# endif /* TEST_TIMING */ static const char * const names[] = { "Mark.Twain-Tom.Sawyer.txt", "../libgo/go/compress/testdata/Mark.Twain-Tom.Sawyer.txt" @@ -341,6 +347,8 @@ test_large (struct backtrace_state *state) printf ("PASS: inflate large\n"); +# ifdef TEST_TIMING + for (i = 0; i < trials; ++i) { cid = CLOCK_REALTIME; @@ -411,6 +419,8 @@ test_large (struct backtrace_state *state) printf ("zlib time: : %zu ns\n", ztime); printf ("percentage : %g\n", (double) ztime / (double) ctime); +# endif /* TEST_TIMING */ + return; fail: -- 2.30.2