From: Stefan Kost Date: Wed, 28 Nov 2007 11:39:35 +0000 (+0000) Subject: Apply the posix-timer check from #361155. Conditionally use the posix timer for loggi... X-Git-Tag: RELEASE-0_10_16~82 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec080cd61bc095c4744e8257a74d759df51408f9;p=platform%2Fupstream%2Fgstreamer.git Apply the posix-timer check from #361155. Conditionally use the posix timer for logging. This gives better timestamp ... Original commit message from CVS: * configure.ac: * gst/gstdebugutils.c: * gst/gstinfo.c: Apply the posix-timer check from #361155. Conditionally use the posix timer for logging. This gives better timestamp precission, less overhead and no ntp jitter. --- diff --git a/ChangeLog b/ChangeLog index 4f4dde4..72e40b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-11-28 Stefan Kost + + * configure.ac: + * gst/gstdebugutils.c: + * gst/gstinfo.c: + Apply the posix-timer check from #361155. Conditionally use the posix + timer for logging. This gives better timestamp precission, less + overhead and no ntp jitter. + 2007-11-28 Sebastian Dröge * gst/gstminiobject.c: (gst_mini_object_get_type), diff --git a/configure.ac b/configure.ac index 5288602..ba46a17 100644 --- a/configure.ac +++ b/configure.ac @@ -358,6 +358,58 @@ dnl check for mmap() AC_FUNC_MMAP AM_CONDITIONAL(HAVE_MMAP, test "x$ac_cv_func_mmap_fixed_mapped" = "xyes") +dnl Check for POSIX timers +AC_CHECK_FUNCS(clock_gettime, [], [ + AC_CHECK_LIB(rt, clock_gettime, [ + AC_DEFINE(HAVE_CLOCK_GETTIME, 1) + LIBS="$LIBS -lrt" + ]) +]) + +AC_CACHE_CHECK(for posix timers, gst_cv_posix_timers,AC_TRY_RUN([ +#include +#ifdef HAVE_UNISTD_H +#include +#endif + int main() { +#if defined(_POSIX_TIMERS) && _POSIX_TIMERS >= 0 && defined(CLOCK_REALTIME) + return 0; +#else + return 1; +#endif + }],gst_cv_posix_timers=yes,gst_cv_posix_timers=no)) + +if test "$gst_cv_posix_timers" = "yes"; then + AC_DEFINE(HAVE_POSIX_TIMERS,1,[Have posix timers]) + GST_HAVE_POSIX_TIMERS_DEFINE="#define GST_HAVE_POSIX_TIMERS 1" +else + GST_HAVE_POSIX_TIMERS_DEFINE="#define GST_HAVE_POSIX_TIMERS 0" +fi +AC_SUBST(GST_HAVE_POSIX_TIMERS_DEFINE) +AM_CONDITIONAL(GST_HAVE_POSIX_TIMERS, test "$gst_cv_posix_timers" = "yes") + +AC_CACHE_CHECK(for monotonic clock, gst_cv_monotonic_clock,AC_TRY_RUN([ +#include +#ifdef HAVE_UNISTD_H +#include +#endif + int main() { +#if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 && defined(CLOCK_MONOTONIC) + return 0; +#else + return 1; +#endif + }],gst_cv_monotonic_clock=yes,gst_cv_monotonic_clock=no)) + +if test "$gst_cv_monotonic_clock" = "yes"; then + AC_DEFINE(HAVE_MONOTONIC_CLOCK,1,[Have a monotonic clock]) + GST_HAVE_MONOTONIC_CLOCK_DEFINE="#define GST_HAVE_MONOTONIC_CLOCK 1" +else + GST_HAVE_MONOTONIC_CLOCK_DEFINE="#define GST_HAVE_MONOTONIC_CLOCK 0" +fi +AC_SUBST(GST_HAVE_MONOTONIC_CLOCK_DEFINE) +AM_CONDITIONAL(GST_HAVE_MONOTONIC_CLOCK, test "$gst_cv_monotonic_clock" = "yes") + dnl Check for a way to display the function name in debug output AG_GST_CHECK_FUNCTION diff --git a/gst/gstdebugutils.c b/gst/gstdebugutils.c index de04573..592617c 100644 --- a/gst/gstdebugutils.c +++ b/gst/gstdebugutils.c @@ -496,7 +496,6 @@ _gst_debug_bin_to_dot_file_with_ts (GstBin * bin, GstDebugGraphDetails details, const gchar * file_name) { gchar *ts_file_name = NULL; - GTimeVal now; GstClockTime elapsed; g_return_if_fail (GST_IS_BIN (bin)); @@ -508,8 +507,21 @@ _gst_debug_bin_to_dot_file_with_ts (GstBin * bin, GstDebugGraphDetails details, } /* add timestamp */ - g_get_current_time (&now); - elapsed = GST_TIMEVAL_TO_TIME (now) - _priv_gst_info_start_time; +#ifdef HAVE_POSIX_TIMERS + { + struct timespec now; + + clock_gettime (CLOCK_MONOTONIC, &now); + elapsed = GST_TIMESPEC_TO_TIME (now) - _priv_gst_info_start_time; + } +#else + { + GTimeVal now; + + g_get_current_time (&now); + elapsed = GST_TIMEVAL_TO_TIME (now) - _priv_gst_info_start_time; + } +#endif ts_file_name = g_strdup_printf ("%" GST_TIME_FORMAT "-%s", GST_TIME_ARGS (elapsed), file_name); diff --git a/gst/gstinfo.c b/gst/gstinfo.c index 2833a89..4c76f4c 100644 --- a/gst/gstinfo.c +++ b/gst/gstinfo.c @@ -277,14 +277,25 @@ __gst_in_valgrind (void) void _gst_debug_init (void) { - GTimeVal current; - gst_atomic_int_set (&__default_level, GST_LEVEL_DEFAULT); gst_atomic_int_set (&__use_color, 1); /* get time we started for debugging messages */ - g_get_current_time (¤t); - _priv_gst_info_start_time = GST_TIMEVAL_TO_TIME (current); +#ifdef HAVE_POSIX_TIMERS + { + struct timespec current; + + clock_gettime (CLOCK_MONOTONIC, ¤t); + _priv_gst_info_start_time = GST_TIMESPEC_TO_TIME (current); + } +#else + { + GTimeVal current; + + g_get_current_time (¤t); + _priv_gst_info_start_time = GST_TIMEVAL_TO_TIME (current); + } +#endif #ifdef HAVE_PRINTF_EXTENSION register_printf_function (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr, @@ -629,7 +640,6 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level, gchar pidcolor[10]; const gchar *levelcolor; gint pid; - GTimeVal now; GstClockTime elapsed; gboolean free_color = TRUE; gboolean free_obj = TRUE; @@ -669,8 +679,21 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level, free_obj = FALSE; } - g_get_current_time (&now); - elapsed = GST_TIMEVAL_TO_TIME (now) - _priv_gst_info_start_time; +#ifdef HAVE_POSIX_TIMERS + { + struct timespec now; + + clock_gettime (CLOCK_MONOTONIC, &now); + elapsed = GST_TIMESPEC_TO_TIME (now) - _priv_gst_info_start_time; + } +#else + { + GTimeVal now; + + g_get_current_time (&now); + elapsed = GST_TIMEVAL_TO_TIME (now) - _priv_gst_info_start_time; + } +#endif /* g_printerr ("%s (%p - %" GST_TIME_FORMAT ") %s%20s%s(%s%5d%s) %s%s(%d):%s:%s%s %s\n",